diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index ced3ba71..fea91dd3 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -12,6 +12,10 @@ src/cmd/cmd_part.c, src/cmd/cmd_pod.c, src/cmd/cmd_shell.c, src/cmd/cmd_svf.c, src/cmd/cmd_writemem.c: Add completion handlers. + * include/urjtag/flash.h, src/flash/detectflash.c: Turn flash detection + handling into an array to make adding new routines easy. Patch by + Jonathan Stroud. + 2011-07-06 Jie Zhang * src/tap/chain.c (urj_tap_chain_connect): Correct checking of the diff --git a/urjtag/include/urjtag/flash.h b/urjtag/include/urjtag/flash.h index 985c53b4..5a61bffd 100644 --- a/urjtag/include/urjtag/flash.h +++ b/urjtag/include/urjtag/flash.h @@ -41,6 +41,9 @@ typedef struct URJ_FLASH_CFI_ARRAY urj_flash_cfi_array_t; +typedef int (*urj_flash_detect_func_t) (urj_bus_t *bus, uint32_t adr, + urj_flash_cfi_array_t **cfi_array); + typedef struct { const char *name; diff --git a/urjtag/src/flash/detectflash.c b/urjtag/src/flash/detectflash.c index d4ccf902..3733a871 100644 --- a/urjtag/src/flash/detectflash.c +++ b/urjtag/src/flash/detectflash.c @@ -47,6 +47,15 @@ urj_flash_cfi_array_t *urj_flash_cfi_array = NULL; +static const urj_flash_detect_func_t urj_flash_detect_funcs[] = { + &urj_flash_cfi_detect, + &urj_flash_jedec_detect, + &urj_flash_amd_detect, +#ifdef JEDEC_EXP + &urj_flash_jedec_exp_detect, +#endif +}; + void urj_flash_cleanup (void) { @@ -59,6 +68,7 @@ urj_flash_detectflash (urj_log_level_t ll, urj_bus_t *bus, uint32_t adr) { urj_flash_cfi_query_structure_t *cfi; const char *s; + int i, ret; if (!bus) { @@ -72,26 +82,12 @@ urj_flash_detectflash (urj_log_level_t ll, urj_bus_t *bus, uint32_t adr) URJ_BUS_PREPARE (bus); - if (urj_flash_cfi_detect (bus, adr, &urj_flash_cfi_array) != URJ_STATUS_OK) + for (i = 0; i < ARRAY_SIZE (urj_flash_detect_funcs); ++i) { - urj_flash_cleanup(); - if (urj_flash_jedec_detect (bus, adr, &urj_flash_cfi_array) - != URJ_STATUS_OK) - { - urj_flash_cleanup(); - if (urj_flash_amd_detect (bus, adr, &urj_flash_cfi_array) - != URJ_STATUS_OK) - { - urj_flash_cleanup(); -#ifdef JEDEC_EXP - if (urj_flash_jedec_exp_detect (bus, adr, &urj_flash_cfi_array) - != URJ_STATUS_OK) - { - urj_flash_cleanup(); - } -#endif - } - } + ret = urj_flash_detect_funcs[i] (bus, adr, &urj_flash_cfi_array); + if (ret == URJ_STATUS_OK) + break; + urj_flash_cleanup (); } if (urj_flash_cfi_array == NULL)