From afea62b622c876704615cf3669d41825dc41dc68 Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Sun, 2 Nov 2003 22:41:18 +0000 Subject: [PATCH] 2003-11-02 Marcel Telka * cmd/cmd_detectflash.c (cmd_detectflash_run, cmd_detectflash_help): Added new address parameter for 'detectflash' command. * flash/detectflash.c (detectflash): Added support for detecting flashes in full address range. Added new global parameter cfi_array. * flash/intel.c (intel_flash_autodetect32, intel_flash_autodetect, intel_flash_autodetect8): Added start address of cfi_array for bus_area() calls. (_intel_flash_print_info): Added start address of cfi_array for bus related function calls. Changed first function parameter. All function callers updated. (intel_flash_print_info, intel_flash_print_info32, intel_flash_erase_block, intel_flash_unlock_block) (intel_flash_program, intel_flash_erase_block32, intel_flash_unlock_block32, intel_flash_program32) (intel_flash_readarray32, intel_flash_readarray): Added start address of cfi_array for bus related function calls. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@584 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- libbrux/ChangeLog | 16 ++++++++++ libbrux/NEWS | 2 ++ libbrux/cmd/cmd_detectflash.c | 13 +++++++-- libbrux/flash/detectflash.c | 15 ++++++---- libbrux/flash/intel.c | 55 ++++++++++++++++++----------------- 5 files changed, 65 insertions(+), 36 deletions(-) diff --git a/libbrux/ChangeLog b/libbrux/ChangeLog index b9537a41..f7f2e9a8 100644 --- a/libbrux/ChangeLog +++ b/libbrux/ChangeLog @@ -1,3 +1,19 @@ +2003-11-02 Marcel Telka + + * cmd/cmd_detectflash.c (cmd_detectflash_run, cmd_detectflash_help): Added new address parameter for 'detectflash' + command. + * flash/detectflash.c (detectflash): Added support for detecting flashes in full address range. + Added new global parameter cfi_array. + + * flash/intel.c (intel_flash_autodetect32, intel_flash_autodetect, intel_flash_autodetect8): Added + start address of cfi_array for bus_area() calls. + (_intel_flash_print_info): Added start address of cfi_array for bus related function calls. + Changed first function parameter. + All function callers updated. + (intel_flash_print_info, intel_flash_print_info32, intel_flash_erase_block, intel_flash_unlock_block) + (intel_flash_program, intel_flash_erase_block32, intel_flash_unlock_block32, intel_flash_program32) + (intel_flash_readarray32, intel_flash_readarray): Added start address of cfi_array for bus related function calls. + 2003-09-23 Marcel Telka * flash/amd.c (amd_flash_autodetect16): New function (Bradley D. LaRonde). diff --git a/libbrux/NEWS b/libbrux/NEWS index 05955758..991b7b00 100644 --- a/libbrux/NEWS +++ b/libbrux/NEWS @@ -1,5 +1,7 @@ $Id$ +2003-11-02: Added support for detecting flashes (detectflash) in full address range. +2003-11-02: Added support for Intel flash located at any address. 2003-09-23: Added initial JEDEC detection for flash chips (Bradley D. LaRonde). 2003-09-23: Added support for AMD Am29LV800B flash (Bradley D. LaRonde). 2003-09-23: Added support for 1 x 16 AMD flash (Bradley D. LaRonde). diff --git a/libbrux/cmd/cmd_detectflash.c b/libbrux/cmd/cmd_detectflash.c index 64149c30..2a98d117 100644 --- a/libbrux/cmd/cmd_detectflash.c +++ b/libbrux/cmd/cmd_detectflash.c @@ -32,7 +32,9 @@ static int cmd_detectflash_run( char *params[] ) { - if (cmd_params( params ) != 1) + uint32_t adr; + + if (cmd_params( params ) != 2) return -1; if (!bus) { @@ -40,7 +42,10 @@ cmd_detectflash_run( char *params[] ) return 1; } - detectflash( bus ); + if (cmd_get_number( params[1], &adr )) + return -1; + + detectflash( bus, adr ); return 1; } @@ -49,8 +54,10 @@ static void cmd_detectflash_help( void ) { printf( _( - "Usage: %s\n" + "Usage: %s ADDRESS\n" "Detect flash memory type connected to a part.\n" + "\n" + "ADDRESS Base address for memory region\n" ), "detectflash" ); } diff --git a/libbrux/flash/detectflash.c b/libbrux/flash/detectflash.c index 84da41e0..dce587ed 100644 --- a/libbrux/flash/detectflash.c +++ b/libbrux/flash/detectflash.c @@ -40,12 +40,13 @@ #include #include +cfi_array_t *cfi_array = NULL; + int jedec_detect( bus_t *bus, uint32_t adr, cfi_array_t **cfi_array ); void -detectflash( bus_t *bus ) +detectflash( bus_t *bus, uint32_t adr ) { - cfi_array_t *cfi_array = NULL; cfi_query_structure_t *cfi; const char *s; @@ -54,13 +55,17 @@ detectflash( bus_t *bus ) return; } + cfi_array_free( cfi_array ); + cfi_array = NULL; + bus_prepare( bus ); - if (cfi_detect( bus, 0, &cfi_array )) { + if (cfi_detect( bus, adr, &cfi_array )) { cfi_array_free( cfi_array ); cfi_array = NULL; - if (jedec_detect( bus, 0, &cfi_array ) != 0) { + if (jedec_detect( bus, adr, &cfi_array ) != 0) { cfi_array_free( cfi_array ); + cfi_array = NULL; printf( _("Flash not found!\n") ); return; } @@ -191,6 +196,4 @@ detectflash( bus_t *bus ) printf( _("\t\t\tNumber of Erase Blocks: %d\n"), cfi->device_geometry.erase_block_regions[i].number_of_erase_blocks ); } } - - cfi_array_free( cfi_array ); } diff --git a/libbrux/flash/intel.c b/libbrux/flash/intel.c index 60cd946b..2da05968 100644 --- a/libbrux/flash/intel.c +++ b/libbrux/flash/intel.c @@ -59,7 +59,7 @@ intel_flash_autodetect32( cfi_array_t *cfi_array ) { bus_area_t area; - if (bus_area( cfi_array->bus, 0, &area ) != 0) + if (bus_area( cfi_array->bus, cfi_array->address, &area ) != 0) return 0; return ((cfi_array->cfi_chips[0]->cfi.identification_string.pri_id_code == CFI_VENDOR_INTEL_ECS) @@ -72,7 +72,7 @@ intel_flash_autodetect( cfi_array_t *cfi_array ) { bus_area_t area; - if (bus_area( cfi_array->bus, 0, &area ) != 0) + if (bus_area( cfi_array->bus, cfi_array->address, &area ) != 0) return 0; return ((cfi_array->cfi_chips[0]->cfi.identification_string.pri_id_code == CFI_VENDOR_INTEL_ECS) @@ -85,7 +85,7 @@ intel_flash_autodetect8( cfi_array_t *cfi_array ) { bus_area_t area; - if (bus_area( cfi_array->bus, 0, &area ) != 0) + if (bus_area( cfi_array->bus, cfi_array->address, &area ) != 0) return 0; return ((cfi_array->cfi_chips[0]->cfi.identification_string.pri_id_code == CFI_VENDOR_INTEL_ECS) @@ -94,11 +94,12 @@ intel_flash_autodetect8( cfi_array_t *cfi_array ) } static void -_intel_flash_print_info( bus_t *bus, int o ) +_intel_flash_print_info( cfi_array_t *cfi_array, int o ) { uint32_t mid, cid; + bus_t *bus = cfi_array->bus; - mid = (bus_read( bus, 0x00 << o ) & 0xFF); + mid = (bus_read( bus, cfi_array->address + (0x00 << o) ) & 0xFF); switch (mid) { case STD_MIC_INTEL: printf( _("Manufacturer: %s\n"), STD_MICN_INTEL ); @@ -109,7 +110,7 @@ _intel_flash_print_info( bus_t *bus, int o ) } printf( _("Chip: ") ); - cid = (bus_read( bus, 0x01 << o ) & 0xFFFF); + cid = (bus_read( bus, cfi_array->address + (0x01 << o) ) & 0xFFFF); switch (cid) { case 0x0016: printf( "28F320J3A\n" ); @@ -144,7 +145,7 @@ _intel_flash_print_info( bus_t *bus, int o ) } /* Read Array */ - bus_write( bus, 0 << o, 0x00FF00FF ); + bus_write( bus, cfi_array->address + (0 << o), 0x00FF00FF ); } static void @@ -157,12 +158,12 @@ intel_flash_print_info( cfi_array_t *cfi_array ) /* TODO */ /* Clear Status Register */ - bus_write( bus, 0 << o, 0x0050 ); + bus_write( bus, cfi_array->address + (0 << o), 0x0050 ); /* Read Identifier Command */ - bus_write( bus, 0 << 0, 0x0090 ); + bus_write( bus, cfi_array->address + (0 << 0), 0x0090 ); - _intel_flash_print_info( bus, o ); + _intel_flash_print_info( cfi_array, o ); } static void @@ -174,12 +175,12 @@ intel_flash_print_info32( cfi_array_t *cfi_array ) /* TODO */ /* Clear Status Register */ - bus_write( bus, 0 << o, 0x00500050 ); + bus_write( bus, cfi_array->address + (0 << o), 0x00500050 ); /* Read Identifier Command */ - bus_write( bus, 0 << 0, 0x00900090 ); + bus_write( bus, cfi_array->address + (0 << 0), 0x00900090 ); - _intel_flash_print_info( bus, o ); + _intel_flash_print_info( cfi_array, o ); } static int @@ -188,11 +189,11 @@ intel_flash_erase_block( cfi_array_t *cfi_array, uint32_t adr ) uint16_t sr; bus_t *bus = cfi_array->bus; - bus_write( bus, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( bus, cfi_array->address, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); bus_write( bus, adr, CFI_INTEL_CMD_BLOCK_ERASE ); bus_write( bus, adr, CFI_INTEL_CMD_CONFIRM ); - while (!((sr = bus_read( bus, 0 ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (!((sr = bus_read( bus, cfi_array->address ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ switch (sr & ~CFI_INTEL_SR_READY) { case 0: @@ -219,11 +220,11 @@ intel_flash_unlock_block( cfi_array_t *cfi_array, uint32_t adr ) uint16_t sr; bus_t *bus = cfi_array->bus; - bus_write( bus, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( bus, cfi_array->address, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); bus_write( bus, adr, CFI_INTEL_CMD_LOCK_SETUP ); bus_write( bus, adr, CFI_INTEL_CMD_UNLOCK_BLOCK ); - while (!((sr = bus_read( bus, 0 ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (!((sr = bus_read( bus, cfi_array->address ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ if (sr != CFI_INTEL_SR_READY) { printf( _("flash: unknown error while unblocking\n") ); @@ -238,11 +239,11 @@ intel_flash_program( cfi_array_t *cfi_array, uint32_t adr, uint32_t data ) uint16_t sr; bus_t *bus = cfi_array->bus; - bus_write( bus, 0, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( bus, cfi_array->address, CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); bus_write( bus, adr, CFI_INTEL_CMD_PROGRAM1 ); bus_write( bus, adr, data ); - while (!((sr = bus_read( bus, 0 ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (!((sr = bus_read( bus, cfi_array->address ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ if (sr != CFI_INTEL_SR_READY) { printf( _("flash: unknown error while programming\n") ); @@ -257,11 +258,11 @@ intel_flash_erase_block32( cfi_array_t *cfi_array, uint32_t adr ) uint32_t sr; bus_t *bus = cfi_array->bus; - bus_write( bus, 0, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( bus, cfi_array->address, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); bus_write( bus, adr, (CFI_INTEL_CMD_BLOCK_ERASE << 16) | CFI_INTEL_CMD_BLOCK_ERASE ); bus_write( bus, adr, (CFI_INTEL_CMD_CONFIRM << 16) | CFI_INTEL_CMD_CONFIRM ); - while (((sr = bus_read( bus, 0 ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (((sr = bus_read( bus, cfi_array->address ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ if (sr != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) { printf( "\nsr = 0x%08X\n", sr ); @@ -276,11 +277,11 @@ intel_flash_unlock_block32( cfi_array_t *cfi_array, uint32_t adr ) uint32_t sr; bus_t *bus = cfi_array->bus; - bus_write( bus, 0, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( bus, cfi_array->address, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); bus_write( bus, adr, (CFI_INTEL_CMD_LOCK_SETUP << 16) | CFI_INTEL_CMD_LOCK_SETUP ); bus_write( bus, adr, (CFI_INTEL_CMD_UNLOCK_BLOCK << 16) | CFI_INTEL_CMD_UNLOCK_BLOCK ); - while (((sr = bus_read( bus, 0 ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (((sr = bus_read( bus, cfi_array->address ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ if (sr != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) { printf( "\nsr = 0x%08X\n", sr ); @@ -295,11 +296,11 @@ intel_flash_program32( cfi_array_t *cfi_array, uint32_t adr, uint32_t data ) uint32_t sr; bus_t *bus = cfi_array->bus; - bus_write( bus, 0, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); + bus_write( bus, cfi_array->address, (CFI_INTEL_CMD_CLEAR_STATUS_REGISTER << 16) | CFI_INTEL_CMD_CLEAR_STATUS_REGISTER ); bus_write( bus, adr, (CFI_INTEL_CMD_PROGRAM1 << 16) | CFI_INTEL_CMD_PROGRAM1 ); bus_write( bus, adr, data ); - while (((sr = bus_read( bus, 0 ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ + while (((sr = bus_read( bus, cfi_array->address ) & 0x00FE00FE) & ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ if (sr != ((CFI_INTEL_SR_READY << 16) | CFI_INTEL_SR_READY)) { printf( "\nsr = 0x%08X\n", sr ); @@ -312,14 +313,14 @@ static void intel_flash_readarray32( cfi_array_t *cfi_array ) { /* Read Array */ - bus_write( cfi_array->bus, 0, 0x00FF00FF ); + bus_write( cfi_array->bus, cfi_array->address, 0x00FF00FF ); } static void intel_flash_readarray( cfi_array_t *cfi_array ) { /* Read Array */ - bus_write( cfi_array->bus, 0, 0x00FF00FF ); + bus_write( cfi_array->bus, cfi_array->address, 0x00FF00FF ); } flash_driver_t intel_32_flash_driver = {