Check during SPI bitbang init that SPI bitbang master configuration is correct.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-bitbang_spi_init_errorcheck/flash.h =================================================================== --- flashrom-bitbang_spi_init_errorcheck/flash.h (Revision 1091) +++ flashrom-bitbang_spi_init_errorcheck/flash.h (Arbeitskopie) @@ -128,7 +128,7 @@ void programmer_delay(int usecs);
enum bitbang_spi_master_type { - BITBANG_SPI_DUMMY /* remove as soon as there is a real entry */ + BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */ };
struct bitbang_spi_master { Index: flashrom-bitbang_spi_init_errorcheck/bitbang_spi.c =================================================================== --- flashrom-bitbang_spi_init_errorcheck/bitbang_spi.c (Revision 1091) +++ flashrom-bitbang_spi_init_errorcheck/bitbang_spi.c (Arbeitskopie) @@ -54,6 +54,16 @@
int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod) { + /* BITBANG_SPI_INVALID is 0, so if someone forgot to initialize ->type, + * we catch it here. Same goes for missing initialization of bitbanging + * functions. + */ + if (!master || master->type == BITBANG_SPI_INVALID || !master->set_cs || + !master->set_sck || !master->set_mosi || !master->get_miso) { + msg_perr("Incomplete bitbanging SPI master setting! Please " + "report a bug at flashrom@flashrom.org\n"); + return 1; + } bitbang_spi_master = master; bitbang_spi_half_period = halfperiod;
Am Sonntag, den 18.07.2010, 13:20 +0200 schrieb Carl-Daniel Hailfinger:
Check during SPI bitbang init that SPI bitbang master configuration is correct.
As clarified on IRC, this is meant as tool for people adding new bitbang adapters. As this it is fine. One could think about not building the check if "CONFIG_RELEASE=yes".
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Michael Karcher flashrom@mkarcher.dialup.fu-berlin.de
Regards, Michael Karcher
On 18.07.2010 16:27, Michael Karcher wrote:
Am Sonntag, den 18.07.2010, 13:20 +0200 schrieb Carl-Daniel Hailfinger:
Check during SPI bitbang init that SPI bitbang master configuration is correct.
As clarified on IRC, this is meant as tool for people adding new bitbang adapters. As this it is fine. One could think about not building the check if "CONFIG_RELEASE=yes".
There are quite a few safety checks we could kill in a release build...
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Michael Karcher flashrom@mkarcher.dialup.fu-berlin.de
Thanks, committed in r1092.
Regards, Carl-Daniel