diff --git a/doc/README.board-dependent-flash b/doc/README.board-dependent-flash new file mode 100644 index 0000000..d71cf49 --- /dev/null +++ b/doc/README.board-dependent-flash @@ -0,0 +1,145 @@ +How to use CFI-Flash and board depended driver together +========================================================= + +1. OVERVIEW +----------- +If CFG_FLASH_BOARD_DRIVER is defined, the following functions are renamed +in CFI_XXXX: flash_print_info + flash_erase + write_buff + flash_real_protect + +They can be called now by the board flash functions. + + +2. Target/Broard dependent Driver +--------------------------------- + +You can use the following functions as pattern for your own implementation: + + +/*---------------------------------------------------------------------------*/ +/* boardflash.c */ +/*---------------------------------------------------------------------------*/ + +extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; + +/*---------------------------------------------------------------------------*/ + +ulong board_flash_get_size (ulong base, int banknum) +{ + flash_info_t *info = &flash_info[banknum]; + + if (base == CFG_INT_FLASH_BASE) + { + debug("Use Board Flash-Init at %p\n",base); + /* put your on code here */ + } + else + { + debug("Use CFI Flash-Init at %p\n",base); + flash_get_size (base,banknum); + } + + return (info->size); +} + +/*---------------------------------------------------------------------------*/ + +void flash_print_info (flash_info_t * info) +{ + int i; + + switch (info->flash_id & FLASH_VENDMASK) { + case : + /* put your on code here */ + break; + default: + cfi_flash_print_info (info); + return; + break; + } + + puts (" Size: "); + if ((info->size >> 20) > 0) + { + printf ("%ld MiB",info->size >> 20); + } + else + { + printf ("%ld KiB",info->size >> 10); + } + printf (" in %d Sectors\n", info->sector_count); + + printf (" Sector Start Addresses:"); + for (i = 0; i < info->sector_count; i++) { + if ((i % 4) == 0) { + printf ("\n "); + } + printf ("%02d: %08lX%s ", i,info->start[i], + info->protect[i] ? " P" : " "); + } + printf ("\n\n"); +} + +/*---------------------------------------------------------------------------*/ + +int flash_erase (flash_info_t * info, int s_first, int s_last) +{ + int iflag, cflag; + int sector; + int rc; + + switch (info->flash_id & FLASH_VENDMASK) + { + case : + /* put your on code here */ + break; + default: + rc=cfi_flash_erase (info,s_first,s_last); + } + return rc; +} + +/*---------------------------------------------------------------------------*/ + +int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) +{ + int rc; + + switch (info->flash_id & FLASH_VENDMASK) + { + case (: + /* put your on code here */ + break; + default: + rc = cfi_write_buff (info,src,addr,cnt); + } + return rc; +} + +/*---------------------------------------------------------------------------*/ + +#ifdef CFG_FLASH_PROTECTION + +int flash_real_protect(flash_info_t * info,long sector,int prot) +{ + int rc; + + switch (info->flash_id & FLASH_VENDMASK) + { + case : + /* put your on code here */ + break; + default: + rc = cfi_flash_real_protect(info,sector,prot); + } + return rc; +} + +#endif +/*---------------------------------------------------------------------------*/ +/* end of boardflash.c */ +/*---------------------------------------------------------------------------*/ + + diff --git a/drivers/cfi_flash.c b/drivers/cfi_flash.c index fd0a186..9c05130 100644 --- a/drivers/cfi_flash.c +++ b/drivers/cfi_flash.c @@ -71,6 +71,13 @@ * Verify erase and program timeouts. */ +#ifdef CFG_FLASH_BOARD_DRIVER +#define flash_print_info cfi_flash_print_info +#define flash_erase cfi_flash_erase +#define write_buff cfi_write_buff +#define flash_real_protect cfi_flash_real_protect +#endif + #ifndef CFG_FLASH_BANKS_LIST #define CFG_FLASH_BANKS_LIST { CFG_FLASH_BASE } #endif @@ -353,8 +360,13 @@ unsigned long flash_init (void) /* Init: no FLASHes known */ for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) { + flash_info[i].flash_id = FLASH_UNKNOWN; +#ifdef CFG_FLASH_BOARD_DRIVER + size += flash_info[i].size = board_flash_get_size (bank_base[i], i); +#else size += flash_info[i].size = flash_get_size (bank_base[i], i); +#endif if (flash_info[i].flash_id == FLASH_UNKNOWN) { #ifndef CFG_FLASH_QUIET_TEST printf ("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n", @@ -641,7 +653,7 @@ int write_buff (flash_info_t * info, uch i = cnt; if ((rc = flash_write_cfibuffer (info, wp, src, i)) != ERR_OK) return rc; - i -= i & (info->portwidth - 1); + i -= (i % info->portwidth); wp += i; src += i; cnt -= i;