20160620_jeffrey - silenceuncrio/diary GitHub Wiki
- 1050 - Winston dual image U-Boot
- 1115 - m300
- 1300 - ucl2.xml NAND Flash
- 1330 - burn the kernel to NAND
- 1340 - burn the rootfs to NAND
- 1340 - ucl2.xml NAND Flash
- 1515 - Create a FLASH partition to store user's HOME
- 1600 - engineering notebook
- 1745 - m300_proposal_uboot_imageLayout_NANDFlash_jeffrey
早上找 Winston 聊了一下
目前對於 dual image 的理解如下
- dual image
- 可開機的儲存裝置上會存兩份 image, 稱為 A 跟 B
- U-Boot 有兩個環境變數
- active - 指名現在是從哪個 partition 做開機
- upgrade - 負責 upgrade 的 application 在 upgrade 之後要設成 1, 開機時 U-Boot 根據 upgrade 的值做的事如下
- 0 - 依據目前的 active partition 做開機
- 1 - 檢查被 upgrade partition 的完整性
- 完整 - active partition 交換, upgrade 設成 0
- 不完整 - active partition 保持不變
- U-Boot
額外要注意的有
- Linux 要能存取 U-Boot 的環境變數
- 掛載啥 mtb
- 如何檢查被 upgrade 之後, 儲存裝置上的 image 的完整性
- romfs - 檢查 checksum
- 可以被更動的檔案系統 - 以 VPN Project 為例
- U-Boot 新增一個環境變數來記錄開機的次數, 就叫 BOOT_CNT
- U-Boot 每次都做
BOOT_CNT ++
- 若成功開機了, 由 Linux 負責
BOOT_CNT = 0
- U-Boot 若看到
BOOT_CNT == 3
表示三次開機不成功, 切換 ACTIVE partition
先根據收集回來的情報來看 m300
感覺要參考一下 ucl2.xml
裡 NAND Flash
的部分
<LIST name="NAND Flash" desc="Choose NAND as media">
<CMD state="BootStrap" type="boot"
body="BootStrap" file ="firmware/u-boot-imx6ul%6uluboot%_%nand%.imx">Loading U-boot</CMD>
<CMD state="BootStrap" type="load"
file="firmware/zImage" address="0x80800000"
loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE">Loading Kernel.</CMD>
<CMD state="BootStrap" type="load"
file="firmware/%initramfs%" address="0x83800000"
loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE">Loading Initramfs.</CMD>
<CMD state="BootStrap" type="load"
file="firmware/zImage-imx6ul-%6uldtb%-%nanddtb%.dtb" address="0x83000000"
loadSection="OTH" setSection="OTH" HasFlashHeader="FALSE">Loading device tree.</CMD>
<CMD state="BootStrap" type="jump" > Jumping to OS image. </CMD>
<!--burn the uboot to NAND: -->
<CMD state="Updater" type="push"
body="$ mount -t debugfs debugfs /sys/kernel/debug">Mounting debugfs</CMD>
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd%part_uboot% 0 0">Erasing Boot partition</CMD>
<CMD state="Updater" type="push"
body="send" file="files/u-boot-imx6ul%6uluboot%_%nand%.imx">Sending u-boot.bin</CMD>
<CMD state="Updater" type="push"
body="$ kobs-ng init -x -v --chip_0_device_path=/dev/mtd%part_uboot% $FILE">Flashing Bootloader</CMD>
<!--burn the kernel to NAND: -->
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd%part_kernel% 0 0">Erasing Kernel partition</CMD>
<CMD state="Updater" type="push"
body="send" file="files/zImage">Sending kernel zImage</CMD>
<CMD state="Updater" type="push"
body="$ nandwrite -p /dev/mtd%part_kernel% -p $FILE">Flashing Kernel</CMD>
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd%part_dtb% 0 0">Erasing dtb partition</CMD>
<CMD state="Updater" type="push"
body="send" file="files/zImage-imx6ul-%6uldtb%-%nanddtb%.dtb">Sending Device Tree file</CMD>
<CMD state="Updater" type="push"
body="$ nandwrite -p /dev/mtd%part_dtb% -p $FILE">Flashing dtb</CMD>
<!--burn the rootfs to NAND: -->
<CMD state="Updater" type="push"
body="$ flash_erase /dev/mtd%part_rootfs% 0 0">Erasing rootfs partition</CMD>
<CMD state="Updater" type="push"
body="$ ubiformat /dev/mtd%part_rootfs%"/>
<CMD state="Updater" type="push"
body="$ ubiattach /dev/ubi_ctrl -m %part_rootfs%">Attaching UBI partition</CMD>
<CMD state="Updater" type="push"
body="$ ubimkvol /dev/ubi0 -Nrootfs -m"/>
<CMD state="Updater" type="push"
body="$ mkdir -p /mnt/mtd%part_rootfs%"/>
<CMD state="Updater" type="push"
body="$ mount -t ubifs ubi0:rootfs /mnt/mtd%part_rootfs%"/>
<CMD state="Updater" type="push"
body="pipe tar -jxv -C /mnt/mtd%part_rootfs%" file="files/rootfs_nogpu.tar.bz2">Sending and writting rootfs</CMD>
<CMD state="Updater" type="push"
body="frf">Finishing rootfs write</CMD>
<CMD state="Updater" type="push"
body="$ umount /mnt/mtd%part_rootfs%">Unmounting rootfs partition</CMD>
<CMD state="Updater" type="push" body="$ echo Update Complete!">Done</CMD>
</LIST>
Jumping to OS image.
之前的部分就不看了
先看 burn the uboot to NAND:
-
mount -t debugfs debugfs /sys/kernel/debug
- Mounting debugfs -
flash_erase /dev/mtd%part_uboot% 0 0
- Erasing Boot partition - send - file="files/u-boot-imx6ul%6uluboot%_%nand%.imx - Sending u-boot.bin
-
kobs-ng init -x -v --chip_0_device_path=/dev/mtd%part_uboot% $FILE
- Flashing Bootloader
"Mounting debugfs" 的部分先跳過
來看 "Erasing Boot partition" 的部分
part_uboot
在 mfgtool2-yocto-mx-14x14-arm2-nand.vbs
被定義成 0
解析 flash_erase /dev/mtd0 0 0
google 到的
命令:flash_erase
作用:擦出指定范围内flash的内容,如果不指定,默认擦出起始位置的第一块,使相应flash变为全1
用法:
flash_erase MTD-device [start] [cnt (# erase blocks)] [lock]
MTD-device:待擦出的分区,如/dev/mtd0
start:起始位置设置,这里必须设置为0x20000(128K)的整数倍
cnt: 从start开始计算,要擦出的块数
lock: 写保护
eg: ./flash_erase /dev/mtd0 0x40000 5 //擦出mtd0分区上从0x40000开始的5块数据 ,128K/块
cnt = 0 表示 erase 0 blocks... 不了解做這件事的用意
繼續吧...
Sending u-boot.bin
這個就不用解釋了
Flashing Bootloader
解析 kobs-ng init -x -v --chip_0_device_path=/dev/mtd%part_uboot% $FILE
等於解析 kobs-ng init -x -v --chip_0_device_path=/dev/mtd0 u-boot-imx6ul14x14ddr3arm2_nand.imx
看到 kobs-ng 3.0.35-4.1.0
summary 說道這是個 Freescale's mxs nand update utility
先這樣吧
來看 burn the kernel to NAND:
部分
- flash_erase /dev/mtd%part_kernel% 0 0" - Erasing Kernel partition
- send - file="files/zImage - Sending kernel zImage
- nandwrite -p /dev/mtd%part_kernel% -p $FILE - Flashing Kernel
- flash_erase /dev/mtd%part_dtb% 0 0 - Erasing dtb partition
- send - file="files/zImage-imx6ul-%6uldtb%-%nanddtb%.dtb - Sending Device Tree file
- nandwrite -p /dev/mtd%part_dtb% -p $FILE - Flashing dtb
抽象來看這個部分的話就是我們 send 了 kernel zImage
和 Device Tree file
到目前正在跑的 Linux 上
然後叫 Linux 使用 nandwrite 將 kernel zImage
和 Device Tree file
flashing 到 Flash 去
-
kernel zImage
- /dev/mtd1 -
Device Tree file
- /dev/mtd2
繼續看 burn the rootfs to NAND:
部分
- flash_erase /dev/mtd%part_rootfs% 0 0 - Erasing rootfs partition
- ubiformat /dev/mtd%part_rootfs%
- ubiattach /dev/ubi_ctrl -m %part_rootfs% - Attaching UBI partition
- ubimkvol /dev/ubi0 -Nrootfs -m
- mkdir -p /mnt/mtd%part_rootfs%
- mount -t ubifs ubi0:rootfs /mnt/mtd%part_rootfs%
- pipe tar -jxv -C /mnt/mtd%part_rootfs% - file="files/rootfs_nogpu.tar.bz2 - Sending and writting rootfs
- frf - Finishing rootfs write
- umount /mnt/mtd%part_rootfs% - Unmounting rootfs partition
這裡的 part_rootfs 在 mfgtool2-yocto-mx-14x14-arm2-nand.vbs
被定義成 3
抽象來看 ucl2.xml
的話 NAND Flash
做了這些事
- Flashing Bootloader - /dev/mtd0
- Flashing kernel zImage - /dev/mtd1
- Flashing Device Tree file - /dev/mtd2
- writting rootfs - /dev/mtd3
那 /dev/mtd 到底是啥呢?
參考 Create a FLASH partition to store user's HOME 可以得到不錯的線索
U-Boot
=> setenv mtdparts mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),200M(rootfs),-(user)
Linux boot message
6 cmdlinepart partitions found on MTD device mxc_nand.0
Creating 6 MTD partitions on "mxc_nand.0":
0x000000000000-0x0000000a0000 : "U-boot"
0x0000000a0000-0x000000100000 : "U-boot_env"
0x000000100000-0x000000180000 : "firmware"
0x000000180000-0x000000680000 : "kernel"
0x000000680000-0x00000ce80000 : "rootfs"
0x00000ce80000-0x000010000000 : "user"
這篇也值得研究 - Managing flash storage with Linux
先寫 engineering notebook
準備 proposal 吧 - m300_proposal_uboot_imageLayout_NANDFlash_jeffrey
| Features | Schedule | Proposal | |---|---|---|---| | u-boot : Reduce image size | 6月10日 | m300_proposal_uboot_reduceImageSize_jeffrey| | u-boot : image layout - SD card | 6月17日 | - | | u-boot : image layout - NAND flash | 6月24日 | m300_proposal_uboot_imageLayout_NANDFlash_jeffrey | | kernel: EMMC/NAND MTD Driver | 7月1日 | | | u-boot : burn image - NAND flash | 7月8日 | |