From 98b488122318764394bdb54f036a62b0fc8050ce Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Fri, 14 Feb 2003 14:41:14 +0000 Subject: [PATCH] 2003-02-14 Marcel Telka * src/readmem.c (readmem): Added support for 1 x 16 bit memory configuration and buffered file writes (Christian Pellegrin). * src/flash.c (flashmem): Added support for 1 x 16 bit flash configuration and buffered file reads (Christian Pellegrin). (flash_erase_block): Added debug messages (Christian Pellegrin). (flash_unlock_block): Added debug message (Christian Pellegrin). (flash_program): Ditto. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@352 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 10 ++++++++++ jtag/NEWS | 3 ++- jtag/src/flash.c | 50 +++++++++++++++++++++++++++++++++++----------- jtag/src/readmem.c | 41 ++++++++++++++++++++++++++++--------- 4 files changed, 82 insertions(+), 22 deletions(-) diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 55cf84d9..eb512868 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,13 @@ +2003-02-14 Marcel Telka + + * src/readmem.c (readmem): Added support for 1 x 16 bit memory configuration and + buffered file writes (Christian Pellegrin). + * src/flash.c (flashmem): Added support for 1 x 16 bit flash configuration and + buffered file reads (Christian Pellegrin). + (flash_erase_block): Added debug messages (Christian Pellegrin). + (flash_unlock_block): Added debug message (Christian Pellegrin). + (flash_program): Ditto. + 2003-02-14 Marcel Telka * src/cfi.c (detect_cfi): Added support for 1 x 16 bit flash configuration (Christian diff --git a/jtag/NEWS b/jtag/NEWS index 95ab470b..4556bada 100644 --- a/jtag/NEWS +++ b/jtag/NEWS @@ -9,7 +9,8 @@ $Id$ * Added JTAG declarations for Intel IXP425 (Christian Pellegrin). * Added bus driver for Intel IXP425 (Christian Pellegrin). * Added JTAG declarations for Xilinx XC2C256-TQ144 (Alessandro Zummo). - * Added support for 1 x 16 bit flash memory detection (Christian Pellegrin). + * Added support for 1 x 16 bit memory configuration (Christian Pellegrin). + * Added buffered file reads/writes (Christian Pellegrin). jtag-0.2.2 (2003-02-04): diff --git a/jtag/src/flash.c b/jtag/src/flash.c index 2fd076cb..e60e8dda 100644 --- a/jtag/src/flash.c +++ b/jtag/src/flash.c @@ -38,6 +38,9 @@ #include #include +#include +/* for ntohs */ + #include "part.h" #include "bus.h" @@ -202,7 +205,7 @@ flashmem( parts *ps, FILE *f, uint32_t addr ) int *erased; int i; - printf( "Note: Supported configuration is 2 x 16 bit only\n" ); + printf( "Note: Supported configuration is 2 x 16 bit or 1 x 16 bit only\n" ); switch (bus_width( ps )) { case 16: @@ -238,28 +241,44 @@ flashmem( parts *ps, FILE *f, uint32_t addr ) adr = addr; while (!feof( f )) { uint32_t data; +#define BSIZE 4096 + char b[BSIZE]; + int bc = 0, bn = 0; + /* FIXME: block_no is probably invalid for 1 x 16 bit memory configuration */ int block_no = adr / (cfi->device_geometry.erase_block_regions[0].erase_block_size * 2); printf( "addr: 0x%08X\r", adr ); if (!erased[block_no]) { - flash_unlock_block32( ps, adr ); + if (o == 1) + flash_unlock_block( ps, adr ); + else + flash_unlock_block32( ps, adr ); printf( "block %d unlocked\n", block_no ); - printf( "erasing block %d: %d\n", block_no, flash_erase_block32( ps, adr ) ); + printf( "erasing block %d: %d\n", block_no, + (o == 1) ? flash_erase_block( ps, adr ) : flash_erase_block32( ps, adr ) ); erased[block_no] = 1; } - fread( &data, sizeof data, 1, f ); - if (flash_program32( ps, adr, data )) { - printf( "\nflash error\n" ); - return; + bn = fread( b, 1, BSIZE, f ); + printf("addr 0x%08X (n is %d)\n", adr, bn); + for (bc = 0; bc < bn; bc += (o == 1) ? 2 : 4) { + if (o == 1) + data = htons( *((uint16_t *) &b[bc]) ); + else + data = * ((uint32_t *) &b[bc]); + if ((o == 1) ? flash_program( ps, adr, data ) : flash_program32( ps, adr, data )) { + printf( "\nflash error\n" ); + return; + } + adr += (o == 1) ? 2 : 4; } - adr += 4; } printf( "\n" ); /* Read Array */ bus_write( ps, 0 << o, 0x00FF00FF ); + if (o != 1) { /* TODO: not available in 1 x 16 bit mode */ fseek( f, 0, SEEK_SET ); printf( "verify:\n" ); adr = addr; @@ -276,6 +295,8 @@ flashmem( parts *ps, FILE *f, uint32_t addr ) adr += 4; } printf( "\nDone.\n" ); + } else + printf( "TODO: Verify is not available in 1 x 16 bit mode.\n" ); /* BYPASS */ parts_set_instruction( ps, "BYPASS" ); @@ -305,10 +326,13 @@ flash_erase_block( parts *ps, uint32_t adr ) case 0: return 0; case CFI_INTEL_SR_ERASE_ERROR | CFI_INTEL_SR_PROGRAM_ERROR: + printf("flash: invalid command seq\n"); return CFI_INTEL_ERROR_INVALID_COMMAND_SEQUENCE; case CFI_INTEL_SR_ERASE_ERROR | CFI_INTEL_SR_VPEN_ERROR: + printf("flash: low vpen\n"); return CFI_INTEL_ERROR_LOW_VPEN; case CFI_INTEL_SR_ERASE_ERROR | CFI_INTEL_SR_BLOCK_LOCKED: + printf("flash: block locked\n"); return CFI_INTEL_ERROR_BLOCK_LOCKED; default: break; @@ -328,9 +352,10 @@ flash_unlock_block( parts *ps, uint32_t adr ) while (!((sr = bus_read( ps, 0 ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ - if (sr != CFI_INTEL_SR_READY) + if (sr != CFI_INTEL_SR_READY) { + printf("flash: unknown error while unblocking\n"); return CFI_INTEL_ERROR_UNKNOWN; - else + } else return 0; } @@ -345,9 +370,10 @@ flash_program( parts *ps, uint32_t adr, uint32_t data ) while (!((sr = bus_read( ps, 0 ) & 0xFE) & CFI_INTEL_SR_READY)) ; /* TODO: add timeout */ - if (sr != CFI_INTEL_SR_READY) + if (sr != CFI_INTEL_SR_READY) { + printf("flash: unknown error while programming\n"); return CFI_INTEL_ERROR_UNKNOWN; - else + } else return 0; } int diff --git a/jtag/src/readmem.c b/jtag/src/readmem.c index e06f9a18..00d6c4f5 100644 --- a/jtag/src/readmem.c +++ b/jtag/src/readmem.c @@ -38,6 +38,10 @@ #include #include +#include +/* for ntohs */ + + #include "part.h" #include "bus.h" @@ -55,7 +59,7 @@ detectflash( parts *ps ) return; } - printf( "Note: Supported configuration is 2 x 16 bit only\n" ); + printf( "Note: Supported configuration is 2 x 16 bit or 1 x 16 bit only\n" ); switch (bus_width( ps )) { case 16: @@ -262,6 +266,7 @@ readmem( parts *ps, FILE *f, uint32_t addr, uint32_t len ) part *p = ps->parts[0]; int step = 0; uint32_t a; + int bc = 0; if (!bus_driver) { printf( "Error: Missing bus_driver!\n" ); @@ -293,15 +298,33 @@ readmem( parts *ps, FILE *f, uint32_t addr, uint32_t len ) printf( "reading:\n" ); bus_read_start( ps, addr ); for (a = addr + step; a <= addr + len; a += step) { - uint32_t d; - - printf( "addr: 0x%08X\r", a ); + uint32_t d = 0; + uint16_t d16 = 0; +#define BSIZE 4096 + char b[BSIZE]; - if (a < addr + len) - d = bus_read_next( ps, a ); - else - d = bus_read_end( ps ); - fwrite( &d, step, 1, f ); + if (a < addr + len) { + if (step == 2) + d16 = bus_read_next( ps, a ); + else + d = bus_read_next( ps, a ); + } + else { + if (step == 2) + d16 = bus_read_end( ps ); + else + d = bus_read_end( ps ); + } + if (step == 2) + *((uint16_t *) &b[bc]) = ntohs(d16); + else + *((uint32_t *) &b[bc]) = d; + bc += step; + if ((bc >= BSIZE) || (a >= (addr + len)) ) { + printf( "addr: 0x%08X\r", a ); + fwrite( b, bc, 1, f ); + bc = 0; + } } printf( "\nDone.\n" );