一、编译 TF-A
1. 获取 TF-A 源码
下载链接:en.SOURCES-tf-a-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz[1]。
下载后解压:
代码语言:javascript复制xz -d en.SOURCES-tf-a-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz
mv en.SOURCES-tf-a-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar en.SOURCES-tf-a-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17.tar
tar -xvf en.SOURCES-tf-a-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17.tar
里面分为源码和 patch 文件:
代码语言:javascript复制tf-a-stm32mp-v2.4-stm32mp-r2-r0 TF-A installation directory
├── [*].patch ST patches to apply during the TF-A preparation (see next chapter)
├── tf-a-stm32mp-v2.4-stm32mp-r2 TF-A source code directory
├── Makefile.sdk Makefile for the TF-A compilation
├── README.HOW_TO.txt Helper file for TF-A management: reference for TF-A build
├── series List of all ST patches to apply
└── tf-a-stm32mp-v2.4-stm32mp-r2-r0.tar.gz Tarball file of the TF-A source code
除了 uboot 源码之外,在上一级目录下,还有 FIP_artifacts 目录如下:
代码语言:javascript复制FIP_artifacts
├── arm-trusted-firmware
│ ├── bl32
│ └── fwconfig
2. 编译 TF-A
编译前的准备
(1)OpenSTLinux SDK 必须安装;
(2)编译内核需要安装的包:
llibncurses、libncursesw dev package、libyaml-dev:
代码语言:javascript复制sudo apt-get install libncurses5-dev libncursesw5-dev libyaml-dev
(3)确保 SDK 环境变量生效(注意路径):
代码语言:javascript复制source $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v3.1.0/Developer-Package/SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
接下来开始编译。
解压源码:
代码语言:javascript复制tar -zxvf tf-a-stm32mp-v2.4-stm32mp-r2-r0.tar.gz
源码打补丁:
代码语言:javascript复制cd tf-a-stm32mp-v2.4-stm32mp-r2/
for p in `ls -1 ../*.patch`; do patch -p1 < $p; done
因为在 OpenSTLinux 默认激活了 FIP,所以在编译前必须要指定 FIP_artifacts:
代码语言:javascript复制export FIP_DEPLOYDIR_ROOT=$PWD/../../FIP_artifacts
编译全部:
代码语言:javascript复制make -f $PWD/../Makefile.sdk all
编译出的结果在上级目录的 deploy 文件夹:
3. 烧写测试
使用第一篇文章中烧写成功过的 SD 卡,只替换 FSBL 进行验证:
代码语言:javascript复制sudo dd if=tf-a-stm32mp157c-dk2-sdcard.stm32 of=/dev/sdb1 conv=fdatasync
sudo dd if=tf-a-stm32mp157c-dk2-sdcard.stm32 of=/dev/sdb2 conv=fdatasync
将 SD 卡重新插入 STM32MP157C-DK2 开发板,可以正常启动,查看串口日志,TF-A 编译时间已修改:
二、编译 uboot
1. 获取 uboot 源码(2020.10 版本)
下载链接:en.SOURCES-u-boot-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz[2]
下载后解压:
代码语言:javascript复制mv en.SOURCES-u-boot-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz en.SOURCES-u-boot-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17.tar.xz
tar -xvf en.SOURCES-u-boot-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17.tar.xz
里面分为源码和 patch 文件:
代码语言:javascript复制u-boot-stm32mp-v2020.10-stm32mp-r2-r0 U-Boot installation directory
├── [*].patch ST patches to apply during the U-Boot preparation (see next chapter)
├── u-boot-stm32mp-v2020.10-stm32mp-r2 U-Boot source code directory
├── Makefile.sdk Makefile for the U-Boot compilation
├── README.HOW_TO.txt Helper file for U-Boot management: reference for U-Boot build
├── series List of all ST patches to apply
└── u-boot-stm32mp-v2020.10-stm32mp-r2-r0.tar.gz Tarball file of the U-Boot source code
解压源码:
代码语言:javascript复制tar -zxvf u-boot-stm32mp-v2020.10-stm32mp-r2-r0.tar.gz
除了 uboot 源码之外,在上一级目录下,还有 FIP_artifacts 目录如下:
代码语言:javascript复制FIP_artifacts
├── arm-trusted-firmware
│ ├── bl32
│ └── fwconfig
├── optee
├── u-boot
│ ├── u-boot-nodtb-stm32mp15.bin
│ ├── u-boot-stm32mp157a-dk1-trusted.dtb Device tree for U-Boot → STM32MP15 Discovery kits
│ ├── u-boot-stm32mp157a-ev1-trusted.dtb Device tree for U-Boot → STM32MP15 Evaluation boards
│ ├── u-boot-stm32mp157c-dk2-trusted.dtb Device tree for U-Boot → STM32MP15 Discovery kits
│ ├── u-boot-stm32mp157c-ed1-trusted.dtb Device tree for U-Boot → STM32MP15 Evaluation boards
│ ├── u-boot-stm32mp157c-ev1-trusted.dtb Device tree for U-Boot → STM32MP15 Evaluation boards
│ ├── u-boot-stm32mp157d-dk1-trusted.dtb Device tree for U-Boot → STM32MP15 Discovery kits
│ ├── u-boot-stm32mp157d-ev1-trusted.dtb Device tree for U-Boot → STM32MP15 Evaluation boards
│ ├── u-boot-stm32mp157f-dk2-trusted.dtb Device tree for U-Boot → STM32MP15 Discovery kits
│ ├── u-boot-stm32mp157f-ed1-trusted.dtb Device tree for U-Boot → STM32MP15 Evaluation boards
│ └── u-boot-stm32mp157f-ev1-trusted.dtb Device tree for U-Boot → STM32MP15 Evaluation boards
2. 编译 uboot
2. 1. uboot 源码打 patch
代码语言:javascript复制cd u-boot-stm32mp-v2020.10-stm32mp-r2/
for p in `ls -1 ../*.patch`; do patch -p1 < $p; done
2.2. 编译 uboot(带 FIP)
指定 FIP 文件夹路径:
代码语言:javascript复制export FIP_DEPLOYDIR_ROOT=$PWD/../../FIP_artifacts
编译全部:
代码语言:javascript复制make -f $PWD/../Makefile.sdk all
编译出来之后,需要部署的文件在上一级目录 deploy 中:
同时,编译出的 FIP 文件在上一级目录 FIP_artifacts 中:
3. 烧写测试
使用第一篇文章中烧写成功过的 SD 卡,只替换 FIP 进行验证:
代码语言:javascript复制sudo dd if=fip-stm32mp157c-dk2-trusted.bin of=/dev/sdb3 conv=fdatasync
将 SD 卡重新插入 STM32MP157C-DK2 开发板,可以正常启动,查看串口日志,u-boot 编译时间已修改:
三、编译内核
1. 获取内核源码
下载链接:en.SOURCES-kernel-stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17.tar.xz[3]
下载后解压:
代码语言:javascript复制tar xvf en.SOURCES-kernel-stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17.tar.xz
里面分为源码和 patch 文件:
代码语言:javascript复制linux-stm32mp-5.10.61-r2 Linux kernel installation directory
├── [*].patch ST patches to apply during the Linux kernel preparation (see next chapter)
├── fragment-[*].config ST configuration fragments to apply during the Linux kernel configuration (see next chapter)
├── linux-5.10.61 Linux kernel source code directory
├── linux-5.10.61.tar.xz Tarball file of the Linux kernel source code
├── README.HOW_TO.txt Helper file for Linux kernel management: reference for Linux kernel build
└── series List of all ST patches to apply
解压源码:
代码语言:javascript复制xz -d xvf linux-5.10.61.tar.xz
tar xvf linux-5.10.61.tar
2. 编译 kernel
2.1. 编译前的准备
(1)OpenSTLinux SDK 必须安装;(2)编译内核需要安装的包:
llibncurses、libncursesw dev package、libyaml-dev:
代码语言:javascript复制sudo apt-get install libncurses5-dev libncursesw5-dev libyaml-dev
mkimage:
代码语言:javascript复制sudo apt-get install u-boot-tools
yaml (check dts):
代码语言:javascript复制sudo apt-get install libyaml-dev
(3)确保 SDK 环境变量生效:
代码语言:javascript复制source STM32MP15-Ecosystem-v3.1.0/Developer-Package/SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
2.2. 内核源代码打 patch
代码语言:javascript复制cd linux-5.10.61/
for p in `ls -1 ../*.patch`; do patch -p1 < $p; done
2.3. 源码配置
方式:配置编译目录 (different of kernel source code directory)
创建 build 目录:
代码语言:javascript复制mkdir -p ../build
生成默认配置文件.config:
代码语言:javascript复制make ARCH=arm O="$PWD/../build" multi_v7_defconfig fragment*.config
循环应用 fragment*.config
文件(搞不懂干啥的,执行了之后编译会出错,所以不要执行):
for f in `ls -1 ../fragment*.config`; do scripts/kconfig/merge_config.sh -m -r -O $PWD/../build $PWD/../build/.config $f; done
yes '' | make ARCH=arm oldconfig
2.4. 编译源码
编译内核:
代码语言:javascript复制make ARCH=arm uImage vmlinux dtbs LOADADDR=0xC2000040 O="$PWD/../build"
编译完成:
编译完成之后,在上一级目录的 build/arch/arm/boot 目录下可以看到编译出的镜像:
在 dts 目录下可以看到编译出的设备树:
2.5. 编译模块
代码语言:javascript复制make ARCH=arm modules O="$PWD/../build"
3. 烧写
sdb4 分区是 ext4 文件系统,所以将之前使用的 SD 卡插入后,需要将该文件系统挂载:
代码语言:javascript复制sudo mkdir -p /mnt/bootfs
sudo mount /dev/sdb4 /mnt/bootfs/
挂载后查看其中内容,存放了 Linux 内核镜像、设备树等:
进入到内核编译目录,将之前内核编译出的镜像和设备树拷贝替换:
代码语言:javascript复制sudo cp -f uImage /mnt/bootfs/
sudo cp -f dts/stm32mp157c-dk2.dtb /mnt/bootfs/
卸载文件系统:
代码语言:javascript复制sudo umount /dev/sdb4
重新将 SD 卡插入到开发板中,查看是否可以正常启动:
参考资料
[1]en.SOURCES-tf-a-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz: https://st.com/content/ccc/resource/technical/sw-updater/firmware2/group0/2b/04/61/eb/4c/83/4d/3d/stm32cube_standard_a7_bsp_components_tf_a/files/SOURCES-tf-a-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz/_jcr_content/translations/en.SOURCES-tf-a-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz
[2]en.SOURCES-u-boot-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz: https://st.com/content/ccc/resource/technical/sw-updater/firmware2/group0/ce/a3/5c/9e/0d/55/4c/43/stm32cube_Standard_A7_BSP_components_u-boot/files/SOURCES-u-boot-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz/_jcr_content/translations/en.SOURCES-u-boot-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz
[3]en.SOURCES-kernel-stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17.tar.xz: https://st.com/content/ccc/resource/technical/sw-updater/firmware2/group0/78/11/85/59/c4/22/46/41/STM32cube_Standard_A7_BSP_components_kernel/files/SOURCES-kernel-stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17.tar.xz/_jcr_content/translations/en.SOURCES-kernel-stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17.tar.xz