From: Erik M. <er...@us...> - 2002-02-13 00:06:18
|
Update of /cvsroot/blob/blob/src/blob In directory usw-pr-cvs1:/tmp/cvs-serv12603/src/blob Modified Files: flash.c nullflash.c Log Message: - Add functions to walk flash block table - Make flash_descriptors const - Convert SerialOutput*() functions to printf() and friends Index: flash.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/flash.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- flash.c 1 Feb 2002 14:38:55 -0000 1.14 +++ flash.c 13 Feb 2002 00:06:11 -0000 1.15 @@ -37,11 +37,11 @@ #endif #include <blob/arch.h> +#include <blob/debug.h> #include <blob/errno.h> #include <blob/error.h> #include <blob/led.h> #include <blob/util.h> -#include <blob/serial.h> #include <blob/flash.h> #include <blob/init.h> @@ -62,7 +62,7 @@ static flash_block_t flash_blocks[NUM_FLASH_BLOCKS]; static int num_flash_blocks; -flash_descriptor_t *flash_descriptors; +const flash_descriptor_t *flash_descriptors; flash_driver_t *flash_driver; @@ -85,27 +85,22 @@ #ifdef BLOB_DEBUG int i; - SerialOutputString("Flash map:\n"); + printf("Flash map:\n"); for(i = 0; i < num_flash_blocks; i++) { u32 start = flash_blocks[i].start; - SerialOutputDec(i); - SerialOutputString(":\t0x"); - SerialOutputHex(flash_blocks[i].size); - SerialOutputString(" @ 0x"); - SerialOutputHex(start); - SerialOutputString(" ("); - SerialOutputDec(flash_blocks[i].size / 1024); - SerialOutputString(" kB),\t"); + printf("%3i: 0x%08x @ 0x%08x (%i kb), ", + i, flash_blocks[i].size, start, + flash_blocks[i].size / 1024); if(flash_blocks[i].lockable && flash_driver->query_block_lock) { if ((flash_driver->query_block_lock)((u32 *) start)) - SerialOutputString("locked\n"); + printf("locked\n"); else - SerialOutputString("unlocked\n"); + printf("unlocked\n"); } else { - SerialOutputString("not lockable\n"); + printf("not lockable\n"); } } #endif @@ -121,19 +116,15 @@ int j; u32 start = 0; -#ifdef BLOB_DEBUG if(flash_descriptors == NULL) { - printerrprefix(); - SerialOutputString("undefined flash_descriptors\n"); + deprintf("undefined flash_descriptors\n"); return; } if(flash_driver == NULL) { - printerrprefix(); - SerialOutputString("undefined flash_driver\n"); + deprintf("undefined flash_driver\n"); return; } -#endif /* fill out missing flash driver functions */ if(flash_driver->enable_vpp == NULL) @@ -146,17 +137,14 @@ num_flash_blocks = 0; while(flash_descriptors[i].size != 0) { -#ifdef BLOB_DEBUG - SerialOutputDec(flash_descriptors[i].num); - SerialOutputString("x 0x"); - SerialOutputHex(flash_descriptors[i].size); - SerialOutputString(", "); + dprintf("%i x 0x%08x, ", + flash_descriptors[i].num, + flash_descriptors[i].size); if(!flash_descriptors[i].lockable) - SerialOutputString("not "); + dprintf("not "); - SerialOutputString("lockable\n"); -#endif + dprintf("lockable\n"); for(j = 0; j < flash_descriptors[i].num; j++) { flash_blocks[num_flash_blocks].start = start; @@ -170,8 +158,7 @@ num_flash_blocks++; if(num_flash_blocks >= NUM_FLASH_BLOCKS) { - printerrprefix(); - SerialOutputString("not enough flash_blocks\n"); + eprintf("not enough flash_blocks\n"); break; } } @@ -186,6 +173,8 @@ __initlist(init_flash, INIT_LEVEL_OTHER_STUFF + 1); + + int flash_erase_region(u32 *start, u32 nwords) { u32 *cur; @@ -195,32 +184,21 @@ cur = start; end = start + nwords; -#if BLOB_DEBUG - SerialOutputString(__FUNCTION__ "(): erasing 0x"); - SerialOutputHex(nwords); - SerialOutputString(" ("); - SerialOutputDec(nwords); - SerialOutputString(") words at 0x"); - SerialOutputHex((u32)start); - serial_write('\n'); -#endif + dprintf("erasing 0x%08x (%d) words at 0x%08x\n", + nwords, nwords, (unsigned int)start); flash_driver->enable_vpp(); while(cur < end) { if(*cur != 0xffffffff) { - SerialOutputString("erasing dirty block at 0x"); - SerialOutputHex((u32)cur); - serial_write('\n'); + printf("erasing dirty block at 0x%08x\n", (u32)cur); /* dirty block */ rv = flash_driver->erase(cur); if(rv < 0) { - printerrprefix(); - SerialOutputString("flash erase error at 0x"); - SerialOutputHex((u32)cur); - serial_write('\n'); + eprintf("flash erase error at 0x%08x\n", + (u32)cur); flash_driver->disable_vpp(); return rv; } @@ -260,17 +238,8 @@ u32 nscandown = 0; u32 nskip = 0; -#if defined BLOB_DEBUG - SerialOutputString(__FUNCTION__ "(): flashing 0x"); - SerialOutputHex(nwords); - SerialOutputString(" ("); - SerialOutputDec(nwords); - SerialOutputString(") words from 0x"); - SerialOutputHex((u32)src); - SerialOutputString(" to 0x"); - SerialOutputHex((u32)dst); - serial_write('\n'); -#endif + dprintf("flashing 0x%08x (%d) words from 0x%08x to 0x%08x\n", + nwords, nwords, (u32)src, (u32)dst); flash_driver->enable_vpp(); @@ -291,22 +260,20 @@ } else { nerrors++; - SerialOutputString("erasing at 0x"); - SerialOutputHex((u32)&dst[i]); - SerialOutputString("..."); + printf("erasing at 0x%08x...", (u32)&dst[i]); /* erase block at current location */ rv = flash_driver->erase(&dst[i]); nerase++; if(rv < 0) { /* something is obviously wrong */ - SerialOutputString(" error\n"); + printf(" error\n"); flash_driver->disable_vpp(); return rv; } - SerialOutputString(" scanning down..."); + printf(" scanning down..."); /* scan down until we find the first non-erased location and restart writing @@ -317,34 +284,24 @@ nscandown++; } - SerialOutputString(" resume writing at 0x"); - SerialOutputHex((u32)&dst[i]); - serial_write('\n'); + printf(" resume writing at 0x%08x\n", (u32)&dst[i]); } /* there is something seriously wrong if this is true */ if(nerrors > 2 * nwords) { - printerrprefix(); - SerialOutputString("too many flash errors, probably hardware error\n"); + eprintf("too many flash errors, probably hardware error\n"); flash_driver->disable_vpp(); return -EFLASHPGM; } } -#ifdef BLOB_DEBUG - SerialOutputDec(nwords); - SerialOutputString(" words source image\n"); - SerialOutputDec(nwrite); - SerialOutputString(" words written to flash\n"); - SerialOutputDec(nskip); - SerialOutputString(" words skipped\n"); - SerialOutputDec(nerase); - SerialOutputString(" erase operations\n"); - SerialOutputDec(nscandown); - SerialOutputString(" words scanned down\n"); - serial_write('\n'); -#endif + + dprintf("%d words source image\n", nwords); + dprintf("%d words written to flash\n", nwrite); + dprintf("%d words skipped\n", nskip); + dprintf("%d erase operations\n", nerase); + dprintf("%d words scanned down\n", nscandown); flash_driver->disable_vpp(); @@ -382,13 +339,8 @@ { int sb, eib; -#ifdef FLASH_DEBUG - SerialOutputString(__FUNCTION__ ": startAddress = 0x"); - SerialOutputHex(startAddress); - SerialOutputString(", length = 0x"); - SerialOutputHex(length); - SerialOutputString("\n"); -#endif + dprintf("startAddress = 0x%08x, length = 0x%08x\n", + startAddress, length); sb = find_block(startAddress); eib = find_block(startAddress + length - 1); @@ -399,16 +351,11 @@ if(eib < 0) return eib; -#ifdef FLASH_DEBUG - SerialOutputString("sb: "); - SerialOutputDec(sb); - SerialOutputString(", eib: "); - SerialOutputDec(eib); - SerialOutputString("\n"); -#endif + dprintf("sb = %d, eib = %d\n", sb, eib); - // would be nice to warn if sb isn't at the beginning of - // its block or eib isn't at the very end of its block. + /* FIXME: would be nice to warn if sb isn't at the beginning + * of its block or eib isn't at the very end of its block. + */ *startBlock = sb; *endInclBlock = eib; @@ -426,18 +373,10 @@ int i; u32 *addr; -#ifdef BLOB_DEBUG - SerialOutputString(__FUNCTION__ "(): "); - if(lock == 0) - SerialOutputString("un"); - - SerialOutputString("lock at 0x"); - SerialOutputHex((u32)start); - SerialOutputString(", nwords = 0x"); - SerialOutputHex(nwords); - serial_write('\n'); -#endif - + dprintf("%slock at 0x%08x, nwords = 0x%08x\n", + lock ? "" : "un", + (u32)start, nwords); + rv = address_range_to_block_range((u32) start, nwords * sizeof(u32), &sb, &eib); @@ -447,10 +386,7 @@ /* check if it is lockable at all */ for(i = sb; i <= eib; i++) { if(!flash_blocks[i].lockable) { -#ifdef BLOB_DEBUG - printerrprefix(); - SerialOutputString("can't (un)lock unlockable blocks\n"); -#endif + deprintf("can't (un)lock unlockable blocks\n"); return -EFLASHPGM; } } @@ -467,12 +403,8 @@ if(rv < 0) { flash_driver->disable_vpp(); -#ifdef BLOB_DEBUG - printerrprefix(); - SerialOutputString("can't (un)lock block at 0x"); - SerialOutputHex((u32)addr); - serial_write('\n'); -#endif + deprintf("can't (un)lock block at 0x%08x", + (u32)addr); return rv; } } @@ -530,4 +462,45 @@ } return cnt; +} + + + + +int flash_get_first_block_address(u32 *addr) +{ + if(num_flash_blocks != 0) { + *addr = flash_blocks[0].start; + return 0; + } else { + return -ERANGE; + } +} + + + + +int flash_get_next_block_address(u32* addr, u32 current) +{ + int i; + u32 new_addr; + + /* first find the current flash block */ + i = find_block(current); + + /* invalid address? */ + if(i < 0) + return i; + + /* calculate new address and check if it is valid */ + new_addr = flash_blocks[i].start + flash_blocks[i].size; + i = find_block(new_addr); + + if(i < 0) + return i; + + /* it's valid, return new address */ + *addr = new_addr; + + return 0; } Index: nullflash.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/nullflash.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- nullflash.c 28 Dec 2001 01:06:12 -0000 1.4 +++ nullflash.c 13 Feb 2002 00:06:11 -0000 1.5 @@ -25,6 +25,7 @@ # include <blob/config.h> #endif +#include <blob/debug.h> #include <blob/errno.h> #include <blob/error.h> #include <blob/flash.h> @@ -35,10 +36,8 @@ static int flash_erase_null(u32 *addr) { -#ifdef BLOB_DEBUG - printerrprefix(); - SerialOutputString("No flash erase() function\n"); -#endif + deprintf("no flash erase() function\n"); + return -EFLASHERASE; } @@ -47,10 +46,8 @@ static int flash_write_null(u32 *dst, const u32* src) { -#ifdef BLOB_DEBUG - printerrprefix(); - SerialOutputString("No flash write() function\n"); -#endif + deprintf("no flash write() function\n"); + return -EFLASHPGM; } @@ -59,10 +56,8 @@ static int flash_lock_block_null(u32 *blockStart) { -#ifdef BLOB_DEBUG - printerrprefix(); - SerialOutputString("No flash lock_block() function\n"); -#endif + deprintf("no flash lock_block() function\n"); + return -EFLASHPGM; } @@ -70,10 +65,8 @@ static int flash_unlock_block_null(u32 *blockStart) { -#ifdef BLOB_DEBUG - printerrprefix(); - SerialOutputString("No flash unlock_block() function\n"); -#endif + deprintf("no flash unlock_block() function\n"); + return -EFLASHPGM; } @@ -82,10 +75,8 @@ static int flash_query_block_lock_null(u32 *blockStart) { -#ifdef BLOB_DEBUG - printerrprefix(); - SerialOutputString("No flash query_block_lock() function\n"); -#endif + deprintf("no flash query_block_lock() function\n"); + return 0; } |