STM32MP157 linux5.15移植

STM32MP157 linux5.15移植

  • 1. 初次编译
  • 2. 移植
    • 2.1 添加自己的板子
    • 2.2 修改设备树
  • 3. 编译下载
    • 3.1 编译
    • 3.2 制作bootfs
    • 3.2 下载
  • 4. 总结

参考母板是STM32MP157D-DK1开发板,移植开发板为100ASK_STM32MP157_V11。

  1. STM32MP157 tf-a2.6 optee3.16 u-boot2021.10 linux5.15移植
  2. STM32MP157启动流程
  3. STM32MP157 tf-a2.6移植](http://t.csdn.cn/RsUmv)
  4. STM32MP157 optee3.16移植](http://t.csdn.cn/qXDNU)
  5. STM32MP157 u-boot2021.10移植
  6. STM32MP157 linux5.15移植
  7. STM32MP157 buildroot-2022.02.5构建根文件系统

1. 初次编译

解压源码,并打补丁。可以参考README.HOW_TO.txt文件,里面说了怎么解压和打补丁,并且还说了如何编译。

#解压源码
$ tar -xvf linux-5.15.24.tar.xz
#进入源码目录
$ cd linux-5.15.24/
#打补丁
$ for p in `ls -1 ../*.patch`; do patch -p1 < $p; done

执行下列命令完成初次编译,O="$PWD/../build"是指定编译的输出目录。每次配置完需要令保存自己的配置(我的配置已保存在arch/arm/configs/stm32mp157d_100ask_defconfig中),防止丢失。

#设置编译器
$ source ../../../../toolchain/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
#配置
$ make ARCH=arm O="$PWD/../build" multi_v7_defconfig 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
#进入编译目录
$ cd ../build/
#配置
$ make menuconfig
#编译uImage vmlinux dtbs modules
$ make ARCH=arm uImage vmlinux dtbs modules LOADADDR=0xC2000040 -j12

2. 移植

2.1 添加自己的板子

复制U-Boot源码下的stm32mp157d-100ask.dtsstm32mp15xx-100ask.dtsi设备树到Linux源码目录下的arch/arm/boot/dts目录中,修改设备树目录下的Makefile。

//dtb-$(CONFIG_ARCH_STM32)变量后追加stm32mp157d-100ask
dtb-$(CONFIG_ARCH_STM32) += \
	stm32f429-disco.dtb \
	stm32f469-disco.dtb \
	stm32f746-disco.dtb \
	// 此处代码已省略
	stm32mp157c-lxa-mc1.dtb \
	stm32mp157c-odyssey.dtb \
	stm32mp157d-100ask.dtb

2.2 修改设备树

复制U-Boot的设备树无需做修改,只有网络需要简单调整。将qca,clk-out-frequency = <125000000>; qca,keep-pll-enabled;两个属性移到phy节点中。

&ethernet0 {
	status = "okay";
	pinctrl-0 = <&ethernet0_rgmii_pins_a>;
	pinctrl-1 = <&ethernet0_rgmii_sleep_pins_a>;
	pinctrl-names = "default", "sleep";
	phy-mode = "rgmii-id";
	max-speed = <1000>;
	phy-handle = <&phy0>;
	nvmem-cells = <&ethernet_mac_address>;
	nvmem-cell-names = "mac-address";

	//qca,clk-out-frequency = <125000000>;
	//qca,keep-pll-enabled;

	mdio0 {
		#address-cells = <1>;
		#size-cells = <0>;
		compatible = "snps,dwmac-mdio";
		phy0: ethernet-phy@6 {
			reg = <6>;
			reset-gpios = <&gpiog 0 GPIO_ACTIVE_LOW>;
			reset-assert-us = <2000>;
			reset-deassert-us = <2000>;

			//添加到这里
			qca,clk-out-frequency = <125000000>; 
			qca,keep-pll-enabled;
		};
	};
};

3. 编译下载

3.1 编译

执行编译命令,进行编译。

$ make ARCH=arm uImage vmlinux dtbs modules LOADADDR=0xC2000040 -j12

3.2 制作bootfs

进入FIP_artifacts目录,执行下列命令制作bootfs。

$ mkdir boot
$ dd if=/dev/zero of=bootfs.ext4 bs=1M count=16
$ mkfs.ext4 -L bootfs bootfs.ext4
$ sudo mount bootfs.ext4 boot
$ sudo cp -f ../linux-stm32mp-5.15.24-stm32mp1-r1-r0/build/arch/arm/boot/uImage boot/
$ sudo cp -f ../linux-stm32mp-5.15.24-stm32mp1-r1-r0/build/arch/arm/boot/dts/stm32mp157d-100ask.dtb boot/
$ sudo umount boot

3.2 下载

选择一个脚本进行烧写,并设置好拨码开关启动。

#EMMC烧写脚本FlashLayout_emmc_stm32mp157d-100ask-trusted.tsv
#Opt	Id		Name		Type		IP		Offset		Binary
-		0x01	fsbl-boot	Binary		none	0x0			arm-trusted-firmware/tf-a-stm32mp157d-100ask-usb.stm32
-		0x03	fip-boot	FIP			none	0x0			fip/fip-stm32mp157d-100ask-trusted.bin
P		0x04	fsbl1		Binary		mmc1	boot1		arm-trusted-firmware/tf-a-stm32mp157d-100ask-emmc.stm32
P		0x05	fsbl2		Binary		mmc1	boot2		arm-trusted-firmware/tf-a-stm32mp157d-100ask-emmc.stm32
P		0x06	metadata1	Binary		mmc1	0x00080000	arm-trusted-firmware/metadata.bin
P		0x07	metadata2	Binary		mmc1	0x00100000	arm-trusted-firmware/metadata.bin
P		0x08	fip-a		FIP			mmc1	0x00180000	fip/fip-stm32mp157d-100ask-trusted.bin
PED		0x09	fip-b		FIP			mmc1	0x00580000	none
PED		0x0A	u-boot-env	Binary		mmc1	0x00980000	none
P		0x10	bootfs		System		mmc1	0x00A00000	bootfs.ext4

#EMMC烧写脚本FlashLayout_emmc_stm32mp157d-100ask-optee.tsv
#Opt	Id		Name		Type		IP		Offset		Binary
-		0x01	fsbl-boot	Binary		none	0x0			arm-trusted-firmware/tf-a-stm32mp157d-100ask-usb.stm32
-		0x03	fip-boot	FIP			none	0x0			fip/fip-stm32mp157d-100ask-optee.bin
P		0x04	fsbl1		Binary		mmc1	boot1		arm-trusted-firmware/tf-a-stm32mp157d-100ask-emmc.stm32
P		0x05	fsbl2		Binary		mmc1	boot2		arm-trusted-firmware/tf-a-stm32mp157d-100ask-emmc.stm32
P		0x06	metadata1	Binary		mmc1	0x00080000	arm-trusted-firmware/metadata.bin
P		0x07	metadata2	Binary		mmc1	0x00100000	arm-trusted-firmware/metadata.bin
P		0x08	fip-a		FIP			mmc1	0x00180000	fip/fip-stm32mp157d-100ask-optee.bin
PED		0x09	fip-b		FIP			mmc1	0x00580000	none
PED		0x0A	u-boot-env	Binary		mmc1	0x00980000	none
P		0x10	bootfs		System		mmc1	0x00A00000	bootfs.ext4

#SD卡烧写脚本FlashLayout_sdcard_stm32mp157d-100ask-trusted.tsv
#Opt	Id		Name		Type		IP		Offset		Binary
-		0x01	fsbl-boot	Binary		none	0x0			arm-trusted-firmware/tf-a-stm32mp157d-100ask-usb.stm32
-		0x03	fip-boot	FIP			none	0x0			fip/fip-stm32mp157d-100ask-trusted.bin
P		0x04	fsbl1		Binary		mmc0	0x00004400	arm-trusted-firmware/tf-a-stm32mp157d-100ask-sdcard.stm32
P		0x05	fsbl2		Binary		mmc0	0x00044400	arm-trusted-firmware/tf-a-stm32mp157d-100ask-sdcard.stm32
P		0x06	metadata1	Binary		mmc0	0x00084400	arm-trusted-firmware/metadata.bin
P		0x07	metadata2	Binary		mmc0	0x000C4400	arm-trusted-firmware/metadata.bin
P		0x08	fip-a		FIP			mmc0	0x00104400	fip/fip-stm32mp157d-100ask-trusted.bin
PED		0x09	fip-b		FIP			mmc0	0x00504400	none
PED		0x0A	u-boot-env	Binary		mmc0	0x00904400	none
P		0x10	bootfs		System		mmc0	0x00984400	bootfs.ext4

#SD卡烧写脚本FlashLayout_sdcard_stm32mp157d-100ask-optee.tsv
#Opt	Id		Name		Type		IP		Offset		Binary
-		0x01	fsbl-boot	Binary		none	0x0			arm-trusted-firmware/tf-a-stm32mp157d-100ask-usb.stm32
-		0x03	fip-boot	FIP			none	0x0			fip/fip-stm32mp157d-100ask-optee.bin
P		0x04	fsbl1		Binary		mmc0	0x00004400	arm-trusted-firmware/tf-a-stm32mp157d-100ask-sdcard.stm32
P		0x05	fsbl2		Binary		mmc0	0x00044400	arm-trusted-firmware/tf-a-stm32mp157d-100ask-sdcard.stm32
P		0x06	metadata1	Binary		mmc0	0x00084400	arm-trusted-firmware/metadata.bin
P		0x07	metadata2	Binary		mmc0	0x000C4400	arm-trusted-firmware/metadata.bin
P		0x08	fip-a		FIP			mmc0	0x00104400	fip/fip-stm32mp157d-100ask-optee.bin
PED		0x09	fip-b		FIP			mmc0	0x00504400	none
PED		0x0A	u-boot-env	Binary		mmc0	0x00904400	none
P		0x10	bootfs		System		mmc0	0x00984400	bootfs.ext4

进入U-Boot命令行,mmc dev 0设置mmc设备(0是SD卡,1是EMMC),mmc part查看分区表。
STM32MP157 linux5.15移植_第1张图片
STM32MP157 linux5.15移植_第2张图片
根据分区表设置bootcmd,saveenv保存环境变量并重启。

#SD卡设置
setenv bootcmd 'ext4load mmc 0:8 c2000000 uImage; ext4load mmc 0:8 c4000000 stm32mp157d-100ask.dtb; bootm c2000000 - c4000000'
#EMMC设置
setenv bootcmd 'ext4load mmc 1:6 c2000000 uImage; ext4load mmc 1:6 c4000000 stm32mp157d-100ask.dtb; bootm c2000000 - c4000000'

内核正常启动,无法挂载跟文件系统,内核给出了警告。
STM32MP157 linux5.15移植_第3张图片

4. 总结

因为没有根文件系统,无法充分验证移植的正确性,下一篇文章我会利用Buildroot构建一个简单的根文件系统。这些代码只启动板子,其他功能问题并没有解决。

学习笔记仅供参考,欢迎指正错误,如有侵权请及时联系。
移植源码地址:https://pan.baidu.com/s/19PvQ9K2D4qQ_dqikRYTWrA
提取码:1234

你可能感兴趣的:(STM32MP157,stm32,arm,linux)