本文主要是介绍(二)正点原子STM32MP135移植——TF-A移植,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
一、TF-A概述
二、编译官方代码
2.1 解压源码
2.2 打补丁
2.3 编译准备
(1)修改Makfile.sdk
(2)设置环境变量
(3)编译
三、移植
3.1 复制官方文件
3.2 修改电源
3.3 修改TF卡和emmc
3.4 添加clk_hse
3.5 删除其他串口
3.6 修改引脚
四、编译
一、TF-A概述
总而言之,和安全相关,篇幅受限,不做详细介绍,可以参考其他博主的帖子,本帖只做移植教程
二、编译官方代码
2.1 解压源码
这里面有一个压缩包,把它解压可以得到源码,根据版本不同,不要照搬,只要能解压出来就行
tar xf tf-a-stm32mp-v2.8.6-stm32mp-r1-r0.tar.xz
特别注意:有一个README.HOW_TO.txt这是官方写给我们的使用文档,完全可以按照里面的方法去编译
2.2 打补丁
官方的源码还是不能编译的,要先打补丁!!!
先进入到源码目录,就是上一步解压出来的文件夹
cd tf-a-stm32mp-v2.8.6-stm32mp-r1-r0.tar.xz
for p in `ls -1 ../*.patch`; do patch -p1 < $p; done
2.3 编译准备
(1)修改Makfile.sdk
编译源码不使用源码目录下的Makefile,使用上一级目录的Makefile.sdk,先对他进行修改。
DEPLOYDIR ?= $(SRC_PATH)/../../FIP_artifacts/arm-trusted-firmware
Makefile.sdk第4行,把DEPLOYDIR目录指向FIP_artifacts下的arm-trusted-firmware,这样编译出来的文件会直接输出到arm-trusted-firmware文件夹,方便后面fiptool打包
TF_A_DEVICETREE ?= stm32mp135f-dk
Makefile.sdk第19行,把其他设备树都给删了,只留下135的板子,之后添加自己板子的时候也要在这里添加
(2)设置环境变量
打开一个终端,之后就不要关闭它了!!!
终端要在源码目录下打开,源码!
source /opt/st/stm32mp1/4.2.1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabiexport FIP_DEPLOYDIR_ROOT=$PWD/../../FIP_artifacts
source是要用arm-ostl-linux-gnueabi这个交叉编译器
export是设置FIP的目录,绝对路径或者相对路径都可以,可能写到Makefile.sdk里也可以,可以写一个sh脚本,不用每次都加载这个环境。
注意:笔者交叉编译器安装路径直接默认了,大家安装的时候记得路径记一下
(3)编译
make -f ../Makefile.sdk all
最后提示 Missing u-boot-stm32mp135f-dk.dtb file in folder: '$FIP_DEPLOYDIR_UBOOT' or '$FIP_DEPLOYDIR_ROOT/u-boot'
没有关系,别在意这个,这是因为Makefile.sdk里自动调用fiptool给我们打包了,但是现在又还没有编译u-boot和optee,所以会报这个
最后会在FIP_artifacts/arm-trusted-fimware里生成如下:
1. tf-a-stm32mp135f-dk-emmc.stm32
2. tf-a-stm32mp135f-dk-usb.stm32
3. tf-a-stm32mp135f-dk-uart.stm32
4. ...(这几个都是.stm32文件,不列了
n. metadata.bin
n+1. fwconfig/stm32mp135f-dk-fw-config-optee.dtb
三、移植
修改头文件引用
#include "stm32mp13-pinctrl-atk.dtsi"
3.1 复制官方文件
cd fdts/
cp stm32mp135f-dk.dts stm32mp135-atk.dts
cp stm32mp13-pinctrl.dtsi stm32mp13-pinctrl-atk.dtsi
cp stm32mp135f-dk-fw-config.dts stm32mp135-atk-fw-config.dts
cd ..
3.2 修改电源
最重要的部分就是修改电源配置,ST官方使用的是电源管理芯片,而正点原子考虑成本因素使用分立电源的设计。
打开stm32mp135-atk.dts文件,第67行开始的代码,这一部分的代码全部删了,是ST官方关于电源的描述
&i2c4 {pinctrl-names = "default";pinctrl-0 = <&i2c4_pins_a>;i2c-scl-rising-time-ns = <185>;i2c-scl-falling-time-ns = <20>;clock-frequency = <400000>;status = "okay";pmic: stpmic@33 {compatible = "st,stpmic1";reg = <0x33>;status = "okay";regulators {compatible = "st,stpmic1-regulators";buck1-supply = <&vin>;buck2-supply = <&vin>;buck3-supply = <&vin>;buck4-supply = <&vin>;ldo1-supply = <&vin>;ldo4-supply = <&vin>;ldo5-supply = <&vin>;ldo6-supply = <&vin>;vref_ddr-supply = <&vin>;pwr_sw1-supply = <&bst_out>;pwr_sw2-supply = <&v3v3_ao>;vddcpu: buck1 {regulator-name = "vddcpu";regulator-min-microvolt = <1250000>;regulator-max-microvolt = <1250000>;regulator-always-on;regulator-over-current-protection;};vdd_ddr: buck2 {regulator-name = "vdd_ddr";regulator-min-microvolt = <1350000>;regulator-max-microvolt = <1350000>;regulator-always-on;regulator-over-current-protection;};vdd: buck3 {regulator-name = "vdd";regulator-min-microvolt = <3300000>;regulator-max-microvolt = <3300000>;regulator-always-on;st,mask-reset;regulator-over-current-protection;};vddcore: buck4 {regulator-name = "vddcore";regulator-min-microvolt = <1250000>;regulator-max-microvolt = <1250000>;regulator-always-on;regulator-over-current-protection;};vdd_adc: ldo1 {regulator-name = "vdd_adc";regulator-min-microvolt = <3300000>;regulator-max-microvolt = <3300000>;};vdd_usb: ldo4 {regulator-name = "vdd_usb";regulator-min-microvolt = <3300000>;regulator-max-microvolt = <3300000>;};vdd_sd: ldo5 {regulator-name = "vdd_sd";regulator-min-microvolt = <3300000>;regulator-max-microvolt = <3300000>;regulator-boot-on;};v1v8_periph: ldo6 {regulator-name = "v1v8_periph";regulator-min-microvolt = <1800000>;regulator-max-microvolt = <1800000>;};vref_ddr: vref_ddr {regulator-name = "vref_ddr";regulator-always-on;};bst_out: boost {regulator-name = "bst_out";};v3v3_sw: pwr_sw2 {regulator-name = "v3v3_sw";regulator-active-discharge = <1>;regulator-always-on;};};};
};
然后在第49行代码之后,补上我们对电源的描述↓↓
vddcore: regulator-vddcore {compatible = "regulator-fixed";regulator-name = "vddcore";regulator-min-microvolt = <1250000>;regulator-max-microvolt = <1250000>;regulator-off-in-suspend;regulator-always-on;};vddcpu: regulator-vddcpu {compatible = "regulator-fixed";regulator-name = "vddcpu";regulator-min-microvolt = <1350000>;regulator-max-microvolt = <1350000>;regulator-off-in-suspend;regulator-always-on;};v3v3: regulator-v3v3 {compatible = "regulator-fixed";regulator-name = "v3v3";regulator-min-microvolt = <3300000>;regulator-max-microvolt = <3300000>;regulator-off-in-suspend;regulator-always-on;};vdd: regulator-vdd {compatible = "regulator-fixed";regulator-name = "vdd";regulator-min-microvolt = <3300000>;regulator-max-microvolt = <3300000>;regulator-off-in-suspend;regulator-always-on;};vdd_usb: regulator-vdd-usb {compatible = "regulator-fixed";regulator-name = "vdd_usb";regulator-min-microvolt = <3300000>;regulator-max-microvolt = <3300000>;regulator-off-in-suspend;regulator-always-on;};
这里有一个天坑!!!天真的我以为改了设备树就好了,如果就这么改,压根跑不起来,烧录的时候卡死在第一步
找了全网,只找到一个帖子提到了,我们添加了电源描述之后,还要去一个文件里修改电源描述的数量。
在plat\st\stm32mp1下的stm32mp1_def.h里,第695行有一个
#define PLAT_NB_FIXED_REGUS U(6)
/* 把它改成电源描述数量+1 */
3.3 修改TF卡和emmc
找到sdmmc1这个节点(就在stm32mp135-atk.dts下),删掉它,替换成我们的
&sdmmc1 {pinctrl-names = "default";pinctrl-0 = <&sdmmc1_b4_pins_a &sdmmc1_clk_pins_a>;disable-wp;st,neg-edge;no-1-8-v;bus-width = <4>;vmmc-supply = <&v3v3>;status = "okay";
};&sdmmc2 {pinctrl-names = "default";pinctrl-0 = <&sdmmc2_b4_pins_a &sdmmc2_b4_b7_pins_a &sdmmc2_clk_pins_a>;non-removable;st,neg-edge;mmc-ddr-3_3v;no-1-8-v;bus-width = <8>;vmmc-supply = <&v3v3>;vqmmc-supply = <&v3v3>;status = "okay";
};
3.4 添加clk_hse
在末尾添加一个节点
&clk_hse {st,digbypass;
};
3.5 删除其他串口
ST官方板子有uart1和uart8,我们把它删掉,只留下uart4
aliases {serial0 = &uart4;serial1 = &usart1;// serial2 = &uart8;// serial3 = &usart2;};
&uart8 {pinctrl-names = "default";pinctrl-0 = <&uart8_pins_a>;status = "disabled";
};&usart1 {pinctrl-names = "default";pinctrl-0 = <&usart1_pins_a>;uart-has-rtscts;status = "disabled";
};
然后打开stm32mp13-bl2.dtsi文件,我们把对应删了的引脚也给删掉
// /omit-if-no-ref/ &i2c4_pins_a;
/omit-if-no-ref/ &sdmmc1_b4_pins_a;
/omit-if-no-ref/ &sdmmc1_clk_pins_a;
/omit-if-no-ref/ &sdmmc2_b4_pins_a;
/omit-if-no-ref/ &sdmmc2_clk_pins_a;
/omit-if-no-ref/ &uart4_pins_a;
// /omit-if-no-ref/ &uart8_pins_a;
// /omit-if-no-ref/ &usart1_pins_a;
3.6 修改引脚
切换到stm32mp13-pinctrl-atk.dtsi文件,这里为了方便,直接复制了原子的文件,也可以对照着修改,笔者直接用原子的文件替换掉了,代码如下
// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/** Copyright (C) STMicroelectronics 2019 - All Rights Reserved* Author: Alexandre Torgue <alexandre.torgue@st.com>*/
#include <dt-bindings/pinctrl/stm32-pinfunc.h>&pinctrl {sdmmc1_b4_pins_a: sdmmc1-b4-0 {pins {pinmux = <STM32_PINMUX('C', 8, AF12)>, /* SDMMC1_D0 */<STM32_PINMUX('C', 9, AF12)>, /* SDMMC1_D1 */<STM32_PINMUX('C', 10, AF12)>, /* SDMMC1_D2 */<STM32_PINMUX('C', 11, AF12)>, /* SDMMC1_D3 */<STM32_PINMUX('D', 2, AF12)>; /* SDMMC1_CMD */slew-rate = <1>;drive-push-pull;bias-disable;};};sdmmc1_clk_pins_a: sdmmc1-clk-0 {pins {pinmux = <STM32_PINMUX('C', 12, AF12)>; /* SDMMC1_CK */slew-rate = <1>;drive-push-pull;bias-disable;};};sdmmc2_b4_pins_a: sdmmc2-b4-0 {pins {pinmux = <STM32_PINMUX('B', 14, AF10)>, /* SDMMC2_D0 */<STM32_PINMUX('B', 15, AF10)>, /* SDMMC2_D1 */<STM32_PINMUX('B', 3, AF10)>, /* SDMMC2_D2 */<STM32_PINMUX('B', 4, AF10)>, /* SDMMC2_D3 */<STM32_PINMUX('G', 6, AF10)>; /* SDMMC2_CMD */slew-rate = <1>;drive-push-pull;bias-pull-up;};};sdmmc2_b4_b7_pins_a: sdmmc2-b4-b7-0 {pins {pinmux = <STM32_PINMUX('F', 0, AF10)>, /* SDMMC2_D4 */<STM32_PINMUX('B', 9, AF10)>, /* SDMMC2_D5 */<STM32_PINMUX('C', 6, AF10)>, /* SDMMC2_D6 */ <STM32_PINMUX('C', 7, AF10)>; /* SDMMC2_D7 */slew-rate = <1>;drive-push-pull;bias-pull-up;};};sdmmc2_clk_pins_a: sdmmc2-clk-0 {pins {pinmux = <STM32_PINMUX('E', 3, AF10)>; /* SDMMC2_CK */slew-rate = <1>;drive-push-pull;bias-pull-up;};};uart4_pins_a: uart4-0 {pins1 {pinmux = <STM32_PINMUX('D', 6, AF8)>; /* UART4_TX */bias-disable;drive-push-pull;slew-rate = <0>;};pins2 {pinmux = <STM32_PINMUX('D', 8, AF8)>; /* UART4_RX */bias-pull-up;};};
};
四、编译
先去Makefile.sdk里面,把设备树修改成我们的板子
还记得刚才打开没关闭的终端吗?如果关了,那就要重新设置环境变量了哦!回到2.3节的第二步,重新把环境变量设置好,然后编译
make -f ../Makefile.sdk all
可以看到FIP_artifacts/arm_trusted_firmware文件夹里多了几个文件
这篇关于(二)正点原子STM32MP135移植——TF-A移植的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!