summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2010-01-18 08:14:43 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2010-01-18 08:14:43 +0000
commit293adf0242cdbeb66eb8127c557381027c310ae0 (patch)
tree455859d48819fc3681ea71ad43fd56420c22aa17
parent26f72a14f3ef7c77ac3a00e676d597bbf829ccfc (diff)
downloadast2050-flashrom-293adf0242cdbeb66eb8127c557381027c310ae0.zip
ast2050-flashrom-293adf0242cdbeb66eb8127c557381027c310ae0.tar.gz
Do sanity checks of block erasers at startup and continue check on errors
Flashrom performs a self-check on every startup before it even starts to initialize any programmer. That way, compiler errors and code errors will be caught before they can do any harm. This patch adds an eraseblock structure self-check. It also modifies the self-check code to consistently run all checks even if one check failed. Corresponding to flashrom svn r864. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Sean Nelson <audiohacked@gmail.com>
-rw-r--r--flashrom.c81
1 files changed, 61 insertions, 20 deletions
diff --git a/flashrom.c b/flashrom.c
index db44c2f..5a3c448 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -833,6 +833,54 @@ int read_flash(struct flashchip *flash, char *filename)
return 0;
}
+/* This function shares a lot of its structure with erase_flash(). */
+int selfcheck_eraseblocks(struct flashchip *flash)
+{
+ int i, k;
+
+ for (k = 0; k < NUM_ERASEFUNCTIONS; k++) {
+ unsigned int done = 0;
+ struct block_eraser eraser = flash->block_erasers[k];
+
+ for (i = 0; i < NUM_ERASEREGIONS; i++) {
+ /* Blocks with zero size are bugs in flashchips.c. */
+ if (eraser.eraseblocks[i].count &&
+ !eraser.eraseblocks[i].size) {
+ msg_gerr("ERROR: Flash chip %s erase function "
+ "%i region %i has size 0. Please report"
+ " a bug at flashrom@flashrom.org\n",
+ flash->name, k, i);
+ return 1;
+ break;
+ }
+ /* Blocks with zero count are bugs in flashchips.c. */
+ if (!eraser.eraseblocks[i].count &&
+ eraser.eraseblocks[i].size) {
+ msg_gerr("ERROR: Flash chip %s erase function "
+ "%i region %i has count 0. Please report"
+ " a bug at flashrom@flashrom.org\n",
+ flash->name, k, i);
+ return 1;
+ break;
+ }
+ done += eraser.eraseblocks[i].count *
+ eraser.eraseblocks[i].size;
+ }
+ /* This erase function is completely empty. */
+ if (!done)
+ continue;
+ if (done != flash->total_size * 1024) {
+ msg_gerr("ERROR: Flash chip %s erase function %i "
+ "region walking resulted in 0x%06x bytes total,"
+ " expected 0x%06x bytes. Please report a bug at"
+ " flashrom@flashrom.org\n", flash->name, k,
+ done, flash->total_size * 1024);
+ return 1;
+ }
+ }
+ return 0;
+}
+
int erase_flash(struct flashchip *flash)
{
int i, j, k, ret = 0, found = 0;
@@ -864,17 +912,6 @@ int erase_flash(struct flashchip *flash)
found = 1;
printf_debug("trying... ");
for (i = 0; i < NUM_ERASEREGIONS; i++) {
- /* Blocks with zero size are bugs in flashchips.c.
- * FIXME: This check should be performed on startup.
- */
- if (eraser.eraseblocks[i].count &&
- !eraser.eraseblocks[i].size) {
- fprintf(stderr, "ERROR: Erase region with size "
- "0 for this chip. Please report a bug "
- "at flashrom@flashrom.org\n");
- ret = 1;
- break;
- }
/* count==0 for all automatically initialized array
* members so the loop below won't be executed for them.
*/
@@ -893,10 +930,6 @@ int erase_flash(struct flashchip *flash)
eraser.eraseblocks[i].size;
}
printf_debug("\n");
- if (done != flash->total_size * 1024)
- fprintf(stderr, "ERROR: Erase region walking erased "
- "0x%06x bytes total, expected 0x%06x bytes.",
- done, flash->total_size * 1024);
/* If everything is OK, don't try another erase function. */
if (!ret)
break;
@@ -948,22 +981,30 @@ void print_version(void)
int selfcheck(void)
{
- /* Safety check. */
+ int ret = 0;
+ struct flashchip *flash;
+
+ /* Safety check. Instead of aborting after the first error, check
+ * if more errors exist.
+ */
if (ARRAY_SIZE(programmer_table) - 1 != PROGRAMMER_INVALID) {
fprintf(stderr, "Programmer table miscompilation!\n");
- return 1;
+ ret = 1;
}
if (spi_programmer_count - 1 != SPI_CONTROLLER_INVALID) {
fprintf(stderr, "SPI programmer table miscompilation!\n");
- return 1;
+ ret = 1;
}
#if BITBANG_SPI_SUPPORT == 1
if (bitbang_spi_master_count - 1 != BITBANG_SPI_INVALID) {
fprintf(stderr, "Bitbanging SPI master table miscompilation!\n");
- return 1;
+ ret = 1;
}
#endif
- return 0;
+ for (flash = flashchips; flash && flash->name; flash++)
+ if (selfcheck_eraseblocks(flash))
+ ret = 1;
+ return ret;
}
void check_chip_supported(struct flashchip *flash)
OpenPOWER on IntegriCloud