From 2b8b490c4f799cae7436ee3b1fcabc0620a306bf Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Thu, 12 Jun 2003 13:10:06 +0000 Subject: [PATCH] 2003-06-10 Marcel Telka * include/flash.h (flash_driver_t): Structure removed. (flash_erase_block, flash_unlock_block, flash_program, flash_readarray): Macro removed. * src/flash.c (set_flash_driver, flashcheck, flashmsbin, flashmem): Updated for new flash_driver_t declared in brux/flash.h in include module. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@484 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 7 +++++++ jtag/include/flash.h | 24 +----------------------- jtag/src/flash.c | 40 +++++++++++++++++++++------------------- 3 files changed, 29 insertions(+), 42 deletions(-) diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 05ad25ac..7b2c2f83 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,10 @@ +2003-06-10 Marcel Telka + + * include/flash.h (flash_driver_t): Structure removed. + (flash_erase_block, flash_unlock_block, flash_program, flash_readarray): Macro removed. + * src/flash.c (set_flash_driver, flashcheck, flashmsbin, flashmem): Updated for new + flash_driver_t declared in brux/flash.h in include module. + 2003-06-10 Marcel Telka * include/Makefile.am (noinst_HEADERS): Removed cfi.h. diff --git a/jtag/include/flash.h b/jtag/include/flash.h index 11146eb5..77b6ccf1 100644 --- a/jtag/include/flash.h +++ b/jtag/include/flash.h @@ -26,33 +26,11 @@ #ifndef FLASH_H #define FLASH_H -#include -#include - -#include "part.h" -#include "bus.h" - -typedef struct { - int buswidth; /* supported bus width, 1/2/4 bytes */ - const char *name; - const char *description; - int (*flash_autodetect)( bus_t *bus, cfi_query_structure_t *cfi ); - void (*flash_print_info)( bus_t *bus ); - int (*flash_erase_block)( bus_t *bus, uint32_t adr ); - int (*flash_unlock_block)( bus_t *bus, uint32_t adr ); - int (*flash_program)( bus_t *bus, uint32_t adr, uint32_t data ); - void (*flash_readarray)( bus_t *bus ); -} flash_driver_t; +#include extern flash_driver_t *flash_driver; extern flash_driver_t *flash_drivers[]; -/* #define flash_print_info flash_driver->flash_print_info */ -#define flash_erase_block flash_driver->flash_erase_block -#define flash_unlock_block flash_driver->flash_unlock_block -#define flash_program flash_driver->flash_program -#define flash_readarray flash_driver->flash_readarray - #define CFI_INTEL_ERROR_UNKNOWN 1 #define CFI_INTEL_ERROR_UNSUPPORTED 2 #define CFI_INTEL_ERROR_LOW_VPEN 3 diff --git a/jtag/src/flash.c b/jtag/src/flash.c index 4e304132..f8752680 100644 --- a/jtag/src/flash.c +++ b/jtag/src/flash.c @@ -60,13 +60,15 @@ flash_driver_t *flash_drivers[] = { flash_driver_t *flash_driver = NULL; static void -set_flash_driver( bus_t *bus, cfi_query_structure_t *cfi ) +set_flash_driver( cfi_array_t *cfi_array ) { int i; + cfi_query_structure_t *cfi = &cfi_array->cfi_chips[0]->cfi; + flash_driver = NULL; for (i = 0; flash_drivers[i] != NULL; i++) - if (flash_drivers[i]->flash_autodetect( bus, cfi )) { + if (flash_drivers[i]->autodetect( cfi_array )) { flash_driver = flash_drivers[i]; return; } @@ -93,12 +95,12 @@ flashcheck( bus_t *bus, cfi_array_t **cfi_array ) return; } - set_flash_driver( bus, &(*cfi_array)->cfi_chips[0]->cfi ); + set_flash_driver( *cfi_array ); if (!flash_driver) { printf( _("Flash not supported!\n") ); return; } - flash_driver->flash_print_info( bus ); + flash_driver->print_info( *cfi_array ); } void @@ -138,9 +140,9 @@ flashmsbin( bus_t *bus, FILE *f ) last = (start + len - 1) / (cfi->device_geometry.erase_block_regions[0].erase_block_size * 2); for (; first <= last; first++) { adr = first * cfi->device_geometry.erase_block_regions[0].erase_block_size * 2; - flash_unlock_block( bus, adr ); + flash_driver->unlock_block( cfi_array, adr ); printf( _("block %d unlocked\n"), first ); - printf( _("erasing block %d: %d\n"), first, flash_erase_block( bus, adr ) ); + printf( _("erasing block %d: %d\n"), first, flash_driver->erase_block( cfi_array, adr ) ); } } @@ -170,7 +172,7 @@ flashmsbin( bus_t *bus, FILE *f ) printf( "\r" ); fflush(stdout); fread( &data, sizeof data, 1, f ); - if (flash_program( bus, a, data )) { + if (flash_driver->program( cfi_array, a, data )) { printf( _("\nflash error\n") ); return; } @@ -180,7 +182,7 @@ flashmsbin( bus_t *bus, FILE *f ) } printf( "\n" ); - flash_readarray( bus ); + flash_driver->readarray( cfi_array ); fseek( f, 15, SEEK_SET ); printf( _("verify:\n") ); @@ -257,39 +259,39 @@ flashmem( bus_t *bus, FILE *f, uint32_t addr ) #define BSIZE 4096 uint8_t b[BSIZE]; int bc = 0, bn = 0; - int block_no = adr / (cfi->device_geometry.erase_block_regions[0].erase_block_size * flash_driver->buswidth / 2); + int block_no = adr / (cfi->device_geometry.erase_block_regions[0].erase_block_size * flash_driver->bus_width / 2); if (!erased[block_no]) { - flash_unlock_block( bus, adr ); + flash_driver->unlock_block( cfi_array, adr ); printf( _("\nblock %d unlocked\n"), block_no ); - printf( _("erasing block %d: %d\n"), block_no, flash_erase_block( bus, adr ) ); + printf( _("erasing block %d: %d\n"), block_no, flash_driver->erase_block( cfi_array, adr ) ); erased[block_no] = 1; } bn = fread( b, 1, BSIZE, f ); - for (bc = 0; bc < bn; bc += flash_driver->buswidth) { + for (bc = 0; bc < bn; bc += flash_driver->bus_width) { int j; printf( _("addr: 0x%08X"), adr ); printf( "\r" ); fflush( stdout ); data = 0; - for (j = 0; j < flash_driver->buswidth; j++) + for (j = 0; j < flash_driver->bus_width; j++) if (big_endian) data = (data << 8) | b[bc + j]; else data |= b[bc + j] << (j * 8); - if (flash_program( bus, adr, data )) { + if (flash_driver->program( cfi_array, adr, data )) { printf( _("\nflash error\n") ); return; } - adr += flash_driver->buswidth; + adr += flash_driver->bus_width; } } printf( "\n" ); - flash_readarray( bus ); + flash_driver->readarray( cfi_array ); fseek( f, 0, SEEK_SET ); printf( _("verify:\n") ); @@ -301,7 +303,7 @@ flashmem( bus_t *bus, FILE *f, uint32_t addr ) uint32_t readed; int j; - if (fread( buf, flash_driver->buswidth, 1, f ) != 1) { + if (fread( buf, flash_driver->bus_width, 1, f ) != 1) { if (feof(f)) break; printf( _("Error during file read.\n") ); @@ -309,7 +311,7 @@ flashmem( bus_t *bus, FILE *f, uint32_t addr ) } data = 0; - for (j = 0; j < flash_driver->buswidth; j++) + for (j = 0; j < flash_driver->bus_width; j++) if (big_endian) data = (data << 8) | buf[j]; else @@ -323,7 +325,7 @@ flashmem( bus_t *bus, FILE *f, uint32_t addr ) printf( _("\nverify error:\nreaded: 0x%08X\nexpected: 0x%08X\n"), readed, data ); return; } - adr += flash_driver->buswidth; + adr += flash_driver->bus_width; } printf( _("\nDone.\n") );