uboot2013.04
mtdparts default 設定MTD分區預設值, 預設值定義在 nuc970_evb.h中. 這個設定是將MTD分
#define MTDIDS_DEFAULT "nand0=nand0" #define MTDPARTS_DEFAULT "mtdparts=nand0:0x200000@0x0(u-boot),0x1400000@0x200000(kernel),-(user)" #define MTD_ACTIVE_PART "nand0,2"
區ID設為nand0, 預設三個分區u-boot, kernel 和user. 第一分區: 名稱為u-boot, 起始位置為0x0, 大小為0x200000. 第二分區: 名稱為kernel, 起始位置為0x200000, 大小為0x1400000. 第三分區: 名稱為user, 起始位置為0x1600000, 大小為剩餘空間.
U-Boot> mtdparts mtdparts variable not set, see 'help mtdparts' no partitions defined
defaults: mtdids : nand0=nand0 mtdparts: mtdparts=nand0:0x200000@0x0(u-boot),0x1400000@0x200000(kernel),-(user) U-Boot>
U-Boot> env print [-f]=nambaudrate=115200 baudrate=115200 bootargs=noinitrd ubi.mtd=2 root=ubi0:system rw rootfstype=ubifs console=ttyS0,115200n8 rdinit=/sbin/init mem=64M mtdparts=nand0:0x200000@0x0(u-boot),0x1400000@0x200000(kernel),-(user) bootcmd=nboot 0x7fc0 0 0x200000; bootm 0x7fc0 bootdelay=9 ethact=emac ethaddr=00:00:00:11:66:88 stderr=serial stdin=serial stdout=serial
bootargs 這個參數將會傳遞給內核系統, 內核和文件系統的不同就會有不同的設置方法. 下面這個範例是將bootargs 的NAND MTD層分區傳遞至內核, 詳細的分區設定請參考4.5.10 MTD命令. 最後, 記得將環境變數儲存到 NAND flash.
注意:如果 U-boot 有設定環境變數, 那內核裡必須勾選 “Command line partition table parsing”, 如此一來, 參數才會傳入內核裡.
開機命令設置 – 以NAND Flash UBIFS文件系統為根文件系統的設定 開機命令可以用來設置系統. 包含了根文件系統型態, 記憶體大小, console 波特率… 等. 使用這個設定需要啟動UBIFS文件系統 (請參考 5.3.4 文件系統設置), 並且取消 RAM根文件系統設定. General setup ---> [ ] Initial RAM filesystem and RAM disk (initramfs/initrd) support
下列範例是需要先將根文件系統製作成UBIFS格式的鏡像文件(請參考3.8.4製作FS 型態Image), 再燒入至mtd2所在的位置, 當內核啟動會依據下列開機命令將根文件 系統帶起.
原:root=/dev/ram0 console=ttyS0,115200n8 rdinit=/sbin/init mem=64M
修改后:noinitrd ubi.mtd=2 root=ubi0:system rw rootfstype=ubifs console=ttyS0,115200n8 rdinit=/sbin/init mem=64M
Boot options ---> (noinitrd ubi.mtd=2 root=ubi0:system rw rootfstype=ubifs console=ttyS0, 115200n8 rdinit=/sbin/init mem=64M) Default kernel command string Kernel command line type (Use bootloader arguments if available) ---
UBIFS文件系統設置 UBIFS 是用於固態硬碟儲存裝置上,並與LogFS相互競爭,作為JFFS2的後繼檔案系 統之一。UBIFS 在設計與效能上均較YAFFS2、JFFS2更適合 MLC NAND FLASH。例 如:UBIFS 支援 write-back, 其寫入的資料會被 cache, 直到有必要寫入時才寫到 flash, 大大地降低分散小區塊數量並提高 I/O 效率。 Device Drivers ---> -*- Memory Technology Device (MTD) support ---> <*> Enable UBI - Unsorted block images ---> File systems ---> [*] Miscellaneous filesystems ---> <*> UBIFS file system support [*] Advanced compression options [*] LZO compression support
MTD NAND flash 設置 NAND flash 是使用的驅動是掛在 MTD 子系統之下. 可按照以下設置使能. NAND flash 接口有兩組管腳可選擇, Port C 以及 Port I, 需視硬件接線設置. Device Drivers ---> Generic Driver Options ---> <*> Nuvoton NUC970 FMI function selection Select FMI device to support (Support MTD NAND Flash) ---> -*- Memory Technology Device (MTD) support ---> <*> Command line partition table parsing <*> Caching block device access to MTD devices -*- NAND Device Support ---> -*- Nuvoton NUC970 MTD NAND ---> NUC970 NAND Flash pin selection (Port C) --->
驅動中的基本設置如果需要由U-boot環境變數傳入就必須將” Command line partition table parsing” 選上, 否則會使用驅動程式裡的默認配置, 主要會將 MTD 分為三塊空 間. 上電進入 shell 後, 分別是/dev/mtdblock0, /dev/mtdblock1, 以及 /dev/mtdblock2. 第一 塊是放置 U-Boot 的空間, 第二塊放置內核文件, 第三塊則是用來掛載 YAFFS2 或 UBIFS 文件系統的空間. 若是配置有需要更改, 例如增加或減少分區, 改變分區大小. 請直接編輯 uboot/include/nuc970_evb.h 或 drivers/mtd/nand/nuc970_nand.c
UBIFS製作Image命令如下: # mkfs.ubifs -F -x lzo -m 2048 -e 126976 -c 732 -o rootfs_ubifs.img -d ./rootfs # ubinize -o ubi.img -m 2048 -p 131072 –O 2048 -s 2048 ubinize.cfg mkfs.ubifs 使用的參數說明如下: -F :設定檔案系統未使用的空間優先mount. -x: 壓縮的格式,"lzo", "favor_lzo", "zlib" 或 "none" (預設:"lzo") -m:最小的I/O操作的大小,也就是NAND Flash一個頁的大小。 -e:邏輯擦除塊的大小(logical erase block size)。因為實體擦除塊(PEB)為128KiB,所以 邏輯擦除塊設定為124KiB=126976。 -c:最大的擦除塊的號碼(maximum logical erase block count)。 -o:輸出檔案。 ubinize使用的參數說明名如下: -o:輸出檔案。 -m:最小輸入/輸出的大小,也就是NAND Flash一個頁的大小。 -p:實體擦除塊大小,128KiB=131072。 -O:VID檔頭位移位置。 -s:使用最小輸入/輸出的大小,存放UBI檔頭。 ubinize.cfg 內容如下: [rootfs-volume] NUC970 Linux BSP 使用手冊 Nov. 8, 2016 34 of 185 Rev. 1.00 mode=ubi image=rootfs_ubifs.img vol_id=0 vol_size=92946432 vol_type=dynamic vol_name=system vol_flags=autoresize 即可將rootfs資料夾壓縮成ubi.img,再透過NuWriter放到相對應NAND Flash的位址。 輸入下列命令即可將UBIFS檔案系統掛在flash資料夾中: 需要參考/sys/class/misc/ubi_ctrl/dev內容,假設內容為 10:56,則設定如下: # mknod /dev/ubi_ctrl c 10 56 # ubiattach /dev/ubi_ctrl -p /dev/mtd2 # mount -t ubifs ubi0:system /flash UBIFS相關指令可以在mtd-utils套件中找到。UBIFS文件系統設置可以參考5.3.4章節。
在ubuntu下安装mtd-utils
root@ubuntu:/ apt install mtd-utils
测试安装
root@ubuntu:/home/hbin/nuc977_bsp/nuc970bsp# mkfs.ubifs -V mkfs.ubifs 1.5.2
root@ubuntu:/home/hbin/nuc977_bsp/nuc970bsp# mkfs.ubifs -F -x lzo -m 2048 -e 126976 -c 732 -o rootfs_ubifs.img -d ./rootfs root@ubuntu:/home/hbin/nuc977_bsp/nuc970bsp# ubinize -o ubi.img -p 131072 -m 2048 -s 2048 -O 2048 rootfs_ubinize.cfg root@ubuntu:/home/hbin/nuc977_bsp/nuc970bsp#
设置 Image Type 为 Data 模式,Image encrypt 为 Disable,Image start offset 为 0x1600000,按 Burn 烧 写。
上电启动
.................................
UBI error: scan_peb: bad image sequence number 105634952 in PEB 49, expected 2098770162 Erase counter header dump: magic 0x55424923 version 1 ec 1 vid_hdr_offset 2048 data_offset 4096 image_seq 105634952 hdr_crc 0x2f5bd0c7 erase counter header hexdump: UBI error: ubi_attach_mtd_dev: failed to attach mtd2, error -22 UBI error: ubi_init: cannot attach mtd2 UBIFS error (pid 1): ubifs_mount: cannot open "ubi0:system", error -19 VFS: Cannot open root device "ubi0:system" or unknown-block(0,0): error -19
Please append a correct "root=" boot option; here are the available partitions: 1f00 2048 mtdblock0 (driver?) 1f01 20480 mtdblock1 (driver?) 1f02 108544 mtdblock2 (driver?) Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
内核崩溃
查资料是根文件系统的nandflash部份要进行擦除
U-Boot> mtdparts default U-Boot> mtdparts
device nand0 <nand0>, # parts = 3 #: name size offset mask_flags 0: u-boot 0x00200000 0x00000000 0 1: kernel 0x01400000 0x00200000 0 2: user 0x06a00000 0x01600000 0
active partition: nand0,0 - (u-boot) 0x00200000 @ 0x00000000
defaults: mtdids : nand0=nand0 mtdparts: mtdparts=nand0:0x200000@0x0(u-boot),0x1400000@0x200000(kernel),-(user)
NAND erase.part: device 0 offset 0x1600000, size 0x6a00000 Skipping bad block at 0x01b20000 Skipping bad block at 0x03480000 Erasing at 0x7fe0000 -- 100% complete. OK
U-Boot> ubi part user Creating 1 MTD partitions on "nand0": 0x000001600000-0x000008000000 : "mtd=2" UBI: attaching mtd1 to ubi0 UBI: physical eraseblock size: 131072 bytes (128 KiB) UBI: logical eraseblock size: 126976 bytes UBI: smallest flash I/O unit: 2048 UBI: VID header offset: 2048 (aligned 2048) UBI: data offset: 4096 UBI: empty MTD device detected UBI: create volume table (copy #1) UBI: create volume table (copy #2) UBI: attached mtd1 to ubi0 UBI: MTD device name: "mtd=2" UBI: MTD device size: 106 MiB UBI: number of good PEBs: 846 UBI: number of bad PEBs: 2 UBI: max. allowed volumes: 128 UBI: wear-leveling threshold: 4096 UBI: number of internal volumes: 1 UBI: number of user volumes: 0 UBI: available PEBs: 834 UBI: total number of reserved PEBs: 12 UBI: number of PEBs reserved for bad PEB handling: 8 UBI: max/mean erase counter: 1/0 U-Boot>
ubi create system - 创建分区
VFS: Mounted root (ubifs filesystem) on device 0:11. devtmpfs: mounted Freeing unused kernel memory: 128K (c03b6000 - c03d6000)
BusyBox v1.22.1 (2016-02-03 14:11:04 CST) built-in shell (ash) Enter 'help' for a list of built-in commands.
~ # ~ # ~ # ls bin etc linuxrc proc sys usr dev lib mnt sbin tmp var ~ #
参考:NUC970 Linux BSP 使用手冊.pdf
参考:https://blog.csdn.net/qianxilin/article/details/89282773