From fd72c20e60ff0df892faf56f2e1f6f88262dda2d Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 28 Sep 2010 05:23:53 +0000 Subject: [PATCH] amd_flash: validate the bus address before we read/write it git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1860 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 5 +++++ urjtag/src/flash/amd_flash.c | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 726ef0dc..4ae4b0e0 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -1,3 +1,8 @@ +2010-09-28 Mike Frysinger + + * src/flash/amd_flash.c (urj_flash_amd_detect): Move the bus address range + checks up to before we actually attempt to read/write the bus. + 2010-09-27 Mike Frysinger * data/analog/bf533/bf533: Drop brackets from ADDR and DATA signals to match diff --git a/urjtag/src/flash/amd_flash.c b/urjtag/src/flash/amd_flash.c index d62f9627..fbe115e7 100644 --- a/urjtag/src/flash/amd_flash.c +++ b/urjtag/src/flash/amd_flash.c @@ -101,6 +101,12 @@ urj_flash_amd_detect (urj_bus_t *bus, uint32_t adr, return URJ_STATUS_FAIL; } + (*cfi_array)->bus = bus; + (*cfi_array)->address = adr; + if (URJ_BUS_AREA (bus, adr, &area) != URJ_STATUS_OK) + // retain error state + return URJ_STATUS_FAIL; + URJ_BUS_WRITE (bus, adr + 0x0, 0xf0); URJ_BUS_WRITE (bus, adr + 0x555, 0xaa); URJ_BUS_WRITE (bus, adr + 0x2AA, 0x55); @@ -129,11 +135,6 @@ urj_flash_amd_detect (urj_bus_t *bus, uint32_t adr, break; } - (*cfi_array)->bus = bus; - (*cfi_array)->address = adr; - if (URJ_BUS_AREA (bus, adr, &area) != URJ_STATUS_OK) - // retain error status - return URJ_STATUS_FAIL; /* bus width detection failed */ unsigned int bw = area.width; int ba, i; if (bw != 8 && bw != 16 && bw != 32)