先准备以下几个压缩包,可以独立下载压缩包,也可以通过yocto工程获取
l@l:/work/imx8mq-sdk/bootloader$ ll
总用量 18480
drwxr-xr-x 4 l l 4096 6月 7 2018 firmware-imx-7.4/
-rwxrwxrwx 1 l l 2613383 5月 10 09:55 firmware-imx-7.4.tar.bz2*
drwxr-xr-x 24 l l 4096 5月 24 23:17 imx8m-uboot-imx-2017.03-r0/
-rwxrwxrwx 1 l l 13974645 5月 10 09:55 imx8m-uboot-imx-2017.03-r0.tar.bz2*
drwxr-xr-x 19 l l 4096 5月 18 12:22 imx-atf-1.4.1/
-rwxrwxrwx 1 l l 2212964 5月 10 09:55 imx-atf-1.4.1.tar.bz2*
drwxrwxr-x 7 l l 4096 5月 24 23:17 imx-mkimage/
-rwxrwxrwx 1 l l 82828 5月 10 09:55 imx-mkimage.tar.bz2*
-rwxrwxr-x 1 l l 682 5月 18 14:06 remake.sh*
firmware-imx-7.4是一些初始化的bin格式文件,由spl或者uboot调用,用以初始化ddr和hdmi
l@l:/work/imx8mq-sdk/bootloader/firmware-imx-7.4/firmware$ ls ddr/synopsys/lpddr4_pmu_train_* hdmi/cadence/signed_hdmi_imx8m.bin -l
-rw-r--r-- 1 l l 1668 6月 7 2018 ddr/synopsys/lpddr4_pmu_train_1d_dmem.bin
-rw-r--r-- 1 l l 32244 6月 7 2018 ddr/synopsys/lpddr4_pmu_train_1d_imem.bin
-rw-r--r-- 1 l l 1380 6月 7 2018 ddr/synopsys/lpddr4_pmu_train_2d_dmem.bin
-rw-r--r-- 1 l l 23232 6月 7 2018 ddr/synopsys/lpddr4_pmu_train_2d_imem.bin
-rw-r--r-- 1 l l 105304 6月 7 2018 hdmi/cadence/signed_hdmi_imx8m.bin
atf: ARM Trusted Firmware;进行一些cortex-A8相关的初始化。提供源码,需要自己重新编译。
编译脚本:
#!/bin/bash
source /opt/fsl-imx-x11/4.9.51-mx8-beta/environment-setup-aarch64-poky-linux
cd imx-atf-1.4.1
make PLAT=imx8mq bl31 -j4
此部分包括u-boot-spl.bin 和 u-boot-nodtb.bin
编译脚本:
cd imx8m-uboot-imx-2017.03-r0/
source /opt/fsl-imx-x11/4.9.51-mx8-beta/environment-setup-aarch64-poky-linux
make mrproper
make imx8mq_evk_defconfig
unset LDFLAGS
make -j4
cp u-boot-nodtb.bin spl/u-boot-spl.bin arch/arm/dts/fsl-imx8mq-evk.dtb ../imx-mkimage/iMX8M/
cp tools/mkimage ../imx-mkimage/iMX8M/mkimage_uboot
独立编译,没有git版本控制信息。所以屏蔽git相关信息
# 顶层Makefile
35 buildinfo:
36 @echo -n '#define MKIMAGE_COMMIT 0x12345678' > src/build_info.h
37# @git rev-parse --short=8 HEAD >> src/build_info.h
38 @echo ' ' >> src/build_info.h
直接输出bootloader的编译镜像文件flash.bin文件。
#!/bin/bash
cd imx8m-uboot-imx-2017.03-r0/
source /opt/fsl-imx-x11/4.9.51-mx8-beta/environment-setup-aarch64-poky-linux
make mrproper
make imx8mq_evk_defconfig
unset LDFLAGS
make -j4
cp u-boot-nodtb.bin spl/u-boot-spl.bin arch/arm/dts/fsl-imx8mq-evk.dtb ../imx-mkimage/iMX8M/
cp tools/mkimage ../imx-mkimage/iMX8M/mkimage_uboot
cd ../imx-atf-1.4.1/
make PLAT=imx8mq bl31 -j4
cp build/imx8mq/release/bl31.bin ../imx-mkimage/iMX8M/
cd ../firmware-imx-7.4/
cp firmware/ddr/synopsys/lpddr4_pmu_train_* ../imx-mkimage/iMX8M/
cp firmware/hdmi/cadence/signed_hdmi_imx8m.bin ../imx-mkimage/iMX8M/
cd ../imx-mkimage/
make SOC=iMX8M flash_hdmi_spl_uboot
cp iMX8M/flash.bin ../
flash.bin文件由imx-mkimage工具生成,在编译前,先把所需文件拷贝到对应SOC文件夹下
## 已删除原有文件,下面为需要准备的文件
l@l:/work/imx8mq-sdk/bootloader/imx-mkimage$ ls iMX8M/ -l
总用量 2992
-rwxrwxr-x 1 l l 50840 5月 24 23:17 bl31.bin
-rw-rw-r-- 1 l l 28997 5月 24 23:17 fsl-imx8mq-evk.dtb
-rw-r--r-- 1 l l 1668 5月 24 23:17 lpddr4_pmu_train_1d_dmem.bin
-rw-r--r-- 1 l l 32244 5月 24 23:17 lpddr4_pmu_train_1d_imem.bin
-rw-r--r-- 1 l l 1380 5月 24 23:17 lpddr4_pmu_train_2d_dmem.bin
-rw-r--r-- 1 l l 23232 5月 24 23:17 lpddr4_pmu_train_2d_imem.bin
-rwxrwxr-x 1 l l 168496 5月 24 23:17 mkimage_uboot
-rw-r--r-- 1 l l 105304 5月 24 23:17 signed_hdmi_imx8m.bin
-rwxrwxr-x 1 l l 590072 5月 24 23:17 u-boot-nodtb.bin
-rwxrwxr-x 1 l l 72632 5月 24 23:17 u-boot-spl.bin
执行
make SOC=iMX8M flash_hdmi_spl_uboot
传入目标为:flash_hdmi_spl_uboot
在Makefile中找不到flash_hdmi_spl_uboot,所以使用DEFAULT目标:
.DEFAULT:
@$(MAKE) -s --no-print-directory bin
@$(MAKE) --no-print-directory -C $(SOC) -f soc.mak $@
@$(MAKE) -s --no-print-directory bin
@$(MAKE)
:${MAKE}
就是预设的 make 这个命令的名称(或者路径)。-s --no-print-directory
:就是静默编译,不输出编译信息。bin: $(MKIMG)
MKIMG = $(PWD)/mkimage_imx8
SRCS = src/imx8qm.c src/imx8qx.c src/mkimage_imx8.c
$(MKIMG): buildinfo $(SRCS)
@echo "Compiling mkimage_imx8"
$(CC) $(CFLAGS) $(SRCS) -o $(MKIMG) -I src
@$(MAKE) --no-print-directory -C $(SOC) -f soc.mak $@
-C $(SOC)
:指定下层Makefile,指定完之后调用下层的Makefile文件。-f soc.mak
:从soc.mak读入Makefile。也即,使用soc.mak的make规则make -f Make.Linux
或make --file Make.AIX
。$(SOC)
下@$(MAKE)
动作执行`@$(MAKE) --no-print-directory -C iMX8M -f soc.mak flash_hdmi_spl_uboot`
进入iMX8M子目录,make目标flash_hdmi_spl_uboot
解析soc.mak:
flash_hdmi_spl_uboot: flash_evk
flash_evk: $(MKIMG) signed_hdmi_imx8m.bin u-boot-spl-ddr.bin u-boot.itb
./mkimage_imx8 -fit -signed_hdmi signed_hdmi_imx8m.bin -loader u-boot-spl-ddr.bin 0x7E1000 -second_loader u-boot.itb 0x40200000 0x60000 -out $(OUTIMG)
上面的几个依赖,还有$(MKIMG)
、u-boot-spl-ddr.bin 和 u-boot.itb 没有
$(MKIMG)
编译$(MKIMG)
工具,该工具用于生成最终的flash.bin文件;
$(MKIMG): mkimage_imx8.c
@echo "Compiling mkimage_imx8"
$(CC) $(CFLAGS) mkimage_imx8.c -o $(MKIMG) -lz
$(CC)
:gcc命令$(CFLAGS)
:-O2 -Wall -std=c99 -static
$(MKIMG)
:MKIMAGE = mkimage_imx8
-lz
:连接libz库u-boot-spl-ddr.bin: u-boot-spl.bin lpddr4_pmu_train_1d_imem.bin lpddr4_pmu_train_1d_dmem.bin lpddr4_pmu_train_2d_imem.bin lpddr4_pmu_train_2d_dmem.bin
@objcopy -I binary -O binary --pad-to 0x8000 --gap-fill=0x0 lpddr4_pmu_train_1d_imem.bin lpddr4_pmu_train_1d_imem_pad.bin
@objcopy -I binary -O binary --pad-to 0x4000 --gap-fill=0x0 lpddr4_pmu_train_1d_dmem.bin lpddr4_pmu_train_1d_dmem_pad.bin
@objcopy -I binary -O binary --pad-to 0x8000 --gap-fill=0x0 lpddr4_pmu_train_2d_imem.bin lpddr4_pmu_train_2d_imem_pad.bin
@cat lpddr4_pmu_train_1d_imem_pad.bin lpddr4_pmu_train_1d_dmem_pad.bin > lpddr4_pmu_train_1d_fw.bin
@cat lpddr4_pmu_train_2d_imem_pad.bin lpddr4_pmu_train_2d_dmem.bin > lpddr4_pmu_train_2d_fw.bin
@cat u-boot-spl.bin lpddr4_pmu_train_1d_fw.bin lpddr4_pmu_train_2d_fw.bin > u-boot-spl-ddr.bin
@rm -f lpddr4_pmu_train_1d_fw.bin lpddr4_pmu_train_2d_fw.bin lpddr4_pmu_train_1d_imem_pad.bin lpddr4_pmu_train_1d_dmem_pad.bin lpddr4_pmu_train_2d_imem_pad.bin
依赖全都有了,直接执行下面指令
objcopy
·:将目标文件的一部分或者全部内容拷贝到另外一个目标文件中,或者实现目标文件的格式转换。-I binary -O binary
:指定输入输出格式,binary为二进制格式--pad-to 0x8000 --gap-fill=0x0
:从bin文件末开始,用--gap-fill=0x0
,一直填充到--pad-to 0x8000
,作用就是把bin文件设定为0x8000 = 32KB大小所以,生成的u-boot-spl-ddr.bin二进制文件image map就是
文件 | 大小 |
---|---|
u-boot-spl.bin | 实际大小 |
lpddr4_pmu_train_1d_imem.bin | 0x8000固定大小 |
lpddr4_pmu_train_1d_dmem.bin | 0x4000固定大小 |
lpddr4_pmu_train_2d_imem.bin | 0x8000固定大小 |
lpddr4_pmu_train_2d_dmem.bin | 实际大小 |
u-boot.itb: $(dtbs)
./mkimage_fit_atf.sh $(dtbs) > u-boot.its
./mkimage_uboot -E -p 0x3000 -f u-boot.its u-boot.itb
@rm -f u-boot.its
$(dtbs)
: fsl-imx8mq-evk.dtb./mkimage_fit_atf.sh $(dtbs) > u-boot.its
:输出的 u-boot.its参考下面TAG-u-boot.its,该文件被mkimage_uboot使用,mkimage_uboot来源于uboot/tools/mkimage-f
:指定FIT(flattenned image tree)的文件名./mkimage_uboot -E -p 0x3000 -f u-boot.its u-boot.itb
:的作用就是把u-boot.its设备树格式的文本编译成设备树,然后放在u-boot.itb的开始位置,然后用0x0填充到0x3000字节。接着,根据传入设备树描述信息,开始填充u-boot.itbmap | size | content |
---|---|---|
0000_0000 0000_0370 | 0x370 | FIT |
0000_0370 0000_3000 | 0x2C90 | 0 |
0000_3000 0009_3140 | 0x90140 | u-boot-nodtb.bin |
0009_3140 0009_F7D8 | 0xC698 | bl31.bin |
0009_F7D8 000A_691D | 0x7145 | fsl-imx8mq-evk.dtb |
执行mkimage_imx8,从iMX8M/mkimage_imx8.c的main函数开始分析
./mkimage_imx8 -fit -signed_hdmi signed_hdmi_imx8m.bin -loader u-boot-spl-ddr.bin 0x7E1000 -second_loader u-boot.itb 0x40200000 0x60000 -out $(OUTIMG)
最后,flash.bin的内存映象为:
map | size | content |
---|---|---|
0000_0000 0001_9758 | 0x19758 | signed_hdmi_imx8m.bin |
0001_A000 0001_A030 | 0x30 | image ivt header |
0001_A030 0004_09B4 | 0x26984 | u-boot-spl-ddr.bin |
0004_0A00 0004_2A00 | 0x2000 | CSF:0 |
0005_7C00 000F_E520 | 0xA6920 | u-boot.itb |
TAG-u-boot.its:
/dts-v1/;
/ {
description = "Configuration to load ATF before U-Boot";
images {
uboot@1 {
description = "U-Boot (64-bit)";
data = /incbin/("u-boot-nodtb.bin");
type = "standalone";
arch = "arm64";
compression = "none";
load = <0x40200000>;
};
atf@1 {
description = "ARM Trusted Firmware";
data = /incbin/("bl31.bin");
type = "firmware";
arch = "arm64";
compression = "none";
load = <0x00910000>;
entry = <0x00910000>;
};
fdt@1 {
description = "fsl-imx8mq-evk";
data = /incbin/("fsl-imx8mq-evk.dtb");
type = "flat_dt";
compression = "none";
};
};
configurations {
default = "config@1";
config@1 {
description = "fsl-imx8mq-evk";
firmware = "uboot@1";
loadables = "atf@1";
fdt = "fdt@1";
};
};
};
END-TAG
TAG-u-boot.itb:
l@l:/work/imx8mq-sdk/uboot/imx-mkimage/iMX8M$ mkimage -l u-boot.itb
FIT description: Configuration to load ATF before U-Boot
Created: Sun May 19 00:52:57 2019
Image 0 (uboot@1)
Description: U-Boot (64-bit)
Created: Sun May 19 00:52:57 2019
Type: Standalone Program
Compression: uncompressed
Data Size: unavailable
Architecture: AArch64
Load Address: 0x40200000
Entry Point: 0xffffffff
Image 1 (atf@1)
Description: ARM Trusted Firmware
Created: Sun May 19 00:52:57 2019
Type: Firmware
Compression: uncompressed
Data Size: unavailable
Architecture: AArch64
Load Address: 0x00910000
Image 2 (fdt@1)
Description: fsl-imx8mq-evk
Created: Sun May 19 00:52:57 2019
Type: Flat Device Tree
Compression: uncompressed
Data Size: unavailable
Architecture: Unknown Architecture
Default Configuration: 'config@1'
Configuration 0 (config@1)
Description: fsl-imx8mq-evk
Kernel: unavailable
FDT: fdt@1
Loadables: atf@1
END-TAG