一、编译 tf-a
下载链接:en.SOURCES-tf-a-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz[1]。
下载后解压:
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
解压后包含源码和补丁文件:

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
除了 TF-A 源码之外,在上一级目录下,还有 FIP_artifacts 目录如下:
FIP_artifacts ├── arm-trusted-firmware │ ├── bl32 │ └── fwconfig
(1)OpenSTLinux SDK 必须安装;
(2)编译内核需要安装的包:
sudo apt-get install libncurses5-dev libncursesw5-dev libyaml-dev
(3)确保 SDK 环境变量生效(注意路径):
source $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v3.1.0/Developer-Package/SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
接下来开始编译。
解压源码:
tar -zxvf tf-a-stm32mp-v2.4-stm32mp-r2-r0.tar.gz
源码打补丁:
cd tf-a-stm32mp-v2.4-stm32mp-r2 for p in `ls -1 ../*.patch`; do patch -p1 < $p; done
因为在 OpenSTLinux 默认激活了 FIP,所以在编译前必须要指定 FIP_artifacts:
export FIP_DEPLOYDIR_ROOT=$PWD/../../FIP_artifacts
编译全部:
make -f $PWD/../Makefile.sdk all
编译出的结果在上级目录的 deploy 文件夹:

使用第一篇文章中烧写成功过的 SD 卡,只替换 FSBL 进行验证:
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
下载链接:en.SOURCES-u-boot-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz[2]
下载后解压:
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
解压后包含源码和补丁文件:

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
解压源码:
tar -zxvf u-boot-stm32mp-v2020.10-stm32mp-r2-r0.tar.gz
除了 uboot 源码之外,在上一级目录下,还有 FIP_artifacts 目录如下:
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.1. uboot 源码打 patch
cd u-boot-stm32mp-v2020.10-stm32mp-r2 for p in `ls -1 ../*.patch`; do patch -p1 < $p; done
2.2. 编译 uboot(带 FIP)
指定 FIP 文件夹路径:
export FIP_DEPLOYDIR_ROOT=$PWD/../../FIP_artifacts
编译全部:
make -f $PWD/../Makefile.sdk all
编译出来之后,需要部署的文件在上一级目录 deploy 中:

同时,编译出的 FIP 文件在上一级目录 FIP_artifacts 中:

使用第一篇文章中烧写成功过的 SD 卡,只替换 FIP 进行验证:
sudo dd if=fip-stm32mp157c-dk2-trusted.bin of=/dev/sdb3 conv=fdatasync
将 SD 卡重新插入 STM32MP157C-DK2 开发板,可以正常启动,查看串口日志,u-boot 编译时间已修改:

三、编译内核
下载链接:en.SOURCES-kernel-stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17.tar.xz[3]
下载后解压:
tar xvf en.SOURCES-kernel-stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17.tar.xz
解压后包含源码和补丁文件:

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
解压源码:
xz -d xvf linux-5.10.61.tar.xz tar xvf linux-5.10.61.tar
2.1. 编译前的准备
(1)OpenSTLinux SDK 必须安装;
(2)编译内核需要安装的包:
sudo apt-get install libncurses5-dev libncursesw5-dev libyaml-dev
mkimage:
sudo apt-get install u-boot-tools
yaml (check dts):
sudo apt-get install libyaml-dev
(3)确保 SDK 环境变量生效:
source STM32MP15-Ecosystem-v3.1.0/Developer-Package/SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
2.2. 内核源代码打 patch
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 目录:
mkdir -p ../build
生成默认配置文件.config:
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. 编译源码
编译内核:
make ARCH=arm uImage vmlinux dtbs LOADADDR=0xC2000040 O="$PWD/../build"
编译完成:

编译完成之后,在上一级目录的 build/arch/arm/boot 目录下可以看到编译出的镜像:

在 dts 目录下可以看到编译出的设备树:

2.5. 编译模块
make ARCH=arm modules O="$PWD/../build"
sdb4 分区是 ext4 文件系统,所以将之前使用的 SD 卡插入后,需要将该文件系统挂载:
sudo mkdir -p /mnt/bootfs sudo mount /dev/sdb4 /mnt/bootfs/
挂载后查看其中内容,存放了 Linux 内核镜像、设备树等:

进入到内核编译目录,将之前内核编译出的镜像和设备树拷贝替换:
sudo cp -f uImage /mnt/bootfs/ sudo cp -f dts/stm32mp157c-dk2.dtb /mnt/bootfs/
卸载文件系统:
sudo umount /dev/sdb4
重新将 SD 卡插入到开发板中,查看是否可以正常启动:

参考资料
[1]en.SOURCES-tf-a-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz: https://www.php.cn/link/6d465fa01e3c983aaf1600556cbfa0c6
[2]en.SOURCES-u-boot-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz: https://www.php.cn/link/24bb26bb300eefd5ecd1373e002d8df5
[3]en.SOURCES-kernel-stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17.tar.xz: https://www.php.cn/link/b4aa16d8d291bc9eef7d9eccc6567683
以上就是stm32mp157开发笔记 | TF-A、uboot、linux内核源码获取、编译、烧写的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号