Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/67364 )
Change subject: attempt to fix programmer global usage ......................................................................
attempt to fix programmer global usage
The map_flash() control flow and life-time is very ill conceived, same with programmer_delay().
Change-Id: I9206ca8ce306b07d2a5da495c900adf6890b3dae Signed-off-by: Edward O'Callaghan quasisec@google.com --- M flashrom.c 1 file changed, 29 insertions(+), 15 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/64/67364/1
diff --git a/flashrom.c b/flashrom.c index 479d442..e72fdf1 100644 --- a/flashrom.c +++ b/flashrom.c @@ -189,17 +189,18 @@ return ret; }
-static void *programmer_map_flash_region(const char *descr, uintptr_t phys_addr, size_t len) +static void *programmer_map_flash_region(const struct programmer_entry *prog, + const char *descr, uintptr_t phys_addr, size_t len) { - void *ret = programmer->map_flash_region(descr, phys_addr, len); + void *ret = prog->map_flash_region(descr, phys_addr, len); msg_gspew("%s: mapping %s from 0x%0*" PRIxPTR " to 0x%0*" PRIxPTR "\n", __func__, descr, PRIxPTR_WIDTH, phys_addr, PRIxPTR_WIDTH, (uintptr_t) ret); return ret; }
-static void programmer_unmap_flash_region(void *virt_addr, size_t len) +static void programmer_unmap_flash_region(const struct programmer_entry *prog, void *virt_addr, size_t len) { - programmer->unmap_flash_region(virt_addr, len); + prog->unmap_flash_region(virt_addr, len); msg_gspew("%s: unmapped 0x%0*" PRIxPTR "\n", __func__, PRIxPTR_WIDTH, (uintptr_t)virt_addr); }
@@ -619,22 +620,22 @@ return limitexceeded; }
-static void unmap_flash(struct flashctx *flash) +static void unmap_flash(const struct programmer_entry *prog, struct flashctx *flash) { if (flash->virtual_registers != (chipaddr)ERROR_PTR) { - programmer_unmap_flash_region((void *)flash->virtual_registers, flash->chip->total_size * 1024); + programmer_unmap_flash_region(prog, (void *)flash->virtual_registers, flash->chip->total_size * 1024); flash->physical_registers = 0; flash->virtual_registers = (chipaddr)ERROR_PTR; }
if (flash->virtual_memory != (chipaddr)ERROR_PTR) { - programmer_unmap_flash_region((void *)flash->virtual_memory, flash->chip->total_size * 1024); + programmer_unmap_flash_region(prog, (void *)flash->virtual_memory, flash->chip->total_size * 1024); flash->physical_memory = 0; flash->virtual_memory = (chipaddr)ERROR_PTR; } }
-static int map_flash(struct flashctx *flash) +static int map_flash(const struct programmer_entry *prog, struct flashctx *flash) { /* Init pointers to the fail-safe state to distinguish them later from legit values. */ flash->virtual_memory = (chipaddr)ERROR_PTR; @@ -648,7 +649,7 @@
const chipsize_t size = flash->chip->total_size * 1024; uintptr_t base = flashbase ? flashbase : (0xffffffff - size + 1); - void *addr = programmer_map_flash_region(flash->chip->name, base, size); + void *addr = programmer_map_flash_region(prog, flash->chip->name, base, size); if (addr == ERROR_PTR) { msg_perr("Could not map flash chip %s at 0x%0*" PRIxPTR ".\n", flash->chip->name, PRIxPTR_WIDTH, base); @@ -662,7 +663,7 @@ * Ignore these problems for now and always report success. */ if (flash->chip->feature_bits & FEATURE_REGISTERMAP) { base = 0xffffffff - size - 0x400000 + 1; - addr = programmer_map_flash_region("flash chip registers", base, size); + addr = programmer_map_flash_region(prog, "flash chip registers", base, size); if (addr == ERROR_PTR) { msg_pdbg2("Could not map flash chip registers %s at 0x%0*" PRIxPTR ".\n", flash->chip->name, PRIxPTR_WIDTH, base); @@ -739,7 +740,7 @@ *flash->chip = *chip; flash->mst = mst;
- if (map_flash(flash) != 0) + if (map_flash(prog, flash) != 0) goto notfound;
/* We handle a forced match like a real match, we just avoid probing. Note that probe_flash() @@ -789,7 +790,7 @@ break; /* Not the first flash chip detected on this bus, and it's just a generic match. Ignore it. */ notfound: - unmap_flash(flash); + unmap_flash(prog, flash); free(flash->chip); flash->chip = NULL; } @@ -823,7 +824,7 @@ flash->chip->printlock(flash);
/* Get out of the way for later runs. */ - unmap_flash(flash); + unmap_flash(prog, flash);
/* Return position of matching chip. */ return chip - flashchips; @@ -1538,7 +1539,7 @@ return 1; }
- if (map_flash(flash) != 0) + if (map_flash(programmer, flash) != 0) // TODO(quasiesec): wire though prog return 1;
/* Initialize chip_restore_fn_count before chip unlock calls. */ @@ -1581,7 +1582,7 @@ void finalize_flash_access(struct flashctx *const flash) { deregister_chip_restore(flash); - unmap_flash(flash); + unmap_flash(programmer, flash); // TODO(quasiesec): wire though prog }
int flashrom_flash_erase(struct flashctx *const flashctx)