From: Christopher H. <ch...@us...> - 2003-01-24 09:26:06
|
Update of /cvsroot/blob/blob/src/blob In directory sc8-pr-cvs1:/tmp/cvs-serv14402/src/blob Modified Files: flash.c intel16.c Log Message: add (optional) support for cfi query to build flash descriptors automagically; implemented for 16-bit wide intel parts Index: flash.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/flash.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- flash.c 9 May 2002 13:27:05 -0000 1.18 +++ flash.c 24 Jan 2003 09:26:00 -0000 1.19 @@ -133,6 +133,27 @@ if(flash_driver->disable_vpp == NULL) flash_driver->disable_vpp = flash_dummy_ok; + if (flash_descriptors[0].num == -1) { + u32 *flashAddr = (u32 *) flash_descriptors[0].size; + flash_descriptor_t *d; + int rc; + + if (flash_driver->query_descriptors == 0) { + deprintf("driver does not support query_descriptors\n"); + flash_descriptors = 0; + return; + } + + rc = flash_driver->query_descriptors(flashAddr, &d); + if (rc) { + deprintf("driver failed to query flash for descriptors\n"); + flash_descriptors = 0; + return; + } + + flash_descriptors = d; + } + /* initialise flash blocks table */ num_flash_blocks = 0; Index: intel16.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/intel16.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- intel16.c 11 Mar 2002 22:06:55 -0000 1.6 +++ intel16.c 24 Jan 2003 09:26:01 -0000 1.7 @@ -31,6 +31,7 @@ #include <blob/util.h> #include <blob/serial.h> #include <blob/time.h> +#include <blob/debug.h> /* flash commands for a single 16 bit intel flash chip */ #define READ_ARRAY 0x000000FF @@ -39,6 +40,7 @@ #define PGM_SETUP 0x00000040 #define STATUS_READ 0x00000070 #define STATUS_CLEAR 0x00000050 +#define READ_QUERY 0x00000098 #define STATUS_READY 0x00000080 #define STATUS_ERASE_SUSP 0x00000040 @@ -324,11 +326,72 @@ } +/* automatic descriptor support */ + +#define MAX_AUTO_DESCRIPTORS 4 +static flash_descriptor_t auto_descriptors[MAX_AUTO_DESCRIPTORS + 1]; + +static int flash_query_descriptors_intel16(u32 *flashAddr, + flash_descriptor_t **out) +{ + u16 *addr = (u16 *) flashAddr; + int result, nregions, n; + + addr[0x55] = READ_QUERY; + barrier(); + + if (addr[0x10] != 'Q' && addr[0x11] != 'R' && addr[0x12] != 'Y') { + result = -EINVAL; + goto out; + } + + dprintf("intel16: manuf_code = %02X\n", addr[CFI_MANUF_CODE]); + dprintf("intel16: device code = %02X\n", addr[CFI_DEVICE_CODE]); + dprintf("intel16: device size = 2^%d bytes\n", addr[CFI_DEVICE_SIZE_LG2]); + + nregions = addr[CFI_ERASE_REGION_COUNT]; + +#define READ_U16LE(off) ((addr[(off)]) | (addr[(off) + 1]<<8)) + + for (n = 0; n < nregions && n < MAX_AUTO_DESCRIPTORS; n++) { + u32 xcount = READ_U16LE(CFI_ERASE_REGION_XBLKS(n)); + u32 count = xcount + 1; + u32 xsize = READ_U16LE(CFI_ERASE_REGION_XSIZE(n)); + u32 size = (xsize == 0) ? 128 : xsize * 256; + + dprintf("intel16: erase region #%d\n", n); + dprintf("intel16: count = %d\n", count); + dprintf("intel16: size = %d\n", size); + + auto_descriptors[n].size = size; + auto_descriptors[n].num = count; + auto_descriptors[n].lockable = 1; /* fix me */ + } + +#undef READ_U16LE + + auto_descriptors[n].size = 0; + auto_descriptors[n].num = 0; + + *out = auto_descriptors; + result = 0; + +out: + /* put flash back into Read Array mode */ + barrier(); + + *addr = READ_ARRAY; + barrier(); + + return result; +} + /* flash driver structure */ flash_driver_t intel16_flash_driver = { - erase: flash_erase_intel16, - write: flash_write_intel16, - lock_block: flash_lock_block_intel16, - unlock_block: flash_unlock_block_intel16, - query_block_lock: flash_query_block_lock_intel16 + .erase = flash_erase_intel16, + .write = flash_write_intel16, + .lock_block = flash_lock_block_intel16, + .unlock_block = flash_unlock_block_intel16, + .query_block_lock = flash_query_block_lock_intel16, + .query_descriptors = flash_query_descriptors_intel16 }; |