From: Erik M. <er...@us...> - 2001-12-28 01:06:17
|
Update of /cvsroot/blob/blob/src/blob In directory usw-pr-cvs1:/tmp/cvs-serv15022/src/blob Modified Files: amd32.c intel16.c intel32.c nullflash.c Log Message: Flash update from Chris Hoover. This part only applies the mechanisms. Also updated the AMD and null flash drivers. Index: amd32.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/amd32.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- amd32.c 2001/10/25 09:59:23 1.2 +++ amd32.c 2001/12/28 01:06:12 1.3 @@ -29,6 +29,7 @@ #include <blob/errno.h> #include <blob/flash.h> #include <blob/util.h> +#include <blob/serial.h> /* flash commands for two 16 bit AMD flash chips */ @@ -184,8 +185,44 @@ +static int flash_lock_block_amd32(u32 *blockStart) +{ + /* FIXME: if AMD flash can be locked, this function should be + * fleshed out -- Erik + */ + return 0; +} + + + + +static int flash_unlock_block_amd32(u32 *blockStart) +{ + /* FIXME: if AMD flash can be unlocked, this function should + * be fleshed out -- Erik + */ + return 0; +} + + + + +static int flash_query_block_lock_amd32(u32 *blockStart) +{ + /* FIXME: if AMD flash can be queried, this function should be + * fleshed out -- Erik + */ + return 0; +} + + + + /* flash driver structure */ flash_driver_t amd32_flash_driver = { - erase: flash_erase_amd32, - write: flash_write_amd32, + erase: flash_erase_amd32, + write: flash_write_amd32, + lock_block: flash_lock_block_amd32, + unlock_block: flash_unlock_block_amd32, + query_block_lock: flash_query_block_lock_amd32 }; Index: intel16.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/intel16.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- intel16.c 2001/10/25 09:59:23 1.2 +++ intel16.c 2001/12/28 01:06:12 1.3 @@ -29,6 +29,7 @@ #include <blob/errno.h> #include <blob/flash.h> #include <blob/util.h> +#include <blob/serial.h> /* flash commands for a single 16 bit intel flash chip */ @@ -42,6 +43,13 @@ #define STATUS_ERASE_ERR 0x00000020 #define STATUS_PGM_ERR 0x00000010 +#define CONFIG_SETUP 0x00000060 +#define LOCK_SECTOR 0x00000001 +#define UNLOCK_SECTOR 0x000000D0 +#define READ_CONFIG 0x00000090 +#define LOCK_STATUS_LOCKED 0x00000001 +#define LOCK_STATUS_LOCKEDDOWN 0x00000002 + @@ -49,6 +57,9 @@ { u16 result; + *addr = STATUS_CLEAR; + barrier(); + /* prepare for erase */ *addr = ERASE_SETUP; barrier(); @@ -69,8 +80,16 @@ *addr = READ_ARRAY; barrier(); - if((result & STATUS_ERASE_ERR) != 0) + if((result & STATUS_ERASE_ERR) != 0) { +#ifdef BLOB_DEBUG + SerialOutputString(__FUNCTION__ " failed, result=0x"); + SerialOutputHex(result); + SerialOutputString(", addr=0x"); + SerialOutputHex((u32) addr); + SerialOutputByte('\n'); +#endif return -EFLASHERASE; + } return 0; } @@ -82,6 +101,9 @@ { u16 result; + *dst = STATUS_CLEAR; + barrier(); + /* setup flash for writing */ *dst = PGM_SETUP; barrier(); @@ -103,9 +125,21 @@ *dst = READ_ARRAY; barrier(); - if(((result & STATUS_PGM_ERR) != 0) || (*dst != *src)) + if(((result & STATUS_PGM_ERR) != 0) || (*dst != *src)) { +#ifdef BLOB_DEBUG + SerialOutputString(__FUNCTION__ " failed, result=0x"); + SerialOutputHex(result); + SerialOutputString(", dst=0x"); + SerialOutputHex((u32) dst); + SerialOutputString(", *dst=0x"); + SerialOutputHex(*dst); + SerialOutputString(", *src=0x"); + SerialOutputHex(*src); + SerialOutputByte('\n'); +#endif return -EFLASHPGM; - + } + return 0; } @@ -165,8 +199,115 @@ +static int flash_lock_block_intel16(u32 *blockStart) +{ + u16 *p = (u16 *) blockStart; + u16 result; + + *p = STATUS_CLEAR; + barrier(); + + *p = CONFIG_SETUP; + barrier(); + *p = LOCK_SECTOR; + barrier(); + + /* status check */ + *p = STATUS_READ; + barrier(); + + result = *p; + barrier(); + + *p = READ_ARRAY; + barrier(); + + if ((result & STATUS_PGM_ERR) != 0) { +#ifdef BLOB_DEBUG + SerialOutputString(__FUNCTION__ " failed at 0x"); + SerialOutputHex((u32) blockStart); + SerialOutputString(", status=0x"); + SerialOutputHex((u32) result); + SerialOutputByte('\n'); +#endif + return -EFLASHPGM; + } + + return 0; +} + + + + +static int flash_unlock_block_intel16(u32 *blockStart) +{ + u16 *p = (u16 *) blockStart; + u16 result; + + *p = STATUS_CLEAR; + barrier(); + + *p = CONFIG_SETUP; + barrier(); + *p = UNLOCK_SECTOR; + barrier(); + + /* status check */ + *p = STATUS_READ; + barrier(); + + result = *p; + barrier(); + + *p = READ_ARRAY; + barrier(); + + if ((result & STATUS_PGM_ERR) != 0) { +#ifdef BLOB_DEBUG + SerialOutputString(__FUNCTION__ " failed at 0x"); + SerialOutputHex((u32) blockStart); + SerialOutputString(", status=0x"); + SerialOutputHex((u32) result); + SerialOutputByte('\n'); +#endif + return -EFLASHPGM; + } + + return 0; +} + + + + +static int flash_query_block_lock_intel16(u32 *blockStart) +{ + u16 *p = (u16 *) blockStart; + u16 result; + + *p = READ_CONFIG; + barrier(); + result = *(p + 2); + barrier(); + + *blockStart = READ_ARRAY; + barrier(); + +#ifdef BLOB_DEBUG + SerialOutputString(__FUNCTION__ ": status of block starting at 0x"); + SerialOutputHex((u32) blockStart); + SerialOutputString(": 0x"); + SerialOutputHex((u32) result); + SerialOutputByte('\n'); +#endif + + return result & (LOCK_STATUS_LOCKED | LOCK_STATUS_LOCKEDDOWN); +} + /* flash driver structure */ flash_driver_t intel16_flash_driver = { - erase: flash_erase_intel16, - write: flash_write_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 }; Index: intel32.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/intel32.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- intel32.c 2001/10/25 09:59:23 1.2 +++ intel32.c 2001/12/28 01:06:12 1.3 @@ -29,6 +29,7 @@ #include <blob/errno.h> #include <blob/flash.h> #include <blob/util.h> +#include <blob/serial.h> /* flash commands for two 16 bit intel flash chips */ @@ -42,6 +43,13 @@ #define STATUS_ERASE_ERR 0x00200020 #define STATUS_PGM_ERR 0x00100010 +#define CONFIG_SETUP 0x00600060 +#define LOCK_SECTOR 0x00010001 +#define UNLOCK_SECTOR 0x00D000D0 +#define READ_CONFIG 0x00900090 +#define LOCK_STATUS_LOCKED 0x00010001 +#define LOCK_STATUS_LOCKEDDOWN 0x00020002 + @@ -50,6 +58,9 @@ { u32 result; + *addr = data_to_flash(STATUS_CLEAR); + barrier(); + /* prepare for erase */ *addr = data_to_flash(ERASE_SETUP); barrier(); @@ -70,8 +81,16 @@ *addr = data_to_flash(READ_ARRAY); barrier(); - if((result & STATUS_ERASE_ERR) != 0) + if((result & STATUS_ERASE_ERR) != 0) { +#ifdef BLOB_DEBUG + SerialOutputString(__FUNCTION__ " failed, result=0x"); + SerialOutputHex(result); + SerialOutputString(", addr=0x"); + SerialOutputHex((u32) addr); + SerialOutputByte('\n'); +#endif return -EFLASHERASE; + } return 0; } @@ -83,6 +102,9 @@ { u32 result; + *dst = data_to_flash(STATUS_CLEAR); + barrier(); + /* setup flash for writing */ *dst = data_to_flash(PGM_SETUP); barrier(); @@ -104,17 +126,134 @@ *dst = data_to_flash(READ_ARRAY); barrier(); - if(((result & STATUS_PGM_ERR) != 0) || (*dst != *src)) + if(((result & STATUS_PGM_ERR) != 0) || (*dst != *src)) { +#ifdef BLOB_DEBUG + SerialOutputString(__FUNCTION__ "failed, result=0x"); + SerialOutputHex(result); + SerialOutputString(", addr=0x"); + SerialOutputHex((u32) dst); + SerialOutputByte('\n'); +#endif return -EFLASHPGM; - + } + return 0; } +static int flash_lock_block_intel32(u32 *blockStart) +{ + u32 result; + + *blockStart = data_to_flash(STATUS_CLEAR); + barrier(); + + *blockStart = data_to_flash(CONFIG_SETUP); + barrier(); + *blockStart = data_to_flash(LOCK_SECTOR); + barrier(); + + *blockStart = data_to_flash(READ_ARRAY); + barrier(); + + /* status check */ + *blockStart = data_to_flash(STATUS_READ); + barrier(); + + result = data_from_flash(*blockStart); + barrier(); + + *blockStart = data_to_flash(READ_ARRAY); + barrier(); + + if ((result & STATUS_PGM_ERR) != 0) { +#ifdef FLASH_DEBUG + SerialOutputString(__FUNCTION__ " failed at 0x"); + SerialOutputHex((u32) blockStart); + SerialOutputString(", status=0x"); + SerialOutputHex((u32) result); + SerialOutputByte('\n'); +#endif + return -EFLASHPGM; + } + + return 0; +} + + + + +static int flash_unlock_block_intel32(u32 *blockStart) +{ + u32 result; + + *blockStart = data_to_flash(STATUS_CLEAR); + barrier(); + + *blockStart = data_to_flash(CONFIG_SETUP); + barrier(); + *blockStart = data_to_flash(UNLOCK_SECTOR); + barrier(); + + *blockStart = data_to_flash(STATUS_READ); + barrier(); + + result = data_from_flash(*blockStart); + barrier(); + + *blockStart = data_to_flash(READ_ARRAY); + barrier(); + + if ((result & STATUS_PGM_ERR) != 0) { +#ifdef FLASH_DEBUG + SerialOutputString(__FUNCTION__ " failed at 0x"); + SerialOutputHex((u32) blockStart); + SerialOutputString(", status=0x"); + SerialOutputHex((u32) result); + SerialOutputByte('\n'); +#endif + return -EFLASHPGM; + } + + return 0; +} + + + + +static int flash_query_block_lock_intel32(u32 *blockStart) +{ + u32 result; + + *blockStart = data_to_flash(READ_CONFIG); + barrier(); + result = data_from_flash(*(blockStart + 2)); + barrier(); + + *blockStart = data_to_flash(READ_ARRAY); + barrier(); + +#ifdef FLASH_DEBUG + SerialOutputString(__FUNCTION__ ": status of block starting at 0x"); + SerialOutputHex((u32) blockStart); + SerialOutputString(": 0x"); + SerialOutputHex((u32) result); + SerialOutputByte('\n'); +#endif + + return result & (LOCK_STATUS_LOCKED | LOCK_STATUS_LOCKEDDOWN); +} + + + + /* flash driver structure */ flash_driver_t intel32_flash_driver = { - erase: flash_erase_intel32, - write: flash_write_intel32, + erase: flash_erase_intel32, + write: flash_write_intel32, + lock_block: flash_lock_block_intel32, + unlock_block: flash_unlock_block_intel32, + query_block_lock: flash_query_block_lock_intel32 }; Index: nullflash.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/nullflash.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- nullflash.c 2001/10/25 09:59:23 1.3 +++ nullflash.c 2001/12/28 01:06:12 1.4 @@ -57,8 +57,46 @@ +static int flash_lock_block_null(u32 *blockStart) +{ +#ifdef BLOB_DEBUG + printerrprefix(); + SerialOutputString("No flash lock_block() function\n"); +#endif + return -EFLASHPGM; +} + + + +static int flash_unlock_block_null(u32 *blockStart) +{ +#ifdef BLOB_DEBUG + printerrprefix(); + SerialOutputString("No flash unlock_block() function\n"); +#endif + return -EFLASHPGM; +} + + + + +static int flash_query_block_lock_null(u32 *blockStart) +{ +#ifdef BLOB_DEBUG + printerrprefix(); + SerialOutputString("No flash query_block_lock() function\n"); +#endif + return 0; +} + + + + /* flash driver structure */ flash_driver_t null_flash_driver = { - erase: flash_erase_null, - write: flash_write_null, + erase: flash_erase_null, + write: flash_write_null, + lock_block: flash_lock_block_null, + unlock_block: flash_unlock_block_null, + query_block_lock: flash_query_block_lock_null }; |