Search code examples
linuxu-bootubifs

Copy UBIFS partition to NAND device


I have a working system with u-boot and a UBIFS partition on SLC NAND.

I've copied the UBIFS partition into a binary image file by reading the whole range of blocks it occupies, including spare area.

I can successfully program this image to another NAND device (skipping empty pages) and mount it, thus duplicating the partition. However, if there's a bad block in the new NAND device, I don't know what would be the correct action?

When I try to skip bad blocks (during programming), which seems to be the most reasonable solution, mount from u-boot fails! Can't UBIFS mount process identify that a bad block was skipped? Is there any other simple solution?


Solution

  • 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 :-)