针对RIoTBoard,官网提供的release 版本的镜像,是基于kernal header 3.6版本的,kernal版本比较旧,最新的kernal 应该是5.10版本的了,于是打算自己构建一个kernal新一点的系统。目前构建嵌入式系统比较强大的两个工具是Yocto和Buildroot,Yocto將嵌入系Linux建制成Binary套件,功能强大,但是上手较慢,学习起来也比较难,对硬件的要求较高;相比之下Buildroot比较简单,上手较快,因此选择了使用Buildroot来构建系统。
1 下载与编译
使用git 下载Buildroot source code,我选择的版本是2018 release版本,基于kernal header 4.18:
git clone https://git.busybox.net/buildroot -b 2018.11.x
下载后执行编译
sudo make riotboard_defconfig
sudo make
编译时间大概持续了4个小时左右,电脑配置高点和开了代理花费的时间会更短点,编译成功会有如下log印出:
>>> Executing post-image script support/scripts/genimage.sh
INFO: cmd: "mkdir -p "/home/zhy/code/rIoTboard/buildroot/buildroot-2018.11.x/output/build/genimage.tmp"" (stderr):
INFO: cmd: "rm -rf "/home/zhy/code/rIoTboard/buildroot/buildroot-2018.11.x/output/build/genimage.tmp"/*" (stderr):
INFO: cmd: "mkdir -p "/home/zhy/code/rIoTboard/buildroot/buildroot-2018.11.x/output/images"" (stderr):
INFO: cmd: "mkdir -p "/home/zhy/code/rIoTboard/buildroot/buildroot-2018.11.x/output/build/genimage.tmp"" (stderr):
INFO: cmd: "cp -a "/home/zhy/code/rIoTboard/buildroot/buildroot-2018.11.x/output/target" "/home/zhy/code/rIoTboard/buildroot/buildroot-2018.11.x/output/build/genimage.tmp/root"" (stderr):
INFO: hdimage(sdcard.img): adding partition 'u-boot' from 'u-boot.imx' ...
INFO: hdimage(sdcard.img): adding partition 'rootfs' (in MBR) from 'rootfs.ext2' ...
INFO: hdimage(sdcard.img): writing MBR
2 系统烧写与测试
编译成功会在output/image目录产出如下的文件:imx6dl-riotboard.dtb、rootfs.ext2、 rootfs.ext4 rootfs.tar 、sdcard.img 、u-boot.bin 、u-boot.imx 、zImage。 我使用的是TF卡启动,首先需要将uboot烧写到TF卡中:
sudo dd if=output/images/u-boot.imx of=/dev/mmcblk0 bs=1k seek=1
uboot烧写成功后会有如下log印出:
463+0 records in
463+0 records out
474112 bytes (474 kB, 463 KiB) copied, 0.0887384 s, 5.3 MB/s
然后在TF卡上创建一个分区来烧写rootfs, 烧写前需要格式化这个分区:
sudo mkfs.ext2 /dev/mmcblk0p1
再将rooffs deploy到TF卡:
sudo mkdir /mnt/sdcard/
sudo mount /dev/mmcblk0p1 /mnt/sdcard/
sudo tar xf rootfs.tar -C /mnt/sdcard/
sudo umount /dev/mmcblk0p1
烧写成功后会有如下log印出: 启动前需要把SW1开关设置成TF卡启动:
10100110(1 表示 ON 位置,0 表示 OFF 位置)
上电后从启动log可以看出uboot是2018.07的版本
U-Boot 2018.07 (Jul 02 2022 - 17:41:06 +0800)
CPU: Freescale i.MX6SOLO rev1.2 996 MHz (running at 792 MHz)
CPU: Commercial temperature grade (0C to 95C) at 42C
Reset cause: POR
Board: RIoTboard
I2C: ready
DRAM: 1 GiB
MMC: FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2
Loading Environment from MMC... *** Warning - bad CRC, using default environment
Failed (-5)
No panel detected: default to HDMI
Display: HDMI (1024x768)
In: serial
Out: serial
Err: serial
Net: FEC [PRIME]
Error: FEC address not set.
kernal版本是4.18:
Starting kernel ...
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 4.18.10 (root@zhy-ThinkPad-E480) (gcc version 7.3.0 (Buildroot 2018.11.4))
[ 0.000000] CPU: ARMv7 Processor [412fc09a] revision 10 (ARMv7), cr=10c5387d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] OF: fdt: Machine model: RIoTboard i.MX6S
[ 0.000000] Memory policy: Data cache writeback
[ 0.000000] cma: Reserved 64 MiB at 0x4c000000
[ 0.000000] CPU: All CPU(s) started in SVC mode.
构建的时候没有选择桌面系统,所以看不到桌面,后续再研究如何构建带有桌面的系统。 编译好的系统已上传到github,项目地址:https://github.com/zhenghaiyang123/riotboard_image_release.git
3 参考文章
https://risc-a-day.blogspot.com/2015/03/buildroot-for-riotboard.html
|