一、编译uboot

1. 获取uboot源码(2020.10版本)

下载链接:​​en.SOURCES-u-boot-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar.xz​

下载后解压:

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文件:

STM32MP157开发笔记 | 02 - uboot和linux内核编译_lua

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

The FIP artifacts directory is named FIP_artifacts:

FIP_artifacts
├── arm-trusted-firmware
│ ├── bl32
│ │ ├── stm32mp157a-dk1-bl32.dtb Device tree for TF-A → STM32MP15 Discovery kits
│ │ ├── stm32mp157a-ev1-bl32.dtb Device tree for TF-A → STM32MP15 Evaluation boards
│ │ ├── stm32mp157c-dk2-bl32.dtb Device tree for TF-A → STM32MP15 Discovery kits
│ │ ├── stm32mp157c-ed1-bl32.dtb Device tree for TF-A → STM32MP15 Evaluation boards
│ │ ├── stm32mp157c-ev1-bl32.dtb Device tree for TF-A → STM32MP15 Evaluation boards
│ │ ├── stm32mp157d-dk1-bl32.dtb Device tree for TF-A → STM32MP15 Discovery kits
│ │ ├── stm32mp157d-ev1-bl32.dtb Device tree for TF-A → STM32MP15 Evaluation boards
│ │ ├── stm32mp157f-dk2-bl32.dtb Device tree for TF-A → STM32MP15 Discovery kits
│ │ ├── stm32mp157f-ed1-bl32.dtb Device tree for TF-A → STM32MP15 Evaluation boards
│ │ ├── stm32mp157f-ev1-bl32.dtb Device tree for TF-A → STM32MP15 Evaluation boards
│ │ └── tf-a-bl32-stm32mp15.bin Binary file for bl32 stage
│ └── fwconfig
│ ├── stm32mp157a-dk1-fw-config-optee.dtb Device tree for FW config → STM32MP15 Discovery kits
│ ├── stm32mp157a-dk1-fw-config-trusted.dtb Device tree for FW config → STM32MP15 Discovery kits
│ ├── stm32mp157a-ev1-fw-config-optee.dtb Device tree for FW config → Evaluation boards
│ ├── stm32mp157a-ev1-fw-config-trusted.dtb Device tree for FW config → Evaluation boards
│ ├── stm32mp157c-dk2-fw-config-optee.dtb Device tree for FW config → STM32MP15 Discovery kits
│ ├── stm32mp157c-dk2-fw-config-trusted.dtb Device tree for FW config → STM32MP15 Discovery kits
│ ├── stm32mp157c-ed1-fw-config-optee.dtb Device tree for FW config → Evaluation boards
│ ├── stm32mp157c-ed1-fw-config-trusted.dtb Device tree for FW config → Evaluation boards
│ ├── stm32mp157c-ev1-fw-config-optee.dtb Device tree for FW config → Evaluation boards
│ ├── stm32mp157c-ev1-fw-config-trusted.dtb Device tree for FW config → Evaluation boards
│ ├── stm32mp157d-dk1-fw-config-optee.dtb Device tree for FW config → STM32MP15 Discovery kits
│ ├── stm32mp157d-dk1-fw-config-trusted.dtb Device tree for FW config → STM32MP15 Discovery kits
│ ├── stm32mp157d-ev1-fw-config-optee.dtb Device tree for FW config → Evaluation boards
│ ├── stm32mp157d-ev1-fw-config-trusted.dtb Device tree for FW config → Evaluation boards
│ ├── stm32mp157f-dk2-fw-config-optee.dtb Device tree for FW config → STM32MP15 Discovery kits
│ ├── stm32mp157f-dk2-fw-config-trusted.dtb Device tree for FW config → STM32MP15 Discovery kits
│ ├── stm32mp157f-ed1-fw-config-optee.dtb Device tree for FW config → Evaluation boards
│ ├── stm32mp157f-ed1-fw-config-trusted.dtb Device tree for FW config → Evaluation boards
│ ├── stm32mp157f-ev1-fw-config-optee.dtb Device tree for FW config → Evaluation boards
│ └── stm32mp157f-ev1-fw-config-trusted.dtb Device tree for FW config → Evaluation boards
├── optee
│ ├── tee-header_v2-stm32mp157a-dk1.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-header_v2-stm32mp157a-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-header_v2-stm32mp157c-dk2.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-header_v2-stm32mp157c-ed1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-header_v2-stm32mp157c-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-header_v2-stm32mp157d-dk1.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-header_v2-stm32mp157d-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-header_v2-stm32mp157f-dk2.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-header_v2-stm32mp157f-ed1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-header_v2-stm32mp157f-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-pageable_v2-stm32mp157a-dk1.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-pageable_v2-stm32mp157a-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-pageable_v2-stm32mp157c-dk2.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-pageable_v2-stm32mp157c-ed1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-pageable_v2-stm32mp157c-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-pageable_v2-stm32mp157d-dk1.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-pageable_v2-stm32mp157d-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-pageable_v2-stm32mp157f-dk2.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-pageable_v2-stm32mp157f-ed1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-pageable_v2-stm32mp157f-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-pager_v2-stm32mp157a-dk1.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-pager_v2-stm32mp157a-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-pager_v2-stm32mp157c-dk2.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-pager_v2-stm32mp157c-ed1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-pager_v2-stm32mp157c-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-pager_v2-stm32mp157d-dk1.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-pager_v2-stm32mp157d-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ ├── tee-pager_v2-stm32mp157f-dk2.bin Binary file for OP-TEE OS → STM32MP15 Discovery kits
│ ├── tee-pager_v2-stm32mp157f-ed1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
│ └── tee-pager_v2-stm32mp157f-ev1.bin Binary file for OP-TEE OS → STM32MP15 Evaluation boards
├── 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. 编译前的准备

(1)OpenSTLinux SDK 必须安装;

(2)编译内核需要安装的包:

llibncurses、libncursesw dev package、libyaml-dev:

sudo apt-get install libncurses5-dev libncursesw5-dev libyaml-dev

(3)确保SDK环境变量生效:

source STM32MP15-Ecosystem-v3.1.0/Developer-Package/SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi

2. 2. uboot源码打patch

cd u-boot-stm32mp-v2020.10-stm32mp-r2/
for p in `ls -1 ../*.patch`; do patch -p1 < $p; done

2.3. 编译uboot

配置普通启动版本:

make stm32mp15_basic_defconfig

编译:

配置编译DK2板设备树:

make DEVICE_TREE=stm32mp157c-dk2 all

编译完成:

STM32MP157开发笔记 | 02 - uboot和linux内核编译_stm32mp157_02

二、编译内核

1. 获取内核源码

下载链接:​​en.SOURCES-kernel-stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17.tar.xz​

下载后解压:

tar xvf en.SOURCES-kernel-stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17.tar.xz

里面分为源码和patch文件:

STM32MP157开发笔记 | 02 - uboot和linux内核编译_stm32mp157_03

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

解压源码:

tar xvf linux-5.10.61.tar.xz

2. 编译kernel

参考 ​​README.HOW_TO.txt​​ 文档。

2.1. 编译前的准备

(1)OpenSTLinux SDK 必须安装;

(2)编译内核需要安装的包:

llibncurses、libncursesw dev package、libyaml-dev:

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"

编译完成:

STM32MP157开发笔记 | 02 - uboot和linux内核编译_stm32mp157_04

编译模块:

make ARCH=arm modules O="$PWD/../build"