1.UBIFS文件系统
UBIFS是UBI file system的简称,用于裸的flash设备,作为jffs2的后继文件系统之一。UBIFS通过UBI子系统处理与MTD设备之间动作。UBIFS文件系统更适合MLCNAND FLASH。需要注意的是UBIFS并不是为SSD,MMC,SD,Compact Flash等之类的基于flash的存储设备,其是针对于裸flash设备(NOR/NAND)。
2.Create UBIFS Format Root Filesystem on NAND Flash
2.1 Modify Buildroot Configuration
将要编译的defconfig文件复制到/buildroot文件目录下,打开menuconfig
~/buildroot$ cp ./configs/xxxx_defconfig .config
~/buildroot$ make menuconfig
配置configuration制作ubifs image
Filesystem images ---> [*] ubi image containing an ubifs root filesystem (0x20000) physical eraseblock size (NEW) (512) sub-page size (NEW) -*- ubifs root filesystem (0x1f800) logical eraseblock size (NEW) (0x800) minimum I/O unit size (NEW) (2048) maximum logical eraseblock count (NEW)
physical eraseblock size(PEB) :创建 UBI 映像flash的物理擦除块大小为 128KiB
sub-page size: flash 支持子页面,子页面大小为 512 字节
logical eraseblock size:UBI 卷的逻辑擦除块大小为126KiB
minimum I/O unit size:每个设备都分为一定数量的页面。页是一次可以读取或编程的最小数据块。这对应于UBI子系统的最小 I/O 大小为2048byte
maximum logical eraseblock count:这意味着可以使用小于这个逻辑块数的文件系统
这些参数可以通过编译initramfs启动kernel,在目标板上通过mtdinfo命令查看信息
mtdinfo -u /dev/mtd2
如果没有对应的mtdinfo命令需要配置configuration使能对应的mtd-utils
Target packages ---> Filesystem and flash utilities ---> [*] mtd, jffs2 and ubi/ubifs tools
将上述configuration配置完成以后覆盖以前的defconfig文件,编译后就可以得到对应的rootfs.ubifs镜像,此文件可以直接在uboot当中烧写到nand flash当中去。
~/buildroot$ make savedefconfig
~/buildroot$ mv defconfig ./configs/xxxx_defconfig
2.2 Modify Linux Kernel Configuration
配置kernel configuration支持ubifs文件系统
~/kernel$ cp ./arch/arm64/configs/xxxx_defconfig .config
~/kernel$ make menuconfig
[*] Device Drivers ---> <*> Memory Technology Device (MTD) support ---> <*> Enable UBI- Unsorted block images ---> File systems ---> [*] Miscellaneous filesystems ---> <*> UBIFS file system support
2.3 Modify DTS in Kernel
通过修改设备树对nand flash 进行分区
&qspi {
status = "okay";
spi-flash@0 {
compatible = "spi-nand";
spi-max-frequency = <5000000>;
reg = <0>;
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "uboot";
reg = <0x0 0x400000>;
};
partition@400000 {
label = "kernel";
reg = <0x400000 0x1200000>;
};
partition@1600000{
label = "rootfs";
reg = <0x1600000 0xA00000>;
};
};
};
在dts中配置好的nand flash可以在target的kernel当中通过cat命令查看分区信息
cat /proc/mtd
2.4 Modify u-boot *.h
在对应的*.h文件当中,将以下参数添加到 bootargs 内核命令行中:
rootfstype=ubifs root=<卷描述符> ubi.mtd=<mtd 分区>
例子
setenv bootargs 'console=ttyLP1,115200 rootfstype=ubifs ubi.mtd=rootfs root=ubi0:rootfs rw rootwait'
2.5 Burn ubifs in uboot
UBIFS文件系统镜像可以使用命令ubi write烧写到NAND FLASH上,具体命令为:
1.配置FLASH的分区,此处以 NAND FLASH为例,分为3个区:
setenv mtdids nand0=nand0
setenv mtdparts mtdparts=nand0:0x400000(uboot),0x1200000(kernel),0xA00000(rootfs)
2.设置完后,使用mtdparts命令可以看到分区信息:
mtdparts
3.烧写ubifs文件系统
dhcp ${kernel_addr} ${serverip}:rootfs.ubifs
mtd erase spi-nand0 0x1600000 0xA00000
ubi part rootfs //ubi设备与mtd设备的rootfs分区连接
ubi create rootfs //ubi设备生成一个rootfs卷
ubi write ${kernel_addr} rootfs ${blocksize} //将DRAM当中的ubifs写入ubi卷中
通过以上命令,可以将文件系统烧写到第3个分区上,UBIFS文件系统卷标为rootfs。
若uboot当中没有ubi以及mtdparts命令,需要配置uboot当中的config文件,配置方式与上述配置kernel的方法大致相同。
CONFIG_CMD_MTDPARTS=y
CONFIG_CMD_UBI=y
CONFIG_CMD_UBI_RENAME=y
3.Create UBIFS Format Root Filesystem on NOR Flash
主要阐述和nand的区别
3.1 Modify Buildroot Configuration
修改buildroot配置参数,制作与nor flash参数相一致的ubifs
3.2 Modify DTS in Kernel
将compatible参数修改为spi-nor,同时将mtd分区进行修改。
&qspi {
status = "okay";
spi-flash@0 {
compatible = "spi-nor";
spi-max-frequency = <5000000>;
reg = <0>;
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "uboot";
reg = <0x0 0x400000>;
};
partition@400000 {
label = "kernel";
reg = <0x400000 0x1200000>;
};
partition@1600000{
label = "rootfs";
reg = <0x1600000 0xA00000>;
};
};
};
3.3 Modify DTS in Uboot
将uboot当中的设备树设置为spi-nor
&qspi1 {
status = "okay";
spi-nor@0 {
compatible ="spi-nor";
spi-max-frequency = <500000>;
reg = <0>;
};
};