#define NAND_BLOCK_CNT (8192) // 8192 blocks
#define NAND_PAGE_CNT (32) // Each Block has 32 Pages
#define NAND_PAGE_SIZE (512) // Each Page has 512 Bytes
#define NAND_BLOCK_SIZE (NAND_PAGE_CNT * NAND_PAGE_SIZE)
#define NAND_BBI_OFFSET 5 // Bad block info spare offset
#define NAND_BUS_WIDTH 8 // 8-bit bus
但是FMD_GetBlockStatus 就不一样 了,它是真正的去读flash了,红字的地方,他是根据 nand flash里每个block 的第一个page或第二个page里的spare are 的第6个byte(也就是第517个字节,从512开始算,如果nandflash 是8位总线),下面是我用的K9F1208的资料里的一段话
All device locations are erased(FFh) except locations where the invalid block(s) information is written prior to shipping. The invalid
block(s) status is defined by the 6th byte(X8 device) or 1st word(X16 device) in the spare area. Samsung makes sure that either the
1st or 2nd page of every invalid block has non-FFh(X8 device) or non-FFFFh(X16 device) data at the column address of 517(X8
device) or 256 and 261(X16 device). Since the invalid block information is also erasable in most cases, it is impossible to recover the
information once it has been erased. Therefore, the system must be able to recognize the invalid block(s) based on the original
invalid block information and create the invalid block table via the following suggested flow chart(Figure 4). Any intentional erasure of
the original invalid block information is prohibited.
总之就是以块为单位,读每个块的第一页的spare are区里的第517字节来判断block是否可以使用,这个函数主要是干这个的。调用它的函数就可以知道最后由多好个可以使用的block(如果没有block被 reserve ),那么就可以根据总block数来得到nandflash里的可以使用的容量,接下来就可以reserve ,接着在partition 等等
DWORD FMD_GetBlockStatus(BLOCK_ID blockID)
{
SECTOR_ADDR Sector = (blockID * NAND_PAGE_CNT);
SectorInfo SI[2];
DWORD dwResult = 0;
// Samsung makes sure that either the 1st or 2nd page of every initial
// invalid block has non-FFh data at the column address of 517. Read
// first two page spare areas and to determine block status.
if (!FMD_ReadSector(Sector, NULL, SI, 2))
{
ERRORMSG(TRUE, (_T("NAND block %d status is unknown.\r\n"), blockID));
dwResult = BLOCK_STATUS_UNKNOWN;
goto cleanUp;
}