作者
QQ群:852283276
微信:arm80x86
微信公众号:青儿创客基地
B站:主页 https://space.bilibili.com/208826118
参考
Zynq-Linux移植学习笔记之25-新内核JFFS2文件系统CRC错误解决
UBI文件系统遇到的问题
ubifs 的一点积累
ubifs boot 移植
【转】U-Boot中ubi和ubifs命令的使用
uboot支持ubi和ubifs遇到的问题
uboot中访问ubifs文件系统内容
ubifsmount reports “Error reading superblock”, but linux can mount FS
UBIFS error (pid 0): ubifs_get_sb: cannot open “ubi:rootfs”, error -19
UBIFS - UBI File-System
uboot
打开宏,
#define CONFIG_LZO
#define CONFIG_RBTREE
#define CONFIG_CMD_UBI
#define CONFIG_CMD_UBIFS
测试,
T2080> ubi part rootfs
在文件*\drivers\mtd\ubi\vtbl.c
中ubi_err(ubi, "the layout volume was not found");
没有找到文件系统,
av = ubi_find_av(ai, UBI_LAYOUT_VOLUME_ID);
if (!av) {
printf("%s line%d\n", __FUNCTION__, __LINE__);
/*
* No logical eraseblocks belonging to the layout volume were
* found. This could mean that the flash is just empty. In
* this case we create empty layout volume.
*
* But if flash is not empty this must be a corruption or the
* MTD device just contains garbage.
*/
if (ai->is_empty) {
printf("%s line%d\n", __FUNCTION__, __LINE__);
ubi->vtbl = create_empty_lvol(ubi, ai);
if (IS_ERR(ubi->vtbl))
return PTR_ERR(ubi->vtbl);
} else {
printf("%s line%d\n", __FUNCTION__, __LINE__);
ubi_err(ubi, "the layout volume was not found");
return -EINVAL;
}
} else {
T2080是大端的,x86是小端,用linux格式化ubifs,用uboot访问,
T2080> ubi part rootfs
ubi0: attaching mtd1
ubi0: scanning is finished
ubi0: attached mtd1 (name "mtd=1", size 245 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 130944 bytes
ubi0: min./max. I/O unit sizes: 1/1, sub-page size 1
ubi0: VID header offset: 64 (aligned 64), data offset: 128
ubi0: good PEBs: 1967, bad PEBs: 0, corrupted PEBs: 0
ubi0: user volume: 1, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 1815166974
ubi0: available PEBs: 0, total reserved PEBs: 1967, PEBs reserved for bad PEB handling: 0
T2080> ubifsmount ubi0:rootfs
T2080> ubifsls
<DIR> 296 Thu Sep 20 10:19:49 2018 boot
T2080> ubifsls /boot
36314 Thu Sep 20 10:19:49 2018 system.dtb
5582835 Thu Sep 20 10:19:41 2018 uImage
T2080> ubifsload $loadaddr /boot/uImage
Loading file '/boot/uImage' to addr 0x01000000...
Done
配置内核
配置内核,先后顺序保持,
Device Drivers > Memory Technology Device (MTD) Support > Enable UBI
File systems > Miscellaneous filesystems > UBIFS
ubi命令,
root@t2080rdb-64b:~# ubiformat -h
ubiformat version 1.5.1 - a tool to format MTD devices and flash UBI images
Usage: ubiformat <MTD device node file name> [-s <bytes>] [-O <offs>] [-n]
[-Q <num>] [-f <file>] [-S <bytes>] [-e <value>] [-x <num>] [-y] [-q] [-v] [-h]
[--sub-page-size=<bytes>] [--vid-hdr-offset=<offs>] [--no-volume-table]
[--flash-image=<file>] [--image-size=<bytes>] [--erase-counter=<value>]
[--image-seq=<num>] [--ubi-ver=<num>] [--yes] [--quiet] [--verbose]
[--help] [--version]
Example 1: ubiformat /dev/mtd0 -y - format MTD device number 0 and do
not ask questions.
Example 2: ubiformat /dev/mtd0 -q -e 0 - format MTD device number 0,
be quiet and force erase counter value 0.
-s, --sub-page-size=<bytes> minimum input/output unit used for UBI
headers, e.g. sub-page size in case of NAND
flash (equivalent to the minimum input/output
unit size by default)
-O, --vid-hdr-offset=<offs> offset if the VID header from start of the
physical eraseblock (default is the next
minimum I/O unit or sub-page after the EC
header)
-n, --no-volume-table only erase all eraseblock and preserve erase
counters, do not write empty volume table
-f, --flash-image=<file> flash image file, or '-' for stdin
-S, --image-size=<bytes> bytes in input, if not reading from file
-e, --erase-counter=<value> use <value> as the erase counter value for all
eraseblocks
-x, --ubi-ver=<num> UBI version number to put to EC headers
(default is 1)
-Q, --image-seq=<num> 32-bit UBI image sequence number to use
(by default a random number is picked)
-y, --yes assume the answer is "yes" for all question
this program would otherwise ask
-q, --quiet suppress progress percentage information
-v, --verbose be verbose
-h, -?, --help print help message
-V, --version print program version
root@t2080rdb-64b:~# ubiformat /dev/mtd1
ubiformat: mtd1 (nor), size 257818624 bytes (245.9 MiB), 1967 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 1 bytes
libscan: scanning eraserandom: nonblocking pool is initialized
libscan: scanning eraseblock 1966 -- 100 % complete
ubiformat: 1461 eraseblocks are supposedly empty
ubiformat: warning!: 506 of 1967 eraseblocks contain non-UBI data
ubiformat: continue? (y/N) y
ubiformat: warning!: only 0 of 1967 eraseblocks have valid erase counter
ubiformat: erase counter 0 will be used for all eraseblocks
ubiformat: note, arbitrary erase counter value may be specified using -e option
ubiformat: continue? (y/N) y
ubiformat: use erase counter 0 for all eraseblocks
ubiformat: formatting eraseblock 1966 -- 100 % complete
root@t2080rdb-64b:~# ubiattach -h
ubiattach version 1.5.1 - a tool to attach MTD device to UBI.
Usage: ubiattach [<UBI control device node file name>]
[-m <MTD device number>] [-d <UBI device number>] [-p <path to device>]
[--mtdn=<MTD device number>] [--devn=<UBI device number>]
[--dev-path=<path to device>]
[--max-beb-per1024=<maximum bad block number per 1024 blocks>]
UBI control device defaults to /dev/ubi_ctrl if not supplied.
Example 1: ubiattach -p /dev/mtd0 - attach /dev/mtd0 to UBI
Example 2: ubiattach -m 0 - attach MTD device 0 (mtd0) to UBI
Example 3: ubiattach -m 0 -d 3 - attach MTD device 0 (mtd0) to UBI
and create UBI device number 3 (ubi3)
Example 4: ubiattach -m 1 -b 25 - attach /dev/mtd1 to UBI and reserve
25*C/1024 eraseblocks for bad block handling, where C is the flash
is total flash chip eraseblocks count, that is flash chip size in
eraseblocks (including bad eraseblocks). E.g., if the flash chip
has 4096 PEBs, 100 will be reserved.
-d, --devn=<number> the number to assign to the newly created UBI device
(assigned automatically if this is not specified)
-p, --dev-path=<path> path to MTD device node to attach
-m, --mtdn=<number> MTD device number to attach (alternative method, e.g
if the character device node does not exist)
-O, --vid-hdr-offset VID header offset (do not specify this unless you really
know what you are doing, the default should be optimal)
-b, --max-beb-per1024 maximum expected bad block number per 1024 eraseblock.
The default value is correct for most NAND devices.
Allowed range is 0-768, 0 means the default kernel value.
-h, --help print help message
-V, --version print program version
root@t2080rdb-64b:~# ubiattach -p /dev/mtd1
ubi0: attaching mtd1
ubi0: scanning is finished
ubi0: attached mtd1 (name "rootfs", size 245 MiB)
ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 130944 bytes
ubi0: min./max. I/O unit sizes: 1/1024, sub-page size 1
ubi0: VID header offset: 64 (aligned 64), data offset: 128
ubi0: good PEBs: 1967, bad PEBs: 0, corrupted PEBs: 0
ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 0/0, WL threshold: 4096, image sequence number: 1815166974
ubi0: available PEBs: 1963, total reserved PEBs: 4, PEBs reserved for bad PEB handling: 0
ubi0: background thread "ubi_bgt0d" started, PID 1983
UBI device number 0, total 1967 LEBs (257566848 bytes, 245.6 MiB), available 1963 LEBs (257043072 bytes, 245.1 MiB), LEB size 130944 bytes (127.9 KiB)
root@t2080rdb-64b:~# ubimkvol -h
ubimkvol version 1.5.1 - a tool to create UBI volumes.
Usage: ubimkvol <UBI device node file name> [-h] [-a <alignment>] [-n <volume ID>] [-N <name>]
[-s <bytes>] [-S <LEBs>] [-t <static|dynamic>] [-V] [-m]
[--alignment=<alignment>][--vol_id=<volume ID>] [--name=<name>]
[--size=<bytes>] [--lebs=<LEBs>] [--type=<static|dynamic>] [--help]
[--version] [--maxavsize]
Example: ubimkvol /dev/ubi0 -s 20MiB -N config_data - create a 20 Megabytes volume
named "config_data" on UBI device /dev/ubi0.
-a, --alignment=<alignment> volume alignment (default is 1)
-n, --vol_id=<volume ID> UBI volume ID, if not specified, the volume ID
will be assigned automatically
-N, --name=<name> volume name
-s, --size=<bytes> volume size volume size in bytes, kilobytes (KiB)
or megabytes (MiB)
-S, --lebs=<LEBs count> alternative way to give volume size in logical
eraseblocks
-m, --maxavsize set volume size to maximum available size
-t, --type=<static|dynamic> volume type (dynamic, static), default is dynamic
-h, -?, --help print help message
-V, --version print program version
root@t2080rdb-64b:~# ubimkvol /dev/ubi0 -N rootfs -m
Set volume size to 257043072
Volume ID 0, size 1963 LEBs (257043072 bytes, 245.1 MiB), LEB size 130944 bytes (127.9 KiB), dynamic, name "rootfs", alignment 1
root@t2080rdb-64b:~# ls /dev | grep ubi
ubi0
ubi0_0
ubi_ctrl
root@t2080rdb-64b:~# mkdir hi
root@t2080rdb-64b:~# mount -t ubifs ubi0:rootfs ./hi
UBIFS (ubi0:0): default file-system created
UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 1994
UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "rootfs"
UBIFS (ubi0:0): LEB size: 130944 bytes (127 KiB), min./max. I/O unit sizes: 8 bytes/1024 bytes
UBIFS (ubi0:0): FS size: 255733632 bytes (243 MiB, 1953 LEBs), journal size 12832512 bytes (12 MiB, 98 LEBs)
UBIFS (ubi0:0): reserved for root: 4952683 bytes (4836 KiB)
UBIFS (ubi0:0): media format: w4/r0 (latest is w4/r0), UUID 1D373E95-2817-4C22-A0B3-C85AC8EDDA71, small LPT model
第一次运行只需执行,
root@t2080rdb-64b:~# ubiformat /dev/mtd1
root@t2080rdb-64b:~# ubiattach -p /dev/mtd1
root@t2080rdb-64b:~# ubimkvol /dev/ubi0 -N rootfs -m
root@t2080rdb-64b:~# mount -t ubifs ubi0:rootfs ./hi
第二次运行只需执行,
root@t2080rdb-64b:~# ubiattach -p /dev/mtd1
root@t2080rdb-64b:~# mount -t ubifs ubi0:rootfs ./hi
从ubifs启动根文件系统,
ubifs_bootargs=earlycon rootfstype=ubifs noinitrd ubi.mtd=1 root=ubi0:rootfs rw console=ttyS0,115200\0