U-Boot 移植
前面我们已经配置 Yocto 工程,构建出 SDK 并安装编译工具链。
DISTRO=fsl-imx-xwayland MACHINE=imx8mqevk source imx-setup-release.sh -b build-xwayland
bitbake imx-image-full -c populate_sdk
为了顺利启动 i.MX8 板子,我们还需要修改并构建出适用的 U-Boot。下面会介绍两种构建 U-Boot 的方法,一种是通过独立环境构建,另一种是通过 Yocto 工程构建。
独立环境构建 U-Boot
下载 uboot 源代码
git clone https://source.codeaurora.org/external/imx/uboot-imx -b imx_v2020.04_5.4.47_2.2.0
配置 uboot
cd uboot-imx
make clean
make imx8mq_evk_defconfig
我们这里使用与我们的硬件平台最接近的 imx8mq_evk_defconfig 配置,你也可以将其复制一份,重命名并修改为定制的板级配置。
编译
make
编译结束后,得到 4 个文件
- u-boot-nodtb.bin
- tool/mkimage
- spl/u-boot-spl.bin
- arch/arm/dts/imx8mq-evk.dtb
For i.MX 8, use the imx-mkimage tool to combine the U-Boot binary with Arm Trusted Firmware (ATF) and SCUFW to produce the final flash.bin boot image and burn to the SD card. See the imxmkimage tool for details.
对于 i.MX8,请使用 imx-mkimage 工具将 U-Boot 二进制文件与 Arm Trusted Firmware(ATF)和 SCUFW 结合使用,以生成最终的 flash.bin 引导映像并刻录到 SD 卡。 有关详细信息,请参见 imx-mkimage 工具。
烧录 uboot
dd if=<boot_image> of=/dev/sd<x> bs=1k seek=<offset> conv=fsync
对于 i.MX8 来说,offset 为 33,假设 SD 卡对应 /dev/sdb 块设备,那么具体的烧录命令如下:
dd if=flash.bin of=/dev/sdb bs=1k seek=33 conv=fsync
Yocto 工程构建 U-Boot
生成 flash.bin
配置编译环境
source /opt/fsl-imx-xwayland/5.4-zeus/environment-setup-aarch64-poky-linux
制作用于烧写的引导镜像 :imx-boot-imx8mqevk-sd.bin-flash_hdmi_spl_uboot
编译 uboot 源码
编译后可得到:
u-boot-nodtb.bin
tool/mkimage
spl/u-boot-spl.bin
arch/arm/dts/imx8mq-evk.dtb
一共 4 个文件。
编译 ATF(bl31.bin) :ARM trusted FW
git clone https://source.codeaurora.org/external/imx/imx-atf
检出对应的版本
cd imx-atf
git tag
...
rel_imx_5.4.47_2.2.0
...
git checkout rel_imx_5.4.47_2.2.0
编译
LDFLAGS="" make PLAT=imx8mq
编译结束后,得到 build/imx8mq/release/bl31.bin 文件。
imx-boot-tools
在 Yocto 工程的 build 目录下的 tmp/deploy/images/imx8mqevk/imx-boot-tools/
3、解压 firmware-imx-7.4.tar.bz2
得到
firmware/ddr/synopsys/lpddr4_pmu_train_1d_dmem.bin
firmware/ddr/synopsys/lpddr4_pmu_train_1d_imem.bin
firmware/ddr/synopsys/lpddr4_pmu_train_2d_dmem.bin
firmware/ddr/synopsys/lpddr4_pmu_train_2d_imem.bin
firmware/hdmi/cadence/signed_hdmi_imx8m.bin
共 5 个文件
以上步骤 1~3 可以得到 10 个文件
准备 imx-mkimage 工具
git clone https://source.codeaurora.org/external/imx/imx-mkimage
检出对应版本
cd imx-mkimage
git tag
...
rel_imx_5.4.47_2.2.0
...
git checkout rel_imx_5.4.47_2.2.0
把上面 10 个文件复制到目录 imx-mkimage/iMX8M/ 下,并更改 mkimage 为 mkimage_uboot 。
mv mkimage mkimage_uboot
用下面指令编译 flash.bin 文件
make clean
make SOC=iMX8M flash_hdmi_spl_uboot
生成文件 iMX8M/flash.bin
重命名 flash.bin 为 imx-boot-imx8mqevk-sd.bin-flash_hdmi_spl_uboot 即可。
脚本化
cd uboot-imx
cp spl/u-boot-spl.bin ../imx-mkimage/iMX8M/ -f
cp tools/mkimage ../imx-mkimage/iMX8M/mkimage_uboot -f
cp u-boot-nodtb.bin ../imx-mkimage/iMX8M/ -f
cp arch/arm/dts/imx8mq-evk.dtb ../imx-mkimage/iMX8M/ -f
注意:测试发现不使用 make clean 这里每次都要清除之前的编译残留。否则新修改的内容可能并没更新到 flash.bin 文件中。
Linux 镜像分布
启动 uboot
U-Boot 2020.04-g6b8ad0715e (May 26 2021 - 22:47:32 +0800)
CPU: i.MX8MQ rev2.1 1300 MHz (running at 800 MHz)
CPU: Industrial temperature grade (-40C to 105C) at 42C
Reset cause: POR
Model: NXP i.MX8MQ EVK
DRAM: 2 GiB