在wsl下开发T113的主线linux(5)-构建ubi文件系统

本文详细介绍了如何使用Buildroot来构建针对SPI-NAND闪存的UBI文件系统,包括配置编译环境、设置文件系统参数、内核选项以及处理启动问题。过程中涉及到的步骤包括选择架构、定制编译器、配置UBI选项,以及解决内核对MTD和UBI支持的问题。最后,文章提到了系统成功启动并展示了部分启动日志。

接下来是构建文件系统,这里使用最新的buildroot
https://buildroot.org/download.htmlicon-default.png?t=MBR7https://buildroot.org/download.html

tar xf buildroot-2022.11.tar.gz
cd buildroot-2022.11
make menuconfig

配置目标指令集类型

配置外部自定义编译器

配置生成文件系统类型为ubifs,最大逻辑擦除块数量决定了spinand的容量,我这里是128M的spinand,所以128M/128k = 1024

上面的这些配置操作可以用下面的默认配置文件代替,在configs文件夹创建sunxi_t113_spinand_defconfig文件,添加下面内容,使用make sunxi_t113_spinand_defconfig载入配置。

# architecture
BR2_arm=y
BR2_cortex_a7=y
BR2_ARM_FPU_VFPV4=y

# Toolchain
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y
BR2_TOOLCHAIN_EXTERNAL_PATH="/home/wsl/arm-none-linux-gnueabihf"
BR2_TOOLCHAIN_EXTERNAL_GLIBC=y
BR2_TOOLCHAIN_EXTERNAL_PREFIX="arm-none-linux-gnueabihf"
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="arm-none-linux-gnueabihf"
BR2_TOOLCHAIN_EXTERNAL_GCC_12=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_20=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC=y
# BR2_TOOLCHAIN_EXTERNAL_INET_RPC is not set
BR2_TOOLCHAIN_EXTERNAL_CXX=y

# system

# kernel

# bootloader

# filesystem / image
BR2_TARGET_ROOTFS_UBI=y
BR2_TARGET_ROOTFS_UBI_PEBSIZE=0x20000
BR2_TARGET_ROOTFS_UBI_SUBSIZE=0
BR2_TARGET_ROOTFS_UBIFS=y
BR2_TARGET_ROOTFS_UBIFS_LEBSIZE=0x1f000
BR2_TARGET_ROOTFS_UBIFS_MINIOSIZE=0x800
BR2_TARGET_ROOTFS_UBIFS_MAXLEBCNT=1024
BR2_TARGET_ROOTFS_UBIFS_OPTS="-F"

配置完成后make开始编译,接下来就是漫长的下载编译过程,大概需要半小时。
编译成功后会生成output/images/rootfs.ubi,使用xfel命令写入。

xfel spinand erase 0x800000 0x7800000
xfel spinand write 0x800000 output/images/rootfs.ubi

复位发现没有启动成功,原来内核默认没有打开mtd和ubi支持,在内核配置添加下面选项

Device Drivers -> Memory Technology Device (MTD) support -> NAND -> SPI NAND device Support   
Device Drivers -> Memory Technology Device (MTD) support -> Enable UBI - Unsorted block images
File Systems -> Miscellaneous filesystems -> UBIFS file system support

或者在arch\arm\configs\sunxi_defconfig中添加

CONFIG_MTD=y
CONFIG_MTD_SPI_NAND=y
CONFIG_MTD_UBI=y
CONFIG_UBIFS_FS=y

后重新载入配置。

另外设备树中的启动参数和分区也需要修改

bootargs = "mem=128M ubi.mtd=3 rootfstype=ubifs root=ubi0:rootfs rw rootwait console=ttyS0,115200";

&spi0 {
	pinctrl-0 = <&spi0_pins>;
	pinctrl-names = "default";
	status = "okay";

	spi_nand: spi_nand@0 {
        #address-cells = <1>;
        #size-cells = <1>;
		compatible = "spi-nand";
		reg = <0>;

		partition@0 {
				label = "awboot";
				reg = <0x0 0x40000>;	/* 256K */
				read-only;
		};

		partition@40000 {
				label = "dtb";
				reg = <0x40000 0x40000>;  /* 256k */
				read-only;
		};

		partition@80000 {
				label = "kernel";
				reg = <0x80000 0x780000>;  /* 7.5MB */
				read-only;
		};

		partition@800000 {
				label = "rootfs";
				reg = <0x800000 0x7800000>;
		};
	};
};

修改完后重新写入spi-nand,系统顺利启动,一个标准linux 6.1的基础busybox文件系统就做好了,可以根据不同应用可在buildroot添加所需的命令,下面是我常用的一些命令,总之非常方便。

make menuconfig
System configuration  ---> [*] Enable root login with password
Target packages  ---> Networking applications  ---> dropbear
Target packages ---> Libraries ---> Hardware handling ---> tslib
Target packages ---> Text editors and viewers ---> nano
Target packages ---> System tools ---> htop
iperf3
coremark
dhrystone

make busybox-menuconfig
Archival Utilities ---> Make tar xxx, Autodetect compressed tarballs
Linux System Utilities ---> Support mounting CIFS/SMB file systems
Networking Utilities ---> httpd
Networking Utilities ---> ntpd
Networking Utilities ---> udhcpd
Process Utilities ---> Support thread display in ps/pstree/top
Process Utilities ---> pgrep
Process Utilities ---> pmap
Process Utilities ---> Show the number of users

完整启动日志

[I] AWBoot r6143 starting...
[I] SPI-NAND: W25N01GV detected
[I] SPI-NAND: read dt blob of size 22242 at 43.00MB/S
[I] SPI-NAND: read Image of size 5424416 at 49.00MB/S
[I]
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值