NAND flash boot rootfs

From ElphelWiki
Revision as of 11:46, 9 March 2016 by Oleg (talk | contribs) (Created page with "===Boot from NAND flash=== * The default boot option - power on. * A UBIFS image of rootfs is written to /dev/mtd4 ('''ubi0:elphel393''' in bootargs in the device tree) ====Refla...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Boot from NAND flash

  • The default boot option - power on.
  • A UBIFS image of rootfs is written to /dev/mtd4 (ubi0:elphel393 in bootargs in the device tree)

Reflash factory image (update software/firmware or corrupt flash partition)

  • Use files from .../poky/build/tmp/deploy/images/elphel393/nand/
  • Copy all of the image files to a micro SD card (or boot first from the card then copy over network)
  • Boot from micro SD card.
  • Reflash what is needed:
    • Reflash SPL (boot.bin, /dev/mtd0)

cd <path-to-image-files>
# boot.bin
# mtd0 is 1MB (8 eraseblocks,128K = 1 block, there are 64 pages of 2048 per block)
# erase only first 2 blocks, other block are reserved for copies
flash_unlock /dev/mtd0
flash_erase /dev/mtd0 0 2
nandwrite -n /dev/mtd0 -p boot.bin

    • Reflash u-boot (u-boot-dtb.img, /dev/mtd1)

cd <path-to-image-files>
# u-boot-dtb.img
# mtd1 is 4M (32 eraseblocks,128K = 1 block, there are 64 pages of 2048 per block)
# erase only the 1st 8 blocks as image is <1M, leave unused area for backup copies
flash_unlock /dev/mtd1
flash_erase /dev/mtd1 0 8
nandwrite -n /dev/mtd1 -p u-boot-dtb.img

    • Reflash devicetree (devicetree.dtb, /dev/mtd2)

cd <path-to-image-files>
# u-boot-dtb.img
# mtd2 is 1M (8 eraseblocks,128K = 1 block, there are 64 pages of 2048 per block)
flash_unlock /dev/mtd2
flash_erase /dev/mtd2 0 8
nandwrite -n /dev/mtd2 -p devicetree.dtb

    • Reflash kernel (uImage, /dev/mtd3)

cd <path-to-image-files>
# uImage
# mtd3 is 16M (128 eraseblocks,128K = 1 block, there are 64 pages of 2048 per block)
flash_unlock /dev/mtd3
flash_erase /dev/mtd3 0 128
nandwrite -n /dev/mtd3 -p uImage

    • For rootfs there are 2 options:
      • update - recommended, rootfs.ubifs
      • reflash - radical, rootfs.ubi

Update:

# NOT TESTED
ubiattach /dev/ubi_ctrl -m 4
#ubimkvol /dev/ubi0 -N elphel393-rootfs -s 256MiB
ubiupdatevol /dev/ubi0_0 rootfs.ubifs
# read: http://www.linux-mtd.infradead.org/faq/ubifs.html
# read: http://free-electrons.com/blog/creating-flashing-ubi-ubifs-images/
# read: http://www.linux-mtd.infradead.org/doc/ubi.html#L_volupdate
# read: http://comments.gmane.org/gmane.linux.drivers.mtd/39415

Reflash:

cd <path-to-image-files>
flash_unlock /dev/mtd4
flash_erase /dev/mtd4 0 2048
ubiformat /dev/mtd4 -f rootfs.ubi -s 2048 -O 2048

Note: Considering to store the u-boot, device tree and kernel on UBUFS partitions in future.