mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
Print an error message on read errors and abort instead of proceeding anyway
Improve error checking in file write, chip read and chip verify. Refactor the read routines a bit to split reading from file writing. Log for a failed read: [...] Found chip "Winbond W25x16" (2048 KB, SPI) at physical address 0xffe00000. Reading flash... Invalid OPCODE 0x03 Read operation failed! FAILED. Corresponding to flashrom svn r1079. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Stephen Kou <stephen@hyarros.com>
This commit is contained in:
parent
4d3e9ca733
commit
1748c5701f
@ -417,7 +417,7 @@ int cli_classic(int argc, char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
printf("Please note that forced reads most likely contain garbage.\n");
|
printf("Please note that forced reads most likely contain garbage.\n");
|
||||||
return read_flash(flashes[0], filename);
|
return read_flash_to_file(flashes[0], filename);
|
||||||
}
|
}
|
||||||
// FIXME: flash writes stay enabled!
|
// FIXME: flash writes stay enabled!
|
||||||
programmer_shutdown();
|
programmer_shutdown();
|
||||||
|
2
flash.h
2
flash.h
@ -579,7 +579,7 @@ void map_flash_registers(struct flashchip *flash);
|
|||||||
int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
|
int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
|
||||||
int erase_flash(struct flashchip *flash);
|
int erase_flash(struct flashchip *flash);
|
||||||
struct flashchip *probe_flash(struct flashchip *first_flash, int force);
|
struct flashchip *probe_flash(struct flashchip *first_flash, int force);
|
||||||
int read_flash(struct flashchip *flash, char *filename);
|
int read_flash_to_file(struct flashchip *flash, char *filename);
|
||||||
void check_chip_supported(struct flashchip *flash);
|
void check_chip_supported(struct flashchip *flash);
|
||||||
int check_max_decode(enum chipbustype buses, uint32_t size);
|
int check_max_decode(enum chipbustype buses, uint32_t size);
|
||||||
int min(int a, int b);
|
int min(int a, int b);
|
||||||
|
61
flashrom.c
61
flashrom.c
@ -713,7 +713,12 @@ int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, c
|
|||||||
starthere = max(start, i * page_size);
|
starthere = max(start, i * page_size);
|
||||||
/* Length of bytes in the range in this page. */
|
/* Length of bytes in the range in this page. */
|
||||||
lenhere = min(start + len, (i + 1) * page_size) - starthere;
|
lenhere = min(start + len, (i + 1) * page_size) - starthere;
|
||||||
flash->read(flash, readbuf, starthere, lenhere);
|
ret = flash->read(flash, readbuf, starthere, lenhere);
|
||||||
|
if (ret) {
|
||||||
|
msg_gerr("Verification impossible because read failed "
|
||||||
|
"at 0x%x (len 0x%x)\n", starthere, lenhere);
|
||||||
|
break;
|
||||||
|
}
|
||||||
for (j = 0; j < lenhere; j++) {
|
for (j = 0; j < lenhere; j++) {
|
||||||
if (cmpbuf[starthere - start + j] != readbuf[j]) {
|
if (cmpbuf[starthere - start + j] != readbuf[j]) {
|
||||||
/* Only print the first failure. */
|
/* Only print the first failure. */
|
||||||
@ -1064,38 +1069,60 @@ int verify_flash(struct flashchip *flash, uint8_t *buf)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_flash(struct flashchip *flash, char *filename)
|
int write_buf_to_file(unsigned char *buf, unsigned long size, char *filename)
|
||||||
{
|
{
|
||||||
unsigned long numbytes;
|
unsigned long numbytes;
|
||||||
FILE *image;
|
FILE *image;
|
||||||
unsigned long size = flash->total_size * 1024;
|
|
||||||
unsigned char *buf = calloc(size, sizeof(char));
|
|
||||||
|
|
||||||
if (!filename) {
|
if (!filename) {
|
||||||
msg_gerr("Error: No filename specified.\n");
|
msg_gerr("No filename specified.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if ((image = fopen(filename, "wb")) == NULL) {
|
if ((image = fopen(filename, "wb")) == NULL) {
|
||||||
perror(filename);
|
perror(filename);
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
msg_cinfo("Reading flash... ");
|
|
||||||
if (!flash->read) {
|
|
||||||
msg_cinfo("FAILED!\n");
|
|
||||||
msg_cerr("ERROR: flashrom has no read function for this flash chip.\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
} else
|
}
|
||||||
flash->read(flash, buf, 0, size);
|
|
||||||
|
|
||||||
numbytes = fwrite(buf, 1, size, image);
|
numbytes = fwrite(buf, 1, size, image);
|
||||||
fclose(image);
|
fclose(image);
|
||||||
free(buf);
|
if (numbytes != size) {
|
||||||
msg_cinfo("%s.\n", numbytes == size ? "done" : "FAILED");
|
msg_gerr("File %s could not be written completely.\n",
|
||||||
if (numbytes != size)
|
filename);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int read_flash_to_file(struct flashchip *flash, char *filename)
|
||||||
|
{
|
||||||
|
unsigned long size = flash->total_size * 1024;
|
||||||
|
unsigned char *buf = calloc(size, sizeof(char));
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
msg_cinfo("Reading flash... ");
|
||||||
|
if (!buf) {
|
||||||
|
msg_gerr("Memory allocation failed!\n");
|
||||||
|
msg_cinfo("FAILED.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!flash->read) {
|
||||||
|
msg_cerr("No read function available for this flash chip.\n");
|
||||||
|
ret = 1;
|
||||||
|
goto out_free;
|
||||||
|
}
|
||||||
|
if (flash->read(flash, buf, 0, size)) {
|
||||||
|
msg_cerr("Read operation failed!\n");
|
||||||
|
ret = 1;
|
||||||
|
goto out_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = write_buf_to_file(buf, flash->total_size * 1024, filename);
|
||||||
|
out_free:
|
||||||
|
free(buf);
|
||||||
|
msg_cinfo("%s.\n", ret ? "FAILED" : "done");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* This function shares a lot of its structure with erase_flash().
|
/* This function shares a lot of its structure with erase_flash().
|
||||||
* Even if an error is found, the function will keep going and check the rest.
|
* Even if an error is found, the function will keep going and check the rest.
|
||||||
*/
|
*/
|
||||||
@ -1444,7 +1471,7 @@ int doit(struct flashchip *flash, int force, char *filename, int read_it, int wr
|
|||||||
if (flash->unlock)
|
if (flash->unlock)
|
||||||
flash->unlock(flash);
|
flash->unlock(flash);
|
||||||
|
|
||||||
if (read_flash(flash, filename)) {
|
if (read_flash_to_file(flash, filename)) {
|
||||||
programmer_shutdown();
|
programmer_shutdown();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user