summaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
authorPeter Stuge <peter@stuge.se>2008-06-18 02:08:40 +0000
committerPeter Stuge <peter@stuge.se>2008-06-18 02:08:40 +0000
commit7ffbc6f94d50cdc584913c4f02709ae660664a75 (patch)
tree449704116d9462c2f6a23d0551f1b2dab02e0d42 /flashrom.c
parent663f17197c861126da1a2c16dba48a2ed8900f49 (diff)
downloadast2050-flashrom-7ffbc6f94d50cdc584913c4f02709ae660664a75.zip
ast2050-flashrom-7ffbc6f94d50cdc584913c4f02709ae660664a75.tar.gz
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. Corresponding to flashrom svn r259 and coreboot v2 svn r3367. Signed-off-by: Peter Stuge <peter@stuge.se> Acked-by: Ward Vandewege <ward@gnu.org>
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/flashrom.c b/flashrom.c
index e97f196..438e843 100644
--- a/flashrom.c
+++ b/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);
}
OpenPOWER on IntegriCloud