summaryrefslogtreecommitdiff
path: root/serial.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix file descriptor leak in serial.c.stefanct2016-01-161-4/+6
| | | | | | | | | Found by Coverity as "CID 1348465: Resource leaks". Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1915 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* serial: support arbitrary baud rates on Windows.stefanct2016-01-041-30/+34
| | | | | | | | | | | | Available baud rates obviously depend on driver support, but the CBR_ defines used so far are basically only for backwards source compatibility with Win16, so dont bother with them. Signed-off-by: Urja Rannikko <urjaman@gmail.com> Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1909 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* serprog: allow to omit specifying a baud rate.stefanct2016-01-041-10/+15
| | | | | | | | | | | On USB-based serial connections (VCP) the requested baud rate usually does not matter (much). Remove the arbitrary restriction and use whatever default values the OS/hardware provides. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Urja Rannikko <urjaman@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1907 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* serprog: ignore failures when setting serial port options.stefanct2016-01-041-5/+18
| | | | | | | | | | | | There is no good reason to abort earlier just because some options did not stick. This should improve compatibility without negative effects. If communication is affected by the missing flag(s) then we abort later anyway. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Urja Rannikko <urjaman@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1906 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* serprog: clear NDELAY flag only once after opening the port.stefanct2016-01-041-5/+13
| | | | | | | | | | | Change sp_openserport() to directly clear the O_NONBLOCK flag that is potentially set by opening the device with O_NDELAY instead of clearing ALL flags in serialport_config() unconditionally. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Urja Rannikko <urjaman@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1905 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Unify target OS and CPU architecture checks.stefanct2015-01-101-19/+21
| | | | | | | | | | | | | | | | | | | | | | We do CPU architecture checks once for the makefile in arch.h and once for HW access abstraction in hwaccess.c. This patch unifies related files so that they can share the checks to improve maintainability and reduce the chance of inconsistencies. Furthermore, it refines some of the definitions, which - adds "support" for AARCH64 and PPC64, - adds big-endian handling on arm as well as LE handling on PPC64, - fixes compilation of internal.c on AARCH64 and PPC64. Additionally, this patch continues to unify all OS checks in flashrom by adding a new helper macro IS_WINDOWS. The old header file for architecture checking is renamed to platform.h to reflect its broader scope and all new macros are add in there. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1864 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* CID1129998/1129999: Unchecked return value from library.stefanct2014-05-271-7/+30
| | | | | | | | | | | | | | Check return values of various fcntl() invocations in serialport_config(), serialport_read_nonblock() and serialport_write_nonblock(). Also, remove some superfluous print conversion specifiers and refine messages. Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1803 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Add 'const' keyword to chip write and other function prototypes.stefanct2014-05-091-2/+2
| | | | | | | | | | Inspired by and mostly based on a patch Signed-off-by: Mark Marshall <mark.marshall@omicron.at> Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1789 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* serial: use internal_delay() for timeouts.stefanct2013-10-191-1/+1
| | | | | | | | | | | | | Using programmer_delay() for timeouts in serial writes could cause a (theoretically) endless recursion if serial communication is used to send the programmer the delay command to be executed on the programmer instead of the host which fails again, following a timeout which sends... Signed-off-by: Urja Rannikko <urjaman@gmail.com> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1759 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Get rid of sp_die().stefanct2013-08-241-6/+0
| | | | | | | | | | | | | | - Add return values to sp_flush_stream(), sp_pass_writen(), sp_execute_opbuf(), sp_execute_opbuf_noflush(), sp_check_opbuf_usage(), sp_do_read_n(). - Use those return values to propagate errors instead of exiting. In some places this has to wait for core API changes (error handling for chip_readb, chip_readn, chip_write) hence comments are added instead. Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1719 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Introduce serialport_config().stefanct2013-08-231-46/+59
| | | | | | | | | | This allows to easily reconfigure a serial port as needed in the Bus Pirate speedup patch. Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1717 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Initialize sp_fd and fix baud rate setting on windows.stefanct2013-04-131-2/+2
| | | | | | | Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1669 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* serial.c: be more pedantic.stefanct2013-04-011-16/+44
| | | | | | | | | | Check more return codes and close the file handle in case of errors in sp_openserport(). Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1664 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Replace native calls in serprog with wrapper calls.stefanct2013-04-011-1/+1
| | | | | | | | | | read(), write(), usleep() are replaced. Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Signed-off-by: Idwer Vollering <vidwer@gmail.com> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1663 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Introduce serialport_write_nonblock().stefanct2013-04-011-0/+72
| | | | | | | | | | | | | It seems useful to have a generic and platform-independent method to read and write to a serial port without blocking. This is the write part. This allows to get rid of the explicit temporary disabling of blocking I/O in serprog's sp_synchronize(). Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1662 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Replace sp_sync_read_timeout() with serialport_read_nonblock().stefanct2013-04-011-0/+70
| | | | | | | | | | | | | | | It seems useful to have a generic and platform-independent method to read and write to a serial port without blocking. This is the read part. It stores the current blocking properties before disabling blocking and restores them after reading. The timeout is implemented as previously by retrying every millisecond until the timeout is reached or enough characters are available. Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1661 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* serial.c: round baudrates to valid ones.stefanct2013-04-011-40/+63
| | | | | | | | | | | | | | | | | MSDN says: "The baud rate at which the communications device operates. This member can be an actual baud rate value, or one of the following indexes." But it is not specified what happens for different values, so we round down to valid ones (or to the minimum of 9600) by reusing the existing struct baudentry sp_baudtable[] and the new function round_baud(). Do similarly on non-Windows where arbitrary values are not allowed anyway. Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1660 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* serial.c: abstract system error printing.stefanct2013-04-011-6/+28
| | | | | | | | | | | Windows is awkward. The win32 API does not support errno/strerror as one might expect. Introduce a new msg_* function that alleviates the pain a bit (my head still hurts very badly). Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1659 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Break endless loop in serialport_write().stefanct2012-11-301-3/+11
| | | | | | | | | | | serialport_write could loop endlessly when used with a seemingly valid port that does always return 0 on writes instead of an error. Give up after about 125 ms i.e. 250 tries with a period of 500 us. Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Idwer Vollering <vidwer@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1626 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Remove exit calls from sp_sync_read_timeout and sp_synchronize.stefanct2012-09-071-0/+1
| | | | | | | | | | | | | | | | | | Add return values to sp_synchronize so we can signal a failure to the only upstream caller (serprog_init), which is prepared to propagate a failure. sp_sync_read_timeout was harder to fix because it already used a return value, but we needed to distinguish two different failure modes. This solution distinguishes them by the sign of the return values, which maintains readability as much as possible. Thanks to Niklas Söderlund for the original patch and idea. Signed-off-by: Niklas Söderlund <niso@kth.se> Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1595 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Fix compilation with MinGW.stefanct2012-09-011-7/+7
| | | | | | | | | | This was broken since r1557 when we got rid of some exit calls, but returned -1 instead which is not a valid HANDLE value. Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Idwer Vollering <vidwer@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1591 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Remove more exit calls.stefanct2012-07-301-11/+18
| | | | | | | | | | | | | | | | This patch removes the remaining exit calls from - sp_openserport - sp_opensocket - sp_docommand - internal_init Almost all of this was done by Niklas. Signed-off-by: Niklas Söderlund <niso@kth.se> Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1557 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Add serial port bitbanging codemkarcher2012-04-301-0/+55
| | | | | | | | | | | This adds the pony_spi driver which supports the SI_Prog adapter, which is commonly used for SPI chips with PonyProg 2000, and a custom adapter called "SERBANG" which differs in the logic of two pins. Signed-off-by: Virgil-Adrian Teaca <darkstarlinux@gmail.com> Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1525 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* fix unchecked malloc calls and casts of malloc return valuesstefanct2011-07-121-0/+2
| | | | | | | | | | | | in the long term the exit calls should be replaced by returns. until then this is the correct way to handle failures. the casts are not needed (in C) and we don't cast malloc return values anywhere else. Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1370 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Fix and improve Windows/MinGW/MSYS build.uwe2011-07-031-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Makefile: Use $(OS_ARCH) to add some MinGW-specific workarounds and settings, so that a simple "make" is sufficient on MinGW (instead of manual Makefile hacking). - Explicitly set CC=gcc in the Makefile, otherwise you get an error like "cc: command not found" on MinGW. - MinGW doesn't have ffs(), use gcc's __builtin_ffs() instead. - Add /usr/local/include and /usr/local/lib to CPPFLAGS/LDFLAGS, that's where libusb-win32 and libftdi stuff is usually placed on MinGW/MSYS. - Disable serprog (no sockets) and all PCI-based programmers (no libpci) for now. That leaves dummy, ft2232_spi, and buspirate_spi enabled on MinGW per default. - serial.c: Use correct type for 'tmp', both on Windows/MinGW (DWORD) and POSIX (ssize_t). Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1363 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Use shutdown callback mechanism to shutdown programmersdhendrix2011-06-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch attempts to resolve some programmer shutdown ordering issues by having the programmer init functions register shutdown callbacks explicitly wherever it makes most sense. Before, assumptions were made that could lead to the internal programmer's state changing before the external programmer could be shut down properly. Now, each programmer cleans up after itself and (hopefully) performs each operation in the correct order. As a side-effect, this patch gives us a better usage model for reverse operations such as rpci_* and rmmio_*. In the long-run, this should make reversing the initialization process easier to understand, less tedious, and less error-prone. In short, this patch does the following: - Registers a shutdown callback during initialization for each programmer. - Kills the .shutdown function pointer from programmer_entry struct. Also, make most shutdown functions static. - Adds a few minor clean-ups and corrections (e.g. missing physunmap() calls). TODO: Remove forward declaration of serprog_shutdown() (added to simplify diff) Signed-off-by: David Hendricks <dhendrix@google.com> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1338 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* CONFIG_BITBANG_SPI was not selected if CONFIG_NICINTEL_SPI was on byhailfinger2010-10-081-2/+3
| | | | | | | | | | | | | | | | default. Wiki output was missing all flash chips if CONFIG_INTERNAL was not selected. Use correct type for toupper()/tolower()/isspace() functions. Specify software requirements in a generic way. Non-x86 compilation does not work with the default programmer set, so list the make parameters which result in a working build. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1203 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Remove duplicate includes from the code.stepan2010-10-061-1/+0
| | | | | | | | | Signed-off-by: Stefan Reinauer <stepan@coresystems.de> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1196 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Thanks to Johannes Sjölund for reporting that the Bus Pirate init couldhailfinger2010-09-161-2/+6
| | | | | | | | | | | | | | | | | | | not deal with a Bus Pirate which is already in binary Bitbang mode. This is caused by a combination of the slowness of the Bus Pirate, the slowness of USB and a fast serial port flush routine which just flushes the buffer contents and does not wait until data arrival stops. Make the Bus Pirate init more robust by running the flush command 10 times with 1.5 ms delay in between. This code development was sponsored by Mattias Mattsson. Thanks! Tested a few dozen times, should work reliably. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Mattias Mattsson <vitplister@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1178 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Split off programmer.h from flash.h.hailfinger2010-07-271-1/+2
| | | | | | | | | | | | | | | | | | | | | | Programmer specific functions are of absolutely no interest to any file except those dealing with programmer specific actions (special SPI commands and the generic core). The new header structure is as follows (and yes, improvements are possible): flashchips.h flash chip IDs chipdrivers.h chip-specific read/write/... functions flash.h common header for all stuff that doesn't fit elsewhere hwaccess.h hardware access functions programmer.h programmer specific functions coreboot_tables.h header from coreboot, internal programmer only spi.h SPI command definitions Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1112 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Various coding style and cosmetic changes (trivial).uwe2010-03-131-11/+12
| | | | | | | | | | | | | | | - Fix coding-style, whitespace, and indentation in a few places. - Consistently use the same spelling ("Super I/O") everywhere. - Make some flashrom stdout output look a bit nicer. Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@933 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Windows wants UNC names for COM ports >9 (legacy COM ports only work with ↵oxygene2010-01-261-1/+9
| | | | | | | | | | | | | | | one digit). As UNC also works for smaller names, just retarget all requests for dev=COMx on win32 to \\.\COMx. Tested with large and small COM port numbers on XP. Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@883 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Convert all messages in serial.c to the new message infrastructure.snelson2010-01-091-3/+3
| | | | | | | | Signed-off-by: Sean Nelson <audiohacked@gmail.com> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@848 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* buspiratespi support on mingwoxygene2010-01-061-4/+53
| | | | | | | | Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@832 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* - replace the hand written serial input flush routine with the termios one.oxygene2010-01-061-29/+9
| | | | | | | | | | | | | | | - serialport_discard_read isn't necessary anymore - it just wrapped sp_flush_incoming with no extra value. - serialport_read and serialport_write would misbehave if read or write didn't process everything in one go. - sp_flush_incoming should be #define'd out for FAKE_COMMUNICATION like serialport_discard_read was Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de> Acked-by: Sean Nelson <audiohacked@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@831 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Move OS-dependent serial code from buspirate_spi.c to serial.c andhailfinger2010-01-061-0/+52
| | | | | | | | | | | rename a few functions to make it obvious that they are generic and not specific to the Bus Pirate. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Patrick Georgi <patrick.georgi@coresystems.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@830 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
* Move serial handling from serprog.c to serial.c.hailfinger2009-11-231-0/+142
This is the first step in enabling platform independent serprog and it also allows other drivers to use serial port functionality without requiring serprog. Pure code move, no code changed. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@771 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1