有被问到在uboot中访问ubi文件系统,之前大概了解,但是没有实际操作,这次还是操作一遍看看。
至少配置以下几项,其他的驱动是必备的
#define CONFIG_MTD_DEVICE
#define CONFIG_CMD_UBI
#define CONFIG_CMD_UBIFS
#define CONFIG_CMD_MTDPARTS
#define CONFIG_MTD_PARTITIONS
help之后的打印会看到:
mtdparts- define flash/nand partitions
ubi - ubi commands
ubifsload- load file from an UBIFS filesystem
ubifsls - list files in a directory
ubifsmount- mount UBIFS volume
ubifsumount- unmount UBIFS volume
首先使用mtdparts命令生成所有的mtd默认分区,
halley2-sfcnand# mtdparts default
halley2-sfcnand# mtdparts
device nand0 , # parts = 4
#: name size offset mask_flags
0: boot 0x00100000 0x00000000 0
1: kernel 0x00800000 0x00100000 0
2: rootfs 0x02800000 0x00900000 0
3: data 0x0cf00000 0x03100000 0
active partition: nand0,0 - (boot) 0x00100000 @ 0x00000000
defaults:
mtdids : nand0=nand
mtdparts: mtdparts=nand:1M(boot),8M(kernel),40M(rootfs),-(data)
使用ubi part命令连接mtd分区, 例如链接rootfs分区, 激活当前分区会将已经激活的分区取消链接
halley2-sfcnand# ubi part nand
halley2-sfcnand# ubi part
Device 0: nand0, partition rootfs
使用ubi info 查看当前分区信息, 注意其中的PEB代表可擦除的物理页个数
每个物理页大小128K
halley2-sfcnand# ubi info
UBI: MTD device name: "mtd=2"
UBI: MTD device size: 40 MiB
UBI: physical eraseblock size: 131072 bytes (128 KiB)
UBI: logical eraseblock size: 126976 bytes
UBI: number of good PEBs: 320
UBI: number of bad PEBs: 0
UBI: smallest flash I/O unit: 2048
UBI: VID header offset: 2048 (aligned 2048)
UBI: data offset: 4096
UBI: max. allowed volumes: 128
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 2
UBI: available PEBs: 0
UBI: total number of reserved PEBs: 320
UBI: number of PEBs reserved for bad PEB handling: 3
UBI: max/mean erase counter: 5/1
查看更详细的信息, 其中 test 卷标是使用ubi create test创建的。
halley2-sfcnand# ubi info l
UBI: volume information dump:
UBI: vol_id 0
UBI: reserved_pebs 266
UBI: alignment 1
UBI: data_pad 0
UBI: vol_type 3
UBI: name_len 6
UBI: usable_leb_size 126976
UBI: used_ebs 266
UBI: used_bytes 33775616
UBI: last_eb_bytes 126976
UBI: corrupted 0
UBI: upd_marker 0
UBI: name rootfs
UBI: volume information dump:
UBI: vol_id 1
UBI: reserved_pebs 47
UBI: alignment 1
UBI: data_pad 0
UBI: vol_type 3
UBI: name_len 4
UBI: usable_leb_size 126976
UBI: used_ebs 47
UBI: used_bytes 5967872
UBI: last_eb_bytes 126976
UBI: corrupted 0
UBI: upd_marker 0
UBI: name test
UBI: volume information dump:
UBI: vol_id 2147479551
UBI: reserved_pebs 2
UBI: alignment 1
UBI: data_pad 0
UBI: vol_type 3
UBI: name_len 13
UBI: usable_leb_size 126976
UBI: used_ebs 2
UBI: used_bytes 253952
UBI: last_eb_bytes 2
UBI: corrupted 0
UBI: upd_marker 0
UBI: name layout volume
ubi info Display volume and ubi layout information
ubi createvol Create UBI volume on UBI device
ubi removevol Remove UBI volume from UBI device
ubi read Read data from UBI volume to memory
ubi write Write data from memory to UBI volume
ubifsmount
ubifsumount
ubifsls
ubifsload
halley2-sfcnand# help ubifsmount
ubifsmount - mount UBIFS volume
Usage:
ubifsmount <volume-name>
- mount 'volume-name' volume
halley2-sfcnand# help ubifsumount
ubifsumount - unmount UBIFS volume
Usage:
ubifsumount - unmount current volume
halley2-sfcnand# help ubifsload
ubifsload - load file from an UBIFS filesystem
Usage:
ubifsload [bytes]
- load file 'filename' to address 'addr'
halley2-sfcnand# help ubifsls
ubifsls - list files in a directory
Usage:
ubifsls [directory]
- list files in a 'directory' (default '/')
要访问ubifs文件系统的内容, 首先需要执行ubifsmount操作挂在分区:volume, 从上一节中可以直到rootfs文件挂在到了ubi0, 有卷标rootfs, test, layout volume, 其中test是只创建了卷标,并没有数据,所以无法挂在,layout volume是根卷标,没有内容。 只有rootfs有数据,可以挂载, 如下:
halley2-sfcnand# ubi part rootfs
UBI: mtd1 is detached from ubi0
UBI: attaching mtd1 to ubi0
halley2-sfcnand# ubifsmount ubi0:rootfs
UBIFS: mounted UBI device 0, volume 0, name "rootfs"
UBIFS: mounted read-only
UBIFS: file system size: 32378880 bytes (31620 KiB, 30 MiB, 255 LEBs)
UBIFS: journal size: 9023488 bytes (8812 KiB, 8 MiB, 72 LEBs)
UBIFS: media format: w4/r0 (latest is w4/r0)
UBIFS: default compressor: LZO
UBIFS: reserved for root: 0 bytes (0 KiB)
halley2-sfcnand# ubifsls
<DIR> 4576 Wed Jan 03 06:43:17 2018 bin
<DIR> 224 Fri Sep 08 04:17:51 2017 dev
<DIR> 2224 Wed Jan 03 06:43:18 2018 etc
<DIR> 2960 Wed Jan 03 06:43:18 2018 lib
<DIR> 232 Fri Sep 08 04:17:51 2017 mnt
<DIR> 232 Fri Sep 08 04:17:51 2017 opt
<DIR> 304 Wed Jan 03 06:43:18 2018 tmp
<DIR> 232 Fri Sep 08 04:17:51 2017 sys
<DIR> 608 Fri Sep 22 09:34:23 2017 var
<DIR> 608 Wed Jan 03 06:43:18 2018 usr
<DIR> 232 Fri Sep 08 04:17:51 2017 proc
<DIR> 4000 Wed Jan 03 06:43:27 2018 sbin
<DIR> 232 Fri Sep 22 09:34:23 2017 root
<LNK> 11 Fri Sep 08 04:17:51 2017 linuxrc
<LNK> 3 Fri Sep 08 04:17:51 2017 lib32
<DIR> 232 Fri Sep 08 04:17:51 2017 media
<DIR> 600 Wed Jan 03 06:43:58 2018 testsuite
<DIR> 760 Wed Jan 03 06:43:18 2018 firmware
halley2-sfcnand# ubifsload 0x80600000 etc/fstab 1024
Loading file 'etc/fstab' to addr 0x80600000 with size 405 (0x00000195)...
Done
halley2-sfcnand# md 0x80600000
80600000: 652f2023 662f6374 62617473 7473203a # /etc/fstab: st
80600010: 63697461 6c696620 79732065 6d657473 atic file system
80600020: 666e6920 616d726f 6e6f6974 0a230a2e information..#.
80600030: 663c2023 20656c69 74737973 203e6d65 #
80600040: 756f6d3c 7020746e 20203e74 3c202020 <
80600050: 65707974 6f3c093e 6f697470 203e736e type>.
80600060: 20202020 20202020 6d75643c 3c203e70 <
80600070: 73736170 642f0a3e 722f7665 20746f6f pass>./dev/root
80600080: 20202020 202f2020 20202020 20202020 /
80600090: 20202020 74786520 77720932 616f6e2c ext2.rw,noa
806000a0: 206f7475 20202020 20202020 20202030 uto 0
806000b0: 31202020 6f72700a 09090963 6f72702f 1.proc.../pro
806000c0: 20200963 20202020 6f727020 20202063 c. proc
806000d0: 65642020 6c756166 20097374 20093020 defaults. 0.
806000e0: 79730a30 09736673 732f0909 20097379 0.sysfs.../sys.
806000f0: 20202020 79732020 20736673 64202020 sysfs d