summaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-05-08 12:49:03 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2009-05-08 12:49:03 +0000
commit03b4e71cb90aaba1b1adba5e534768f981ffcf6f (patch)
treee4f1f23e4861e7d2bc3a1e776b2b1ce8206f4cd1 /flashrom.c
parentb0039911731ea60ee82fa54bc2a0548cbf9efa5c (diff)
downloadast2050-flashrom-03b4e71cb90aaba1b1adba5e534768f981ffcf6f.zip
ast2050-flashrom-03b4e71cb90aaba1b1adba5e534768f981ffcf6f.tar.gz
Don't assume flash is accessible via MMIO for chips with no read function
Flashrom assumes that the flash chip contents are available via mmap if no read function is defined. This special case is handled in lots of places all over the code. Remove the special case and use the read_memmapped function. Not only does this allow us to fix a read bug in flashrom I recently uncovered on ICH SPI, it also allows us to add support for Paraflasher to flashrom. Corresponding to flashrom svn r473. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/flashrom.c b/flashrom.c
index 2a5f1b3..68ef8f0 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -4,6 +4,7 @@
* Copyright (C) 2000 Silicon Integrated System Corporation
* Copyright (C) 2004 Tyan Corp <yhlu@tyan.com>
* Copyright (C) 2005-2008 coresystems GmbH
+ * Copyright (C) 2008,2009 Carl-Daniel Hailfinger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -81,6 +82,18 @@ void map_flash_registers(struct flashchip *flash)
flash->virtual_registers = physmap("flash chip registers", (0xFFFFFFFF - 0x400000 - size + 1), size);
}
+int read_memmapped(struct flashchip *flash, uint8_t *buf)
+{
+ int i;
+
+ /* We could do a memcpy as optimization if the flash is onboard */
+ //memcpy(buf, (const char *)flash->virtual_memory, flash->total_size * 1024);
+ for (i = 0; i < flash->total_size * 1024; i++)
+ buf[i] = chip_readb(flash->virtual_memory + i);
+
+ return 0;
+}
+
struct flashchip *probe_flash(struct flashchip *first_flash, int force)
{
volatile uint8_t *bios;
@@ -145,9 +158,11 @@ int verify_flash(struct flashchip *flash, uint8_t *buf)
int idx;
int total_size = flash->total_size * 1024;
uint8_t *buf2 = (uint8_t *) calloc(total_size, sizeof(char));
- if (flash->read == NULL)
- memcpy(buf2, (const char *)flash->virtual_memory, total_size);
- else
+ if (!flash->read) {
+ printf("FAILED!\n");
+ fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n");
+ return 1;
+ } else
flash->read(flash, buf2);
printf("Verifying flash... ");
@@ -191,9 +206,11 @@ int read_flash(struct flashchip *flash, char *filename, unsigned int exclude_sta
exit(1);
}
printf("Reading flash... ");
- if (flash->read == NULL)
- memcpy(buf, (const char *)flash->virtual_memory, size);
- else
+ if (!flash->read) {
+ printf("FAILED!\n");
+ fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n");
+ return 1;
+ } else
flash->read(flash, buf);
if (exclude_end_position - exclude_start_position > 0)
@@ -219,11 +236,13 @@ int erase_flash(struct flashchip *flash)
fprintf(stderr, "ERROR: flashrom has no erase function for this flash chip.\n");
return 1;
}
- flash->erase(flash);
- if (NULL == flash->read)
- memcpy(buf, (const char *)flash->virtual_memory, size);
- else
+ if (!flash->read) {
+ printf("FAILED!\n");
+ fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n");
+ return 1;
+ } else
flash->read(flash, buf);
+
for (erasedbytes = 0; erasedbytes < size; erasedbytes++)
if (0xff != buf[erasedbytes]) {
printf("FAILED!\n");
@@ -537,9 +556,11 @@ int main(int argc, char *argv[])
exit(1);
}
printf("Force reading flash... ");
- if (!flashes[0]->read)
- memcpy(buf, (const char *)flashes[0]->virtual_memory, size);
- else
+ if (!flashes[0]->read) {
+ printf("FAILED!\n");
+ fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n");
+ return 1;
+ } else
flashes[0]->read(flashes[0], buf);
if (exclude_end_position - exclude_start_position > 0)
@@ -648,6 +669,9 @@ int main(int argc, char *argv[])
*/
// ////////////////////////////////////////////////////////////
+ /* FIXME: This memcpy will not work for SPI nor external flashers.
+ * Convert to chip_readb.
+ */
if (exclude_end_position - exclude_start_position > 0)
memcpy(buf + exclude_start_position,
(const char *)flash->virtual_memory +
OpenPOWER on IntegriCloud