当NAND flash执行erase all blocks操作时,若某一block执行erase后返回info为OK,是否可以确信该block就valid了?[复制链接]
以下是某一NAND flash的erase all blocks源码.
/*F**************************************************************************
* NAME: nf_erase_all_block
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
* OK : erase done
* KO : erase not done
*----------------------------------------------------------------------------
* PURPOSE:
* This function erase all blocks on a NF card and write CIS information
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* This function use the global variable Uint32 address
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack:
* code:
*****************************************************************************/
bit nf_erase_all_block (void)
{
Byte i;
Uint16 j;
Uint16 block;
Uint16 block_reserved_space;
bit erase;
Nf_CS_ON();
/* Erase all block */
block_reserved_space = (Uint16) (((nf_reserved_space_start >> 5) % 1000));
gl_address = 0;
for (nf_zone = 0; nf_zone < NF_ZONE_MAX_CPT; nf_zone++)
{
for (j = 1024; j != 0; j--)
{
Nf_wait_busy();
Nf_read_open_C_area(gl_address, 0x05); /* Read block status byte */
erase = TRUE;
if (Nf_rd_byte() != 0xFF) /* if bad block */
{
erase = FALSE; /* don't erase block */
}
else
{
((Byte*)&block)[0] = Nf_rd_byte(); /* Read logical block address */
((Byte*)&block)[1] = Nf_rd_byte();
if ( (MEM_RESERVED_SIZE != 0) && (nf_zone == (NF_ZONE_MAX_CPT - 1)))
{
if ((((Byte*)&block)[0] & 0xF8) == 0x10)
{
block = (block & 0x0FFF) >> 1;
if (block >= block_reserved_space) /* If it is a reserved block */
{
erase = FALSE; /* Don't erase block */
}
}
}
}
if (NF_FULL_CHIP_ERASE == FALSE)
{
if (((Byte*)&block)[0] != 0xE8)
{
erase = FALSE;
}
}
else
{
if (((Byte*)&block)[0] == 0x00)
{
erase = FALSE;
}
}
if (erase) //以下开始完成erase
{
nf_block_erase(gl_address);
if (nf_check_status() == KO)
{
nf_mark_bad_block(); /* Failure on erase operation */
}
else //else部分有何作用???
{ /* Fill redundant area with 0x00 */
Nf_write_open_C_area(gl_address, 0x00); // 即spare array
for (i = 16; i != 0; i--)
Nf_wr_byte(0x00);
Nf_send_command(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
if ( nf_check_status() == KO)
{
nf_mark_bad_block(); /* Failure on program operation */
}
else
{
Nf_read_open_C_area(gl_address, 0x00); /* Read 16 bytes */
i = 16;
while ((i != 0) && (Nf_rd_byte() == 0x00)) i--;
if (i)
{
nf_mark_bad_block();
}
else
{
nf_block_erase(gl_address); /* Finally, erase the block */
if ( nf_check_status() == KO)
{ /* Failure on erase operation */
nf_mark_bad_block();
}
}
}
}
}
gl_address += 32;
}
}
return (nf_read_spare_byte());
}