jedec.c was missing error handling in a few cases. Fix.
jedec.c error handling used double negation in too many places for no
good reason. Clean up.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006(a)gmx.net>
Index: flashrom-jedec_errorhandling/jedec.c
===================================================================
--- flashrom-jedec_errorhandling/jedec.c (Revision 777)
+++ flashrom-jedec_errorhandling/jedec.c (Arbeitskopie)
@@ -262,7 +262,7 @@
int write_page_write_jedec(struct flashchip *flash, uint8_t *src,
int start, int page_size)
{
- int i, tried = 0, ok;
+ int i, tried = 0, failed;
uint8_t *s = src;
chipaddr bios = flash->virtual_memory;
chipaddr dst = bios + start;
@@ -287,27 +287,27 @@
dst = d;
src = s;
- ok = !verify_range(flash, src, start, page_size, NULL);
+ failed = verify_range(flash, src, start, page_size, NULL);
- if (!ok && tried++ < MAX_REFLASH_TRIES) {
+ if (failed && tried++ < MAX_REFLASH_TRIES) {
fprintf(stderr, "retrying.\n");
goto retry;
}
- if (!ok) {
+ if (failed) {
fprintf(stderr, " page 0x%lx failed!\n",
(d - bios) / page_size);
}
- return !ok;
+ return failed;
}
int write_byte_program_jedec(chipaddr bios, uint8_t *src,
chipaddr dst)
{
- int tried = 0, ok = 1;
+ int tried = 0, failed = 0;
- /* If the data is 0xFF, don't program it */
+ /* If the data is 0xFF, don't program it and don't complain. */
if (*src == 0xFF) {
- return -1;
+ return 0;
}
retry:
@@ -325,27 +325,30 @@
}
if (tried >= MAX_REFLASH_TRIES)
- ok = 0;
+ failed = 1;
- return !ok;
+ return failed;
}
int write_sector_jedec(chipaddr bios, uint8_t *src,
chipaddr dst, unsigned int page_size)
{
- int i;
+ int i, failed = 0;
for (i = 0; i < page_size; i++) {
- write_byte_program_jedec(bios, src, dst);
+ if (write_byte_program_jedec(bios, src, dst))
+ failed = 1;
dst++, src++;
}
+ if (failed)
+ fprintf(stderr, " writing sector at 0x%lx failed!\n", dst);
- return 0;
+ return failed;
}
int write_jedec(struct flashchip *flash, uint8_t *buf)
{
- int i;
+ int i, failed = 0;
int total_size = flash->total_size * 1024;
int page_size = flash->page_size;
chipaddr bios = flash->virtual_memory;
@@ -358,12 +361,13 @@
printf("Programming page: ");
for (i = 0; i < total_size / page_size; i++) {
printf("%04d at address: 0x%08x", i, i * page_size);
- write_page_write_jedec(flash, buf + i * page_size,
- i * page_size, page_size);
+ if (write_page_write_jedec(flash, buf + i * page_size,
+ i * page_size, page_size))
+ failed = 1;
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
}
printf("\n");
protect_jedec(bios);
- return 0;
+ return failed;
}
--
Developer quote of the month:
"We are juggling too many chainsaws and flaming arrows and tigers."