aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-11-25 16:41:50 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-11-25 16:41:50 +0000
commit2925d6f11d1f7463385baeda6088b31d06be5714 (patch)
tree265276896cd23e63a97b18625f43a57861d01a48
parent411d7c15261f47a1ef9eb22660acf9800c6ed9f4 (diff)
downloadflashrom-2925d6f11d1f7463385baeda6088b31d06be5714.tar.gz
flashrom-2925d6f11d1f7463385baeda6088b31d06be5714.tar.bz2
flashrom-2925d6f11d1f7463385baeda6088b31d06be5714.zip
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. Corresponding to flashrom svn r779. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Sean Nelson <audiohacked@gmail.com>
-rw-r--r--jedec.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/jedec.c b/jedec.c
index 69a59b32..f352c6be 100644
--- a/jedec.c
+++ b/jedec.c
@@ -262,7 +262,7 @@ int erase_chip_jedec(struct flashchip *flash)
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 @@ retry:
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,32 @@ retry:
}
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;
+ chipaddr olddst;
+ olddst = dst;
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", olddst);
- 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 +363,13 @@ int write_jedec(struct flashchip *flash, uint8_t *buf)
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;
}