参考:
https://zhidao.baidu.com/question/432878013833222444.html
http://blog.chinaunix.net/uid-28236237-id-4164656.html
https://blog.csdn.net/xiaoxiaozhu2010/article/details/18087197
1. 新增NAND MTD分区
1) 设备树中修改:
arch\arm\boot\dts\at91-sama5d27_som1_ek.dts
2) 系统起来后,在Uboot中的修改:
修改 bootargs 参数, 修改后如下:
=> edit bootargs
edit: console=ttyS0,115200 earlyprintk mtdparts=atmel_nand:256k(bootstrap)ro,768k(uboot)ro,256K(env_redundant),256k(env),512k(dtb),6M(kernel)ro,252M(rootfs),252M(data) rootfstype=ubifs ubi.mtd=6 root=ubi0:rootfs
将剩余的 rootfs分区(504M)分成两个区:252M(rootfs),252M(data)
修改后 saveenv ,然后 boot
2. 进入系统后,手动挂载UBI文件系统
内核的启动信息:
已经分成了8个MTD分区
UBI相关的命令
进入系统后:
查看系统的MTD分区信息
cat /proc/mtd
dev: size erasesize name
mtd0: 00040000 00040000 “bootstrap”
mtd1: 000c0000 00040000 “uboot”
mtd2: 00040000 00040000 “env_redundant”
mtd3: 00040000 00040000 “env”
mtd4: 00080000 00040000 “dtb”
mtd5: 00600000 00040000 “kernel”
mtd6: 0fc00000 00040000 “rootfs”
mtd7: 0fc00000 00040000 “data”
查看UBI设备
ls /dev/ubi*
/dev/ubi0 /dev/ubi0_0 /dev/ubi_ctrl
格式化Flash设备,擦除Flash,保存擦除计数,写入UBI镜像到Flash;
ubiformat /dev/mtd7
ubiformat: mtd7 (nand), size 264241152 bytes (252.0 MiB), 1008 eraseblocks of 262144 bytes (256.0 KiB), min. I/O size 4096 bytes
libscan: scanning eraseblock 1007 – 100 % complete
ubiformat: 1004 eraseblocks have valid erase counter, mean value is 1
ubiformat: 4 bad eraseblocks found, numbers: 1004, 1005, 1006, 1007
ubiformat: formatting eraseblock 1007 – 100 % complete
链接MTD设备(MTD设备描述原始Flash设备)到UBI并且创建相应的UBI设备;
ubiattach /dev/ubi_ctrl -m 7
ubi1: default fastmap pool size: 50
ubi1: default fastmap WL pool size: 25
ubi1: attaching mtd7
ubi1: scanning is finished
ubi1: attached mtd7 (name “data”, size 252 MiB)
ubi1: PEB size: 262144 bytes (256 KiB), LEB size: 253952 bytes
ubi1: min./max. I/O unit sizes: 4096/4096, sub-page size 4096
ubi1: VID header offset: 4096 (aligned 4096), data offset: 8192
ubi1: good PEBs: 1004, bad PEBs: 4, corrupted PEBs: 0
ubi1: user volume: 0, internal volumes: 1, max. volumes count: 128
ubi1: max/mean erase counter: 3/2, WL threshold: 4096, image sequence number: 2030274995
ubi1: available PEBs: 962, total reserved PEBs: 42, PEBs reserved for bad PEB handling: 36
ubi1: background thread “ubi_bgt1d” started, PID 201
ls /dev/ubi*
/dev/ubi0 /dev/ubi0_0 /dev/ubi1 /dev/ubi_ctrl
从UBI设备上创建UBI卷;
ubimkvol /dev/ubi1 -s 128MiB -N heat_rootfs
cat /sys/class/ubi/ubi1_0/name
(这个名字 heat_rootfs在下次启动修改uboot –bootargs时要用到)
heat_rootfs
ls /dev/ubi*
/dev/ubi0 /dev/ubi0_0 /dev/ubi1 /dev/ubi1_0 /dev/ubi_ctrl
将ubi1_0挂载到本地目录 /mnt上,
mount -t ubifs ubi1_0 /mnt
UBIFS (ubi1:0): default file-system created
UBIFS (ubi1:0): background thread “ubifs_bgt1_0” started, PID 209
UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name “heat_rootfs”
UBIFS (ubi1:0): LEB size: 253952 bytes (248 KiB), min./max. I/O unit sizes: 4096 bytes/4096 bytes
UBIFS (ubi1:0): FS size: 131801088 bytes (125 MiB, 519 LEBs), journal size 6602752 bytes (6 MiB, 26 LEBs)
UBIFS (ubi1:0): reserved for root: 4952683 bytes (4836 KiB)
UBIFS (ubi1:0): media format: w5/r0 (latest is w5/r0), UUID 368F1284-A088-4242-B7A4-83CF998002B3, small LPT model
可以看到ubi1_0成功挂载在/mnt上
mount
ubi0:rootfs on / type ubifs (rw,relatime,ubi=0,vol=0)
devtmpfs on /dev type devtmpfs (rw,relatime,size=59908k,nr_inodes=14977,mode=755)
proc on /proc type proc (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=666)
tmpfs on /dev/shm type tmpfs (rw,relatime,mode=777)
tmpfs on /tmp type tmpfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755)
sysfs on /sys type sysfs (rw,relatime)
ubi1_0 on /mnt type ubifs (rw,relatime,ubi=1,vol=0)
将压缩的根文件系统 rootfs.tar.gz 解压到 /mnt 目录,注意 /mnt目录应该包含 root/ etc/等目录,而不是一个 rootfs/目录。
解压后,reboot,在uboot中修改 bootargs,修改如下:
修改后启动系统,查看系统加载情况。