怎么查nandflash的坏块
发布网友
发布时间:2022-04-12 09:55
我来回答
共1个回答
热心网友
时间:2022-04-12 11:24
首先调用erase,将NAND全部擦除一遍,然后执行如下检测操作,
如果页大于512字节,
badblockpos = 0;
badblockbytes = 2;
如果页小于512字节,
badblockpos = 5;
badblockbytes = 1;
读取每个block的前两页OOB区域的第badblockpos开始的后badblockbytes字节是否为0xff,
如果是,那么说明该block是好的,否则该block是坏块[gliethttp_20080523]!
UINT_T create_bbt(FlashBootType_T fbt)
{
UINT_T Retval;
P_FlashProperties_T pFlashP = GetFlashProperties(fbt);
UINT_T BlkSize,BlkNum;
UINT_T flash_addr;
#define page_size (2048)
#define page_spare_size (64)
#define block_size (64*page_size)
#define tmp_buffer_addr (0x80200000 - page_size - page_spare_size)
#define tmp_spare_buffer_addr (tmp_buffer_addr + page_size)
int i,j;
char *bbpos;
bbpos = (char*)(tmp_spare_buffer_addr + 0);
BlkSize = pFlashP->BlockSize;
BlkNum = pFlashP->NumBlocks;
for(i = 0;i < BlkNum;i++)
{
flash_addr = i * BlkSize;
for(j = 0;j < 2;j++)
{
Retval = xdfc_read((UINT_T *)tmp_buffer_addr, flash_addr + j*page_size, page_size, (UINT_T *)tmp_spare_buffer_addr, GetNANDProperties());
if(Retval)
{
goto __create_bbt_mark;
}
if(bbpos[0] != 0xff)goto __create_bbt_mark;
if(bbpos[1] != 0xff)goto __create_bbt_mark;
}
continue;
__create_bbt_mark:
RelocateBlock( i, &GetFMProperties()->BBT, fbt );
}
}