1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00

22 Commits

Author SHA1 Message Date
Stefan Tauner
00e1608501 Replace sp_sync_read_timeout() with serialport_read_nonblock()
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.

Corresponding to flashrom svn r1661.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
2013-04-01 00:45:38 +00:00
Stefan Tauner
da5b17c0a2 serial.c: round baudrates to valid ones
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.

Corresponding to flashrom svn r1660.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
2013-04-01 00:45:32 +00:00
Stefan Tauner
bf88be9291 serial.c: abstract system error printing
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).

Corresponding to flashrom svn r1659.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
2013-04-01 00:45:08 +00:00
Stefan Tauner
62574aa5c0 Break endless loop in serialport_write()
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.

Corresponding to flashrom svn r1626.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Idwer Vollering <vidwer@gmail.com>
2012-11-30 16:46:41 +00:00
Niklas Söderlund
7145a50f53 Remove exit calls from sp_sync_read_timeout and sp_synchronize
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.

Corresponding to flashrom svn r1595.

Signed-off-by: Niklas Söderlund <niso@kth.se>
Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
2012-09-07 07:07:07 +00:00
Stefan Tauner
bb4fed74b6 Fix compilation with MinGW
This was broken since r1557 when we got rid of some exit calls, but returned
-1 instead which is not a valid HANDLE value.

Corresponding to flashrom svn r1591.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Idwer Vollering <vidwer@gmail.com>
2012-09-01 21:47:19 +00:00
Niklas Söderlund
2a95e8713b Remove more exit calls
This patch removes the remaining exit calls from
 - sp_openserport
 - sp_opensocket
 - sp_docommand
 - internal_init

Almost all of this was done by Niklas.

Corresponding to flashrom svn r1557.

Signed-off-by: Niklas Söderlund <niso@kth.se>
Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
2012-07-30 19:42:33 +00:00
Virgil-Adrian Teaca
da7c545b06 Add serial port bitbanging code
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.

Corresponding to flashrom svn r1525.

Signed-off-by: Virgil-Adrian Teaca <darkstarlinux@gmail.com>
Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>
2012-04-30 23:11:06 +00:00
Stefan Tauner
269de3533a Fix unchecked malloc calls and casts of malloc return values
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.

Corresponding to flashrom svn r1370.

Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
2011-07-12 22:35:21 +00:00
Uwe Hermann
d5e85d674b Fix and improve Windows/MinGW/MSYS build
- 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).

Corresponding to flashrom svn r1363.

Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
2011-07-03 19:44:12 +00:00
David Hendricks
8bb2021d77 Use shutdown callback mechanism to shutdown programmers
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)

Corresponding to flashrom svn r1338.

Signed-off-by: David Hendricks <dhendrix@google.com>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
2011-06-14 01:35:36 +00:00
Carl-Daniel Hailfinger
9e3a6c4913 Multiple unrelated changes
CONFIG_BITBANG_SPI was not selected if CONFIG_NICINTEL_SPI was on by 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.

Corresponding to flashrom svn r1203.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>
2010-10-08 12:40:09 +00:00
Stefan Reinauer
18430a08aa Remove duplicate includes from the code
Corresponding to flashrom svn r1196.

Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
2010-10-06 02:56:44 +00:00
Carl-Daniel Hailfinger
d2f007f98b Handle Bus Pirates already in bit banging mode correctly
Thanks to Johannes Sjölund for reporting that the Bus Pirate init could
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.

Corresponding to flashrom svn r1178.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Mattias Mattsson <vitplister@gmail.com>
2010-09-16 22:34:25 +00:00
Carl-Daniel Hailfinger
5b997c3ed6 Split off programmer.h from flash.h
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

Corresponding to flashrom svn r1112.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
2010-07-27 22:41:39 +00:00
Uwe Hermann
439597032e Various coding style and cosmetic changes
- Fix coding-style, whitespace, and indentation in a few places.

 - Consistently use the same spelling ("Super I/O") everywhere.

Corresponding to flashrom svn r933.

 - 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>
2010-03-13 17:28:29 +00:00
Patrick Georgi
06602c239c Windows wants UNC names for COM ports >9 (legacy COM ports only work with 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.

Corresponding to flashrom svn r883.

Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
2010-01-26 20:58:40 +00:00
Sean Nelson
ebb4f5fc4a Convert all messages in serial.c to the new message infrastructure
Corresponding to flashrom svn r848.

Signed-off-by: Sean Nelson <audiohacked@gmail.com>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
2010-01-09 23:46:39 +00:00
Patrick Georgi
e48654cf70 Buspiratespi support on mingw
Corresponding to flashrom svn r832.

Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
2010-01-06 22:14:39 +00:00
Patrick Georgi
3b6237dbce Multiple unrelated changes
- replace the hand written serial input flush routine with the termios one.
- 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

Corresponding to flashrom svn r831.

Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
Acked-by: Sean Nelson <audiohacked@gmail.com>
2010-01-06 19:09:40 +00:00
Carl-Daniel Hailfinger
efa151eb10 Move OS-dependent serial code from buspirate_spi.c to serial.c
While at it, also rename a few functions to make it obvious
that they are generic and not specific to the Bus Pirate.

Corresponding to flashrom svn r830.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Patrick Georgi <patrick.georgi@coresystems.de>
2010-01-06 16:09:10 +00:00
Carl-Daniel Hailfinger
e51ea10a88 Move serial handling from serprog.c to serial.c
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.

Corresponding to flashrom svn r771.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
2009-11-23 19:20:11 +00:00