运行环境
CPU:君正M300
运行操作系统:Linux5.10.180
调试环境:Ubuntu18.04.6
调试模块:nandflash ubifs文件系统
- ubiattach关联设备物理设备
ubiattach /dev/ubi_ctrl -m 4 # mtdblock4与ubi建立连接
加上-d就是指定ubi号,没有加-d就是从0开始依次递增
~# ubiattach /dev/ubi_ctrl -m 4
[ 14.169498] ubi0: attaching mtd4
[ 14.369292] ubi0: scanning is finished
[ 14.380629] ubi0: attached mtd4 (name "rootfs", size 100 MiB)
[ 14.387044] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 14.400146] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 14.407182] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 14.414399] ubi0: good PEBs: 800, bad PEBs: 0, corrupted PEBs: 0
[ 14.420635] ubi0: user volume: 1, internal volumes: 1, max. volumes count: 128
[ 14.428093] ubi0: max/mean erase counter: 2/1, WL threshold: 4096, image sequence number: 3864667259
[ 14.437587] ubi0: available PEBs: 0, total reserved PEBs: 800, PEBs reserved for bad PEB handling: 80
[ 14.447151] ubi0: background thread "ubi_bgt0d" started, PID 882
UBI device number 0, total 800 LEBs (101580800 bytes, 96.8 MiB), available 0 LEBs (0 bytes), LEB size 126976 bytes (124.0 KiB)
加上-d参数,用法如下
ubiattach /dev/ubi_ctrl -m 4 -d 4
[ 58.062710] ubi4: attaching mtd4
[ 58.196269] ubi4: scanning is finished
[ 58.200158] ubi4: empty MTD device detected
[ 58.223632] ubi4: attached mtd3 (name "rootfs", size 100 MiB)
[ 58.230086] ubi4: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 58.237206] ubi4: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 58.244238] ubi4: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 58.251440] ubi4: good PEBs: 800, bad PEBs: 0, corrupted PEBs: 0
[ 58.257637] ubi4: user volume: 0, internal volumes: 1, max. volumes count: 128
[ 58.265104] ubi4: max/mean erase counter: 0/0, WL threshold: 4096, image sequence number: 3550834246
[ 58.274539] ubi4: available PEBs: 716, total reserved PEBs: 84, PEBs reserved for bad PEB handling: 80
[ 58.284168] ubi4: background thread "ubi_bgt4d" started, PID 880
执行完上述指令之后,ls /dev/ubi* 查看ubi设备信息,将会多一个ubi4
2.创建UBI卷,例如创建一个名为rootfs的卷
ubimkvol /dev/ubi4 -m -N rootfs
/dev/ubi4是设备名,查看上一步红色字体,如果是ubi0,那这里就是/dev/ubi0,如果是ubi1,那这里就是/dev/ubi1,不同的分区数值不一样,会随着ubi建立连接分区的数量增加。
-m Set volume size to maximum available
-n VOLID Volume ID. If not specified,assigned automatically
-N NAME Volume name
rootfs是名称,用户自己命名
如果之前已经用ubimkvol建立UBI卷的分区再次挂载时不需要在执行该命令,也即ubimkvol针对一个分区只能做一次,除非使用flash_eraseall重新格式化
3.挂载UBI卷,挂载对应的/dev/ubi_x,而非/dev/mtd*
mount -t ubifs ubi0:rootfs /mnt
或
mount -t ubifs -o sync,noatime,rw ubi4:rootfs /mnt
ubix需以实际为准
将rootfs挂载到/mnt目录
如果出错,请排查如下几项:
1.如果无法挂载,确认mtdblock4是否格式化,使用ubiformat格式化
ubiformat /dev/mtd4 -y
如果提示:
ubiformat: error!: please, first detach mtd4(/dev/mtd4) from ubi0
输入如下指令
ubidetach /dev/ubi_ctrl -m 4 # mtdblock4与ubi解除连接
或者
ubidetach -d 4 /dev/ubi_ctrl