Download smxNAND User's Guide (NAND Flash Driver)

Transcript
Appendix B: Preprogramming Flash and Handling Bad Blocks
Appendix A provides a way to preprogram flash without handling bad blocks. If you need to preprogram a large
amount of data into the flash chip, the chances are high that your image will span an area with bad blocks. In this
case, your flash burner must know the internal data structure of the flash driver so it can replace each bad block with
a new block. Here are the steps to do this.
1.
Find and read the Block Table in the image file into a memory buffer.
Calculate the block table size, wBlockNum * sizeof(BLOCKNODE)*2.
Allocate a buffer to hold the block table.
Calculate the page number of the block number.
For each block of the image file, check the block table flag. The block table flag is located on the last page of
the block table, at spare area offset BLOCK_TABLE_FLAG_OFFSET, and the value should be
BLOCK_TABLE_FLAG.
For each possible block table area within that block table, check if that block table area is valid, not the
discarded one.
If we find the valid block table area, then read it out and exit that step.
2.
Mark the Block Table as in-progress.
Write IN_PROGRESS_BLOCK_TABLE flag into offset IN_PROGRESS_BLOCK_OFFSET.
3.
Find an empty block in the Block Table, and mark that empty block in the block table to be used. Mark the bad
block in the block table to be bad.
Scan the whole block table to find a block with status bit SPARE_BLOCK.
Replace the bad block entry by that empty block table entry.
4.
Write the data to the new empty block. If it is still bad, go to step 3 until we get a correct one.
5.
Find a new block table position and write the new block table data to it.
Calculate the next block table position.
Check if the new position is a new block.
Update the block table if we need to (new block case).
Write data to the new place.
Write the current block table flag.
6.
Mark the old block table as discarded.
Write DISCARDED_BLOCK_TABLE flag into offset DISCARDED_BLOCK_OFFSET.
We provide sample code to show this, in badblock.c. See the function ReplaceBadBlock() and TODO comments.
You can translate that C code into your burner’s language.
29