Difference between revisions of "NAND flash boot rootfs"

From ElphelWiki
Jump to: navigation, search
(Boot from NAND flash (rootfs))
(Option 1: web browser)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Boot from NAND flash (rootfs)==
+
==<font color="blue">Notes</font>==
* The default boot option - power on.
+
* Overwrite the corrupt flash partition or update
* A UBIFS image of rootfs is written to /dev/mtd4 ('''ubi0:elphel393-rootfs''' in bootargs in the device tree) - mounted as '''/'''
 
 
 
==Reflash factory image==
 
===Notes===
 
* Update software/firmware or corrupt flash partition
 
 
* To update u-boot images, device tree and kernel - booting from micro SD card is not required.
 
* To update u-boot images, device tree and kernel - booting from micro SD card is not required.
* To update rootfs - boot from micro SD card otherwise a mounted flash partition will be rewritten, get corrupt and the camera won't boot - boot from micro SD card and reflash rootfs partition to recover.  
+
* To update rootfs - boot from micro SD card otherwise a mounted flash partition will be rewritten, get corrupt and the camera might not boot - to recover, boot from micro SD card and reflash rootfs partition.  
 
* '''boot.bin''', '''u-boot-dtb.img''' - most likely won't need updating at all. Only if their partitions get corrupt
 
* '''boot.bin''', '''u-boot-dtb.img''' - most likely won't need updating at all. Only if their partitions get corrupt
** As Zynq's BootROM performs 32KB jumps within the first 128MiB of flash in the search of a boot.bin header with a correct checksum it is possible to flash a few backup images to the 1st flash partition (mtd0) in the device tree. The partition size is 1MB, boot.bin size is normally around 100KB (<192KB - Zynq OCM requirement)
+
** As Zynq's BootROM performs 32KB jumps within the first 128MiB of flash in the search of a boot.bin header with a correct checksum it is possible to flash a few backup images to the 1st flash partition (mtd0) in the device tree. The partition size is 1MB, boot.bin size is normally around 100KB (<192KB - Zynq's OCM requirement)
  
===Instructions===
+
* Considering to store u-boot (probably not, because 192K-max-boot.bin might not fit UBIFS driver), device tree and kernel on UBIFS partitions in future. SPL has to be either on the NAND flash or MMC
* Use files from '''.../poky/build/tmp/deploy/images/elphel393/nand/'''
+
 
 +
==<font color="blue">Write files to NAND flash</font>==
 +
* Use files from '''elphel393/bootable-images/elphel393/nand/'''
 
** '''boot.bin'''
 
** '''boot.bin'''
 
** '''u-boot-dtb.img'''
 
** '''u-boot-dtb.img'''
 
** '''devicetree.dtb'''
 
** '''devicetree.dtb'''
 
** '''uImage'''
 
** '''uImage'''
** '''rootfs.ubifs''' (<font color='green'>recommended</font>), '''rootfs.ubi''' (<font color='red'>radical</font>)
+
** '''rootfs.ubi''' or '''rootfs.ubifs'''
* 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 (<font color='red'>important for rootfs updates</font>)
+
===Option 1: web browser===
* Reflash what is needed:
+
* Boot the camera from the micro SD card (<font color='red'>important for rootfs update</font>)
** Reflash SPL ('''boot.bin''', /dev/mtd0)
+
* Go to the http://192.168.0.9/update_software.html
 +
* Upload: '''uImage''', '''rootfs.ubi'''  
 +
* To update u-boot and devicetree, upload: '''boot.bin''', '''u-boot-dtb.img''', '''devicetree.dtb'''
 +
* Verify-button, download backup then Flash-button
 +
 
 +
===Option 2: command line===
 +
* Boot the camera from the micro SD card (<font color='red'>important for rootfs update</font>)
 +
* Copy file to the camera, example from the PC terminal:
 +
$ scp boot.bin u-boot-dtb.img devicetree.dtb uImage rootfs.ubi root@192.168.0.9:/<path-to-image-files>/
 +
* From the ssh session (ssh root@192.168.0.9) reflash what needs an update:
 +
** Reflash rootfs ('''rootfs.ubi''', /dev/mtd4) (<font color='red'>radical</font>)
 
<font size='2'>
 
<font size='2'>
 
  cd <path-to-image-files>
 
  cd <path-to-image-files>
  # boot.bin
+
  flash_unlock /dev/mtd4
# mtd0 is 1MB (8 eraseblocks,128K = 1 block, there are 64 pages of 2048 per block)
+
flash_erase /dev/mtd4 0 2048
# erase only first 2 blocks, other block are reserved for copies
+
ubiformat /dev/mtd4 -f rootfs.ubi -s 2048 -O 2048
  flash_unlock /dev/mtd0
+
</font>
  flash_erase /dev/mtd0 0 2
+
OR
  nandwrite -n /dev/mtd0 -p boot.bin
+
** update rootfs ('''rootfs.ubifs''', /dev/mtd4) (<font color='green'>recommended</font>)
 +
<font size='2'>
 +
  flash_unlock /dev/mtd4
 +
  ubiattach /dev/ubi_ctrl -m 4
 +
  # NOT NEEDED: 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
 
</font>
 
</font>
** Reflash u-boot ('''u-boot-dtb.img''', /dev/mtd1)
+
** Reflash kernel ('''uImage''', /dev/mtd3)
 
<font size='2'>
 
<font size='2'>
 
  cd <path-to-image-files>
 
  cd <path-to-image-files>
  # u-boot-dtb.img
+
  # uImage
  # mtd1 is 4M (32 eraseblocks,128K = 1 block, there are 64 pages of 2048 per block)
+
  # mtd3 is 16M (128 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/mtd3
  flash_unlock /dev/mtd1
+
  flash_erase /dev/mtd3 0 128
  flash_erase /dev/mtd1 0 8
+
  nandwrite -n /dev/mtd3 -p uImage
  nandwrite -n /dev/mtd1 -p u-boot-dtb.img
 
 
</font>
 
</font>
 
** Reflash devicetree ('''devicetree.dtb''', /dev/mtd2)
 
** Reflash devicetree ('''devicetree.dtb''', /dev/mtd2)
Line 50: Line 66:
 
  nandwrite -n /dev/mtd2 -p devicetree.dtb
 
  nandwrite -n /dev/mtd2 -p devicetree.dtb
 
</font>
 
</font>
** Reflash kernel ('''uImage''', /dev/mtd3)
+
** Reflash u-boot ('''u-boot-dtb.img''', /dev/mtd1)
 
<font size='2'>
 
<font size='2'>
 
  cd <path-to-image-files>
 
  cd <path-to-image-files>
  # uImage
+
  # u-boot-dtb.img
  # mtd3 is 16M (128 eraseblocks,128K = 1 block, there are 64 pages of 2048 per block)
+
  # mtd1 is 4M (32 eraseblocks,128K = 1 block, there are 64 pages of 2048 per block)
  flash_unlock /dev/mtd3
+
# erase only the 1st 8 blocks as image is <1M, leave unused area for backup copies
  flash_erase /dev/mtd3 0 128
+
  flash_unlock /dev/mtd1
  nandwrite -n /dev/mtd3 -p uImage
+
  flash_erase /dev/mtd1 0 8
 +
  nandwrite -n /dev/mtd1 -p u-boot-dtb.img
 
</font>
 
</font>
** For rootfs there are 2 options:
+
** Reflash SPL ('''boot.bin''', /dev/mtd0)
*** update - <font color='green'>recommended</font>, '''rootfs.ubifs'''
 
*** reflash - <font color='red'>radical</font>, '''rootfs.ubi'''
 
Update:
 
<font size='2'>
 
flash_unlock /dev/mtd4
 
ubiattach /dev/ubi_ctrl -m 4
 
# NOT NEEDED: 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
 
</font>
 
Reflash:
 
 
<font size='2'>
 
<font size='2'>
 
  cd <path-to-image-files>
 
  cd <path-to-image-files>
  flash_unlock /dev/mtd4
+
# boot.bin
  flash_erase /dev/mtd4 0 2048
+
# mtd0 is 1MB (8 eraseblocks,128K = 1 block, there are 64 pages of 2048 per block)
  ubiformat /dev/mtd4 -f rootfs.ubi -s 2048 -O 2048
+
# 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
 
</font>
 
</font>
'''Note:''' Considering to store the u-boot, device tree and kernel on UBUFS partitions in future.
+
 
 +
==<font color="blue">Boot</font>==
 +
* Make sure the recovery card is not inserted (regular card can stay)
 +
* Power cycle
  
 
[[Category:Elphel393]]
 
[[Category:Elphel393]]

Latest revision as of 10:45, 25 January 2017

Notes

  • Overwrite the corrupt flash partition or update
  • To update u-boot images, device tree and kernel - booting from micro SD card is not required.
  • To update rootfs - boot from micro SD card otherwise a mounted flash partition will be rewritten, get corrupt and the camera might not boot - to recover, boot from micro SD card and reflash rootfs partition.
  • boot.bin, u-boot-dtb.img - most likely won't need updating at all. Only if their partitions get corrupt
    • As Zynq's BootROM performs 32KB jumps within the first 128MiB of flash in the search of a boot.bin header with a correct checksum it is possible to flash a few backup images to the 1st flash partition (mtd0) in the device tree. The partition size is 1MB, boot.bin size is normally around 100KB (<192KB - Zynq's OCM requirement)
  • Considering to store u-boot (probably not, because 192K-max-boot.bin might not fit UBIFS driver), device tree and kernel on UBIFS partitions in future. SPL has to be either on the NAND flash or MMC

Write files to NAND flash

  • Use files from elphel393/bootable-images/elphel393/nand/
    • boot.bin
    • u-boot-dtb.img
    • devicetree.dtb
    • uImage
    • rootfs.ubi or rootfs.ubifs

Option 1: web browser

  • Boot the camera from the micro SD card (important for rootfs update)
  • Go to the http://192.168.0.9/update_software.html
  • Upload: uImage, rootfs.ubi
  • To update u-boot and devicetree, upload: boot.bin, u-boot-dtb.img, devicetree.dtb
  • Verify-button, download backup then Flash-button

Option 2: command line

  • Boot the camera from the micro SD card (important for rootfs update)
  • Copy file to the camera, example from the PC terminal:
$ scp boot.bin u-boot-dtb.img devicetree.dtb uImage rootfs.ubi root@192.168.0.9:/<path-to-image-files>/
  • From the ssh session (ssh root@192.168.0.9) reflash what needs an update:
    • Reflash rootfs (rootfs.ubi, /dev/mtd4) (radical)

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

OR

    • update rootfs (rootfs.ubifs, /dev/mtd4) (recommended)

flash_unlock /dev/mtd4
ubiattach /dev/ubi_ctrl -m 4
# NOT NEEDED: 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 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

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

Boot

  • Make sure the recovery card is not inserted (regular card can stay)
  • Power cycle