Found a working method!
The whole purpose of this was to find a simple algorithm for programming NAND flash parts, before soldeing it to the board.
This is done during mass production by a programming machine, and there's no way to use Linux to do that. Since the NAND part is new, no need for wear leveling information, however, it may have 0 to any number of bad blocks, randomly located in the partition area.
The only available steps are:
- skip bad block
- erase
- write
Preparimg image for mass production:
- Make sure UBI volume is smaller that the MTD partition (5% smaller, for example)
- Create UBI volume and UBIFS, and populate it.
- Dump NAND blocks + spare area of pages into a binary file.
It's possible to prepare UBIFS using mkfs and other tools, but than you need to add the ECC information, which the programming machine may not be able to calculate on the fly, and sometimes just don't have the knowledge.
Programming algorithm is as follows:
- Starting at the MTD partition offset, program each image block to NAND block.
- If NAND block is bad skip it, program image block N to NAND block N+1.
- If image block is empty, don't program, advance to next block on both image and NAND chip.
- Continue the same way until last block of UBI volume.
- Program the last block of image at the last good block of MTD partition on the NAND chip.
Hope that helps anyone :-)