diff options
author | Peter Stuge <peter@stuge.se> | 2008-06-18 02:08:40 +0000 |
---|---|---|
committer | Peter Stuge <peter@stuge.se> | 2008-06-18 02:08:40 +0000 |
commit | 646eb245e6fd4f974a0dd3d1e57a1871cc7fb3c5 (patch) | |
tree | 82657e953506b5437bff4e0ed80e41ebf9d05958 | |
parent | 01441bd5cfee375c3170da0a34433e176b1796b3 (diff) |
flashrom: Force read unknown flash chips
When flash chip detection fails, it is still useful and possible to read the
flash chip contents. If no flash chip is found in normal probes and the
-f -r -c CHIPNAME options are given, a successful probe for the specified
chip is forced, and then flashrom reads the flash chip using either the read
function for the specified chip, or if there is none, a simple memcpy().
The patch also moves the global variable int force in flashrom.c into main()
and passes it as a parameter to layout.c:show_id(), which was the only other
function that used the variable. This is needed to avoid confusion with the
new parameter int force which is added to flashrom.c:probe_flash() and used
to force probe success for the chip named in char *chip_to_probe.
Signed-off-by: Peter Stuge <peter@stuge.se>
Acked-by: Ward Vandewege <ward@gnu.org>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3367 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
-rw-r--r-- | util/flashrom/flash.h | 2 | ||||
-rw-r--r-- | util/flashrom/flashrom.c | 51 | ||||
-rw-r--r-- | util/flashrom/layout.c | 4 |
3 files changed, 47 insertions, 10 deletions
diff --git a/util/flashrom/flash.h b/util/flashrom/flash.h index b7655555d3..17392ecbf0 100644 --- a/util/flashrom/flash.h +++ b/util/flashrom/flash.h @@ -394,7 +394,7 @@ extern int verbose; int map_flash_registers(struct flashchip *flash); /* layout.c */ -int show_id(uint8_t *bios, int size); +int show_id(uint8_t *bios, int size, int force); int read_romlayout(char *name); int find_romentry(char *name); int handle_romentries(uint8_t *buffer, uint8_t *content); diff --git a/util/flashrom/flashrom.c b/util/flashrom/flashrom.c index e97f19610a..438e843ded 100644 --- a/util/flashrom/flashrom.c +++ b/util/flashrom/flashrom.c @@ -43,7 +43,7 @@ char *chip_to_probe = NULL; struct pci_access *pacc; /* For board and chipset_enable */ int exclude_start_page, exclude_end_page; -int force = 0, verbose = 0; +int verbose = 0; int fd_mem; struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device) @@ -99,7 +99,7 @@ int map_flash_registers(struct flashchip *flash) return 0; } -struct flashchip *probe_flash(struct flashchip *flash) +struct flashchip *probe_flash(struct flashchip *flash, int force) { volatile uint8_t *bios; unsigned long flash_baseaddr, size; @@ -111,7 +111,7 @@ struct flashchip *probe_flash(struct flashchip *flash) } printf_debug("Probing for %s %s, %d KB: ", flash->vendor, flash->name, flash->total_size); - if (!flash->probe) { + if (!flash->probe && !force) { printf_debug("failed! flashrom has no probe function for this flash chip.\n"); flash++; continue; @@ -150,7 +150,7 @@ struct flashchip *probe_flash(struct flashchip *flash) } flash->virtual_memory = bios; - if (flash->probe(flash) == 1) { + if (force || flash->probe(flash) == 1) { printf("Found chip \"%s %s\" (%d KB) at physical address 0x%lx.\n", flash->vendor, flash->name, flash->total_size, flash_baseaddr); @@ -251,6 +251,7 @@ int main(int argc, char *argv[]) struct flashchip *flash, *flashes[3]; int opt; int option_index = 0; + int force = 0; int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0; int ret = 0, i; #ifdef __FreeBSD__ @@ -413,7 +414,7 @@ int main(int argc, char *argv[]) board_flash_enable(lb_vendor, lb_part); for (i = 0; i < ARRAY_SIZE(flashes); i++) { - flashes[i] = probe_flash(i ? flashes[i - 1] + 1 : flashchips); + flashes[i] = probe_flash(i ? flashes[i - 1] + 1 : flashchips, 0); if (!flashes[i]) for (i++; i < ARRAY_SIZE(flashes); i++) flashes[i] = NULL; @@ -427,6 +428,44 @@ int main(int argc, char *argv[]) exit(1); } else if (!flashes[0]) { printf("No EEPROM/flash device found.\n"); + if (!force || !chip_to_probe) { + printf("If you know which flash chip you have, and if this version of flashrom\n"); + printf("supports a similar flash chip, you can try to force read your chip. Run:\n"); + printf("flashrom -f -r -c similar_supported_flash_chip filename\n"); + printf("\n"); + printf("Note: flashrom can never write when the flash chip isn't found automatically.\n"); + } + if (force && read_it && chip_to_probe) { + printf("Force read (-f -r -c) requested, forcing chip probe success:\n"); + flashes[0] = probe_flash(flashchips, 1); + if (!flashes[0]) { + printf("flashrom does not support a flash chip named '%s'.\n", chip_to_probe); + printf("Run flashrom -L to view the hardware supported in this flashrom version.\n"); + exit(1); + } + size = flashes[0]->total_size * 1024; + buf = (uint8_t *) calloc(size, sizeof(char)); + + if ((image = fopen(filename, "w")) == NULL) { + perror(filename); + exit(1); + } + printf("Force reading flash..."); + if (!flashes[0]->read) + memcpy(buf, (const char *)flashes[0]->virtual_memory, size); + else + flashes[0]->read(flashes[0], buf); + + if (exclude_end_position - exclude_start_position > 0) + memset(buf + exclude_start_position, 0, + exclude_end_position - exclude_start_position); + + fwrite(buf, sizeof(char), size, image); + fclose(image); + printf("done\n"); + free(buf); + exit(0); + } // FIXME: flash writes stay enabled! exit(1); } @@ -522,7 +561,7 @@ int main(int argc, char *argv[]) } fread(buf, sizeof(char), size, image); - show_id(buf, size); + show_id(buf, size, force); fclose(image); } diff --git a/util/flashrom/layout.c b/util/flashrom/layout.c index 46fcc431c0..a738fb22d5 100644 --- a/util/flashrom/layout.c +++ b/util/flashrom/layout.c @@ -28,8 +28,6 @@ char *mainboard_vendor = NULL; char *mainboard_part = NULL; int romimages = 0; -extern int force; - #define MAX_ROMLAYOUT 16 typedef struct { @@ -43,7 +41,7 @@ romlayout_t rom_entries[MAX_ROMLAYOUT]; static char *def_name = "DEFAULT"; -int show_id(uint8_t *bios, int size) +int show_id(uint8_t *bios, int size, int force) { unsigned int *walk; |