STM32MP157 u-boot2021.10移植

STM32MP157 u-boot2021.10移植

  • 1. 初次编译
  • 2. 移植
    • 2.1 添加自己的板子
    • 2.2 修改设备树
      • 2.2.1 修改串口Uart
      • 2.2.2 修改时钟
      • 2.2.3 修改电源
      • 2.2.4 修改DDR
      • 2.2.5 删除LCD HDMI和音频
      • 2.2.6 修改EMMC和SD卡
      • 2.2.6 修改USB
      • 2.2.7 修改ethernet
      • 2.2.8 修改LED
  • 3. 编译下载
    • 3.1 编译
    • 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移植
  4. STM32MP157 optee3.16移植
  5. STM32MP157 u-boot2021.10移植
  6. STM32MP157 linux5.15移植
  7. STM32MP157 buildroot-2022.02.5构建根文件系统

1. 初次编译

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

#解压源码
$ tar -xvf u-boot-stm32mp-v2021.10-stm32mp1-r1-r0.tar.xz
#进入源码目录
$ cd u-boot-stm32mp-v2021.10-stm32mp1-r1/
#打补丁
$ for p in `ls -1 ../*.patch`; do patch -p1 < $p; done

执行以下命令完成编译,DEPLOYDIR=$FIP_DEPLOYDIR_ROOT/u-boot是U-Boot编译结果存放的目录,如果不设置就会在上一级产生deploy目录存放编译结果,同级目录下生成的build目录存放编译中间文件。

#设置编译器
$ source ../../../../toolchain/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
#设置FIP目录
$ export FIP_DEPLOYDIR_ROOT=$PWD/../../FIP_artifacts
#编译
$ make -f $PWD/../Makefile.sdk DEPLOYDIR=$FIP_DEPLOYDIR_ROOT/u-boot -j12 all
$ make -f $PWD/../Makefile.sdk -j12 all

因为TF_A和OPTEE我们只编译了参考母板和自己的板子,所以我们删除其他板子。编译还是有错误,没搞懂我们稍加修改,编译通过。但是FIP生成了两次,这是因为UBOOT_CONFIGS += trusted出现了两次,删掉一个即可。
STM32MP157 u-boot2021.10移植_第1张图片

#在86行,deploy-targets变量定义之后添加如下代码,定义fip_devicetree变量
fip_devicetree := $(foreach config, $(if $(UBOOT_CONFIG),$(UBOOT_CONFIG),$(UBOOT_CONFIGS)), \
					$(foreach defconfig, $(if $(UBOOT_DEFCONFIG),$(UBOOT_DEFCONFIG),$(UBOOT_DEFCONFIG_$(config))), $(if $(DEVICETREE),$(DEVICETREE),$(UBOOT_DEVICETREE_$(defconfig)))) \
					)

fip: $(deploy-targets)
	FIP_DEPLOYDIR_UBOOT=$(DEPLOYDIR) FIP_DEVICETREE="$(DEVICETREE)" fiptool-stm32mp
#将上面两行改为
fip: $(deploy-targets)
	FIP_DEPLOYDIR_UBOOT=$(DEPLOYDIR) FIP_DEVICETREE="$(fip_devicetree)" fiptool-stm32mp

2. 移植

2.1 添加自己的板子

执行一下命令完成自己的板子文件的创建

$ cd configs/
$ cp stm32mp15_defconfig stm32mp15_100ask_defconfig
$ cd ../arch/arm/dts/
$ cp stm32mp15xx-dkx.dtsi stm32mp15xx-100ask.dtsi
$ cp stm32mp157d-dk1.dts stm32mp157d-100ask.dts
#因为stm32mp157d-dk1-u-boot.dtsi只包含了stm32mp157a-dk1-u-boot.dtsi
$ cp stm32mp157a-dk1-u-boot.dtsi stm32mp157d-100ask-u-boot.dtsi
$ cp stm32mp15-ddr3-2x4Gb-1066-binG.dtsi stm32mp15-ddr3-2x2Gb-1066-binG.dtsi

修改设备树dts目录的Makefile,添加自己的设备树

//dtb-$(CONFIG_STM32MP15x)变量后追加stm32mp157d-100ask
dtb-$(CONFIG_STM32MP15x) += \
	stm32mp157a-avenger96.dtb \
	stm32mp157a-dk1.dtb \
	stm32mp157a-ed1.dtb \
	stm32mp157a-ev1.dtb \
	stm32mp157a-icore-stm32mp1-ctouch2.dtb \
	stm32mp157a-icore-stm32mp1-edimm2.2.dtb \
	stm32mp157a-microgea-stm32mp1-microdev2.0.dtb \
	stm32mp157a-microgea-stm32mp1-microdev2.0-of7.dtb \
	stm32mp157c-dk2.dtb \
	stm32mp157c-ed1.dtb \
	stm32mp157c-ev1.dtb \
	stm32mp157c-odyssey.dtb \
	stm32mp15xx-dhcom-drc02.dtb \
	stm32mp157d-dk1.dtb \
	stm32mp157d-ed1.dtb \
	stm32mp157d-ev1.dtb \
	stm32mp157f-dk2.dtb \
	stm32mp157f-ed1.dtb \
	stm32mp157f-ev1.dtb \
	stm32mp15xx-dhcom-pdk2.dtb \
	stm32mp15xx-dhcom-picoitx.dtb \
	stm32mp15xx-dhcor-avenger96.dtb \
	stm32mp157d-100ask.dtb

对设备树做简单的修改,修改stm32mp157d-100ask.dts文件

13 #include "stm32mp15xx-dkx.dtsi"
//改为
13 #include "stm32mp15xx-100ask.dtsi"

16 model = "STMicroelectronics STM32MP157D-DK1 Discovery Board";
17 compatible = "st,stm32mp157d-dk1", "st,stm32mp157";
//改为
16 model = "STMicroelectronics STM32MP157D-100ASK Discovery Board";
17 compatible = "st,stm32mp157d-100ask", "st,stm32mp157";

修改stm32mp157d-100ask-u-boot.dtsi文件

8 #include "stm32mp15-ddr3-1x4Gb-1066-binG.dtsi"
//改为
8 #include "stm32mp15-ddr3-2x2Gb-1066-binG.dtsi"

Makefile.sdk文件中添加自己的板子,删除stm32mp13_defconfig添加stm32mp15_100ask_defconfig

UBOOT_CONFIGS += trusted
# Init default config settings
UBOOT_DEFCONFIG_trusted += stm32mp15_defconfig
UBOOT_BINARY_stm32mp15_defconfig ?= u-boot.dtb
UBOOT_DEVICETREE_stm32mp15_defconfig ?=  stm32mp157d-dk1
# Init default config settings
UBOOT_DEFCONFIG_trusted += stm32mp15_100ask_defconfig
UBOOT_BINARY_stm32mp15_100ask_defconfig ?= u-boot.dtb
UBOOT_DEVICETREE_stm32mp15_100ask_defconfig ?=  stm32mp157d-100ask

编译生成了u-boot-stm32mp157d-100ask-trusted.dtb文件
在这里插入图片描述

2.2 修改设备树

U-Boot的SPL和TF-A的功能有重合,所以有一部分设备树是一样的。ST并没有使用U-Boot的SPL,和SPL相关的有些设备树不做修改也不影响,比如内存。这里我都做了修改,因为我也不知道具体哪些可以不改,stm32mp157d-100ask-u-boot.dtsi文件中基本是和SPL相关的。这篇文章的目的是启动Linux内核,所以LCD、HDMI和音频等驱动不会实现,但是会实现type-c和网络方便下载和调试。

2.2.1 修改串口Uart

100ASK_STM32MP157_V11开发板的串口和参考母板的串口都使用的是uart4,但是用的引脚不同。在stm32mp157d-100ask.dts文件中引用pinctrl节点,在其下追加uart4_pins_duart4_idle_pins_duart4_sleep_pins_d节点。

//修改stm32mp157d-100ask.dts文件

&pinctrl {
	uart4_pins_d: uart4-3 {
		pins1 {
			pinmux = <STM32_PINMUX('A', 12, AF6)>; /* UART4_TX */
			bias-disable;
			drive-push-pull;
			slew-rate = <0>;
		};
		pins2 {
			pinmux = <STM32_PINMUX('A', 11, AF6)>; /* UART4_RX */
			bias-disable;
		};
	};

	uart4_idle_pins_d: uart4-idle-3 {
		pins1 {
			pinmux = <STM32_PINMUX('A', 12, ANALOG)>; /* UART4_TX */
		};
		pins2 {
			pinmux = <STM32_PINMUX('A', 11, AF6)>; /* UART4_RX */
			bias-disable;
		};
	};

	uart4_sleep_pins_d: uart4-sleep-3 {
		pins {
			pinmux = <STM32_PINMUX('A', 12, ANALOG)>, /* UART4_TX */
				<STM32_PINMUX('A', 11, ANALOG)>; /* UART4_RX */
		};
	};
};

修改uart4对引脚的配置,把uart4_pins_a改为uart4_pins_d

//修改stm32mp15xx-100ask.dtsi文件
&uart4 {
	pinctrl-names = "default", "sleep", "idle";
	pinctrl-0 = <&uart4_pins_a>;
	pinctrl-1 = <&uart4_sleep_pins_a>;
	pinctrl-2 = <&uart4_idle_pins_a>;
	/delete-property/dmas;
	/delete-property/dma-names;
	status = "okay";
};
//改为
&uart4 {
	pinctrl-names = "default", "sleep", "idle";
	pinctrl-0 = <&uart4_pins_d>;
	pinctrl-1 = <&uart4_sleep_pins_d>;
	pinctrl-2 = <&uart4_idle_pins_d>;
	/delete-property/dmas;
	/delete-property/dma-names;
	status = "okay";
};

2.2.2 修改时钟

由于我们参考的官方母板采用的是有源晶振,100ASK_STM32MP157_V11开发板采用了无源晶振。上图是官方晶振原理图,下图为100ASK_STM32MP157_V11开发板原理图。U-Boot时钟为SPL阶段初始化,所以可以不改。
STM32MP157 u-boot2021.10移植_第2张图片

STM32MP157 u-boot2021.10移植_第3张图片

//删除stm32mp157d-100ask-u-boot.dtsi文件如下代码
&clk_hse {
	st,digbypass;
};

2.2.3 修改电源

由于我们参考的官方母板使用了STPMIC1电源管理芯片,但是100ASK_STM32MP157_V11开发板没有使用电源管理芯片,使用的是固定电源。我们需要删除STPMIC1相关的东西,然后添加一些固定电源域完善设备树。

//修改stm32mp15xx-100ask.dtsi文件

/ {
	// 此处代码已省略
	
	vin: vin {
		compatible = "regulator-fixed";
		regulator-name = "vin";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		regulator-always-on;
	};

	//此处添加以下这些固定电源域
	vddcore: regulator-vddcore {
		compatible = "regulator-fixed";
		regulator-name = "vddcore";
		regulator-min-microvolt = <1200000>;
		regulator-max-microvolt = <1350000>;
		regulator-always-on;
	};

	vdd: regulator-vdd {
		compatible = "regulator-fixed";
		regulator-name = "vdd";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
		regulator-boot-on;
	};
	
	v3v3: regulator-v3v3 {
		compatible = "regulator-fixed";
		regulator-name = "v3v3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
		regulator-boot-on;
	};
	
	vdd_usb: regulator-vdd-usb {
		compatible = "regulator-fixed";
		regulator-name = "vdd_usb";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
		regulator-boot-on;
	};
};

&i2c4 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&i2c4_pins_a>;
	pinctrl-1 = <&i2c4_sleep_pins_a>;
	i2c-scl-rising-time-ns = <185>;
	i2c-scl-falling-time-ns = <20>;
	clock-frequency = <400000>;
	status = "okay";
	/* spare dmas for other usage */
	/delete-property/dmas;
	/delete-property/dma-names;

	stusb1600@28 {
		compatible = "st,stusb1600";
		reg = <0x28>;
		interrupts = <11 IRQ_TYPE_LEVEL_LOW>;
		interrupt-parent = <&gpioi>;
		pinctrl-names = "default";
		pinctrl-0 = <&stusb1600_pins_a>;
		status = "okay";
		vdd-supply = <&vin>;

		connector {
			compatible = "usb-c-connector";
			label = "USB-C";
			power-role = "dual";
			typec-power-opmode = "default";

			port {
				con_usbotg_hs_ep: endpoint {
					remote-endpoint = <&usbotg_hs_ep>;
				};
			};
		};
	};
/* 删除这部分注释代码
	pmic: stpmic@33 {
		compatible = "st,stpmic1";
		reg = <0x33>;
		interrupts-extended = <&exti_pwr 55 IRQ_TYPE_EDGE_FALLING>;
		interrupt-controller;
		#interrupt-cells = <2>;
		status = "okay";

		regulators {
			// 此处代码已省略
	};
*/
};

/* 删除这个节点
&vrefbuf {
	// 此处代码已省略;
};
*/
//修改stm32mp157d-100ask-u-boot.dtsi文件

/* 删除这个节点
&pmic {
	u-boot,dm-pre-reloc;
};
*/

官方开发板上电U-Boot利用ADC检测了供电type-c的供电电压是否正常,100ASK_STM32MP157_V11没有这个设计需要去掉,我们直接删除ADC设备树。

//修改stm32mp15xx-100ask.dtsi文件

/* 删除这个节点
&adc {
	pinctrl-names = "default";
	pinctrl-0 = <&adc12_usb_cc_pins_a>;
	vdd-supply = <&vdd>;
	vdda-supply = <&vdd>;
	vref-supply = <&vrefbuf>;
	status = "okay";
	adc1: adc@0 {
		// 此处代码已省略
	};
	adc2: adc@100 {
		// 此处代码已省略
	};
};
*/

最关键的一行st,adc_usb_pd = <&adc1 18>, <&adc1 19>;,ADC是用来检查上电电压,删了这一行就不会检测了,但是我们板子没ADC的设计直接删除。

//修改stm32mp157d-100ask-u-boot.dtsi文件

/ {
	config {
		u-boot,boot-led = "heartbeat";
		u-boot,error-led = "error";
		u-boot,mmc-env-partition = "u-boot-env";
		//st,adc_usb_pd = <&adc1 18>, <&adc1 19>;  删除这行
		st,fastboot-gpios = <&gpioa 13 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
		st,stm32prog-gpios = <&gpioa 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
	};
};

/* 删除这个节点
&adc {
	status = "okay";
};
*/

2.2.4 修改DDR

DDR是在TF-A中初始化的可以不改,直接复制TF_A中的stm32mp15-ddr3-2x2Gb-1066-binG.dtsi文件。

/*
 * Copyright (C) 2015-2018, STMicroelectronics - All Rights Reserved
 *
 * SPDX-License-Identifier:	GPL-2.0+	BSD-3-Clause
 *
 */

/*
 * File generated by STMicroelectronics STM32CubeMX DDR Tool for MPUs
 * DDR type: DDR3 / DDR3L
 * DDR width: 32bits
 * DDR density: 4Gb
 * System frequency: 533000kHz
 * Relaxed Timing Mode: false
 * Address mapping type: RBC
 *
 * Save Date: 2022.08.28, save Time: 00:42:46
 */

#define DDR_MEM_NAME	"DDR3-DDR3L 32bits 533000kHz"
#define DDR_MEM_SPEED	533000
#define DDR_MEM_SIZE	0x20000000

#define DDR_MSTR 0x00040401
#define DDR_MRCTRL0 0x00000010
#define DDR_MRCTRL1 0x00000000
#define DDR_DERATEEN 0x00000000
#define DDR_DERATEINT 0x00800000
#define DDR_PWRCTL 0x00000000
#define DDR_PWRTMG 0x00400010
#define DDR_HWLPCTL 0x00000000
#define DDR_RFSHCTL0 0x00210000
#define DDR_RFSHCTL3 0x00000000
#define DDR_RFSHTMG 0x0081008B
#define DDR_CRCPARCTL0 0x00000000
#define DDR_DRAMTMG0 0x121B2414
#define DDR_DRAMTMG1 0x000A041C
#define DDR_DRAMTMG2 0x0608090F
#define DDR_DRAMTMG3 0x0050400C
#define DDR_DRAMTMG4 0x08040608
#define DDR_DRAMTMG5 0x06060403
#define DDR_DRAMTMG6 0x02020002
#define DDR_DRAMTMG7 0x00000202
#define DDR_DRAMTMG8 0x00001005
#define DDR_DRAMTMG14 0x000000A0
#define DDR_ZQCTL0 0xC2000040
#define DDR_DFITMG0 0x02060105
#define DDR_DFITMG1 0x00000202
#define DDR_DFILPCFG0 0x07000000
#define DDR_DFIUPD0 0xC0400003
#define DDR_DFIUPD1 0x00000000
#define DDR_DFIUPD2 0x00000000
#define DDR_DFIPHYMSTR 0x00000000
#define DDR_ODTCFG 0x06000600
#define DDR_ODTMAP 0x00000001
#define DDR_SCHED 0x00000C01
#define DDR_SCHED1 0x00000000
#define DDR_PERFHPR1 0x01000001
#define DDR_PERFLPR1 0x08000200
#define DDR_PERFWR1 0x08000400
#define DDR_DBG0 0x00000000
#define DDR_DBG1 0x00000000
#define DDR_DBGCMD 0x00000000
#define DDR_POISONCFG 0x00000000
#define DDR_PCCFG 0x00000010
#define DDR_PCFGR_0 0x00000000
#define DDR_PCFGW_0 0x00000000
#define DDR_PCFGQOS0_0 0x02100C03
#define DDR_PCFGQOS1_0 0x00800100
#define DDR_PCFGWQOS0_0 0x01100C03
#define DDR_PCFGWQOS1_0 0x01000200
#define DDR_PCFGR_1 0x00000000
#define DDR_PCFGW_1 0x00000000
#define DDR_PCFGQOS0_1 0x02100C03
#define DDR_PCFGQOS1_1 0x00800040
#define DDR_PCFGWQOS0_1 0x01100C03
#define DDR_PCFGWQOS1_1 0x01000200
#define DDR_ADDRMAP1 0x00080808
#define DDR_ADDRMAP2 0x00000000
#define DDR_ADDRMAP3 0x00000000
#define DDR_ADDRMAP4 0x00001F1F
#define DDR_ADDRMAP5 0x07070707
#define DDR_ADDRMAP6 0x0F0F0707
#define DDR_ADDRMAP9 0x00000000
#define DDR_ADDRMAP10 0x00000000
#define DDR_ADDRMAP11 0x00000000
#define DDR_PGCR 0x01442E02
#define DDR_PTR0 0x0022AA5B
#define DDR_PTR1 0x04841104
#define DDR_PTR2 0x042DA068
#define DDR_ACIOCR 0x10400812
#define DDR_DXCCR 0x00000C40
#define DDR_DSGCR 0xF200011F
#define DDR_DCR 0x0000000B
#define DDR_DTPR0 0x38D488D0
#define DDR_DTPR1 0x098B00D8
#define DDR_DTPR2 0x10023600
#define DDR_MR0 0x00000840
#define DDR_MR1 0x00000000
#define DDR_MR2 0x00000208
#define DDR_MR3 0x00000000
#define DDR_ODTCR 0x00010000
#define DDR_ZQ0CR1 0x00000038
#define DDR_DX0GCR 0x0000CE81
#define DDR_DX1GCR 0x0000CE81
#define DDR_DX2GCR 0x0000CE81
#define DDR_DX3GCR 0x0000CE81

#include "stm32mp15-ddr.dtsi"

2.2.5 删除LCD HDMI和音频

U-Boot主要是为了启动Linux内核,所以音频和视频我并不打算实现,先将这些节点删除。

//修改stm32mp157d-100ask.dtsi文件

/ {
	/* 删除这个节点
	sound: sound {
		compatible = "audio-graph-card";
		label = "STM32MP15-DK";
		routing =
			"Playback" , "MCLK",
			"Capture" , "MCLK",
			"MICL" , "Mic Bias";
		dais = <&sai2a_port &sai2b_port &i2s2_port>;
		status = "okay";
	};
	*/
};

&i2c1 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&i2c1_pins_a>;
	pinctrl-1 = <&i2c1_sleep_pins_a>;
	i2c-scl-rising-time-ns = <100>;
	i2c-scl-falling-time-ns = <7>;
	status = "okay";
	/delete-property/dmas;
	/delete-property/dma-names;
	
	/* 删除这两个节点
	hdmi-transmitter@39 {
		// 此处代码已省略
	};

	cs42l51: cs42l51@4a {
		// 此处代码已省略
	};
	*/
};

&i2s2 {
	clocks = <&rcc SPI2>, <&rcc SPI2_K>, <&rcc PLL3_Q>, <&rcc PLL3_R>;
	clock-names = "pclk", "i2sclk", "x8k", "x11k";
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&i2s2_pins_a>;
	pinctrl-1 = <&i2s2_sleep_pins_a>;
	status = "okay";

	/* 删除这个节点
	i2s2_port: port {
		// 此处代码已省略
	};
	*/
};

&ltdc {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&ltdc_pins_a>;
	pinctrl-1 = <&ltdc_sleep_pins_a>;
	status = "okay";

	/* 删除这个节点
	port {
		// 此处代码已省略
	};
	*/
};

&sai2 {
	clocks = <&rcc SAI2>, <&rcc PLL3_Q>, <&rcc PLL3_R>;
	clock-names = "pclk", "x8k", "x11k";
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&sai2a_pins_a>, <&sai2b_pins_b>;
	pinctrl-1 = <&sai2a_sleep_pins_a>, <&sai2b_sleep_pins_b>;
	status = "okay";

	/* 删除这两个节点
	sai2a: audio-controller@4400b004 {
		// 此处代码已省略
	};

	sai2b: audio-controller@4400b024 {
		// 此处代码已省略
	};
	*/
};

2.2.6 修改EMMC和SD卡

100ASK_STM32MP157_V11开发板设计有EMMC,需要添加EMMC设备。100ASK_STM32MP157_V11开发板SD卡的设计和官方开发板的设计也有区别需要修改。

//修改stm32mp157d-100ask.dtsi文件

//SD卡修改为
&sdmmc1 {
	pinctrl-names = "default", "opendrain", "sleep";
	pinctrl-0 = <&sdmmc1_b4_pins_a>;
	pinctrl-1 = <&sdmmc1_b4_od_pins_a>;
	pinctrl-2 = <&sdmmc1_b4_sleep_pins_a>;
	broken-cd;
	st,neg-edge;
	bus-width = <4>;
	vmmc-supply = <&v3v3>;
	status = "okay";
};
//增加EMMC节点
&sdmmc2 {
	pinctrl-names = "default", "opendrain", "sleep";
	pinctrl-0 = <&sdmmc2_b4_pins_a &sdmmc2_d47_pins_a>;
	pinctrl-1 = <&sdmmc2_b4_od_pins_a &sdmmc2_d47_pins_a>;
	pinctrl-2 = <&sdmmc2_b4_sleep_pins_a &sdmmc2_d47_sleep_pins_a>;
	non-removable;
	no-sd;
	no-sdio;
	st,dirpol;
	st,negedge; 
	bus-width = <8>;
	vmmc-supply = <&v3v3>;
	vqmmc-supply = <&v3v3>;
	status = "okay";
};

2.2.6 修改USB

pinctrl节点中添加fusb302_pins_a节点。

//修改stm32mp157d-100ask.dts文件

&pinctrl {
	//增加这个节点
	fusb302_pins_a: fusb302-0 {
		pins {
			pinmux = <STM32_PINMUX('F', 10, GPIO)>;
			bias-pull-up;
		};
	};
};

官方开发板使用的是他们自己的USB芯片stusb1600,100ASK_STM32MP157_V11开发板用的是fusb302,但是他们好像是兼容的。100ASK_STM32MP157_V11开发板的usb芯片是在i2c1下地址是22,并且i2c1使用的复用引脚是i2c1_pins_b这一组,将"a"改为"b"。

//修改stm32mp157d-100ask.dtsi文件

&i2c1 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&i2c1_pins_b>;
	pinctrl-1 = <&i2c1_sleep_pins_b>;
	i2c-scl-rising-time-ns = <100>;
	i2c-scl-falling-time-ns = <7>;
	status = "okay";
	/delete-property/dmas;
	/delete-property/dma-names;
	
	//增加这个节点
	fusb302@22 {
		compatible = "fcs,fusb302", "st,stusb1600";
		reg = <0x22>;
		interrupts = <10 IRQ_TYPE_EDGE_FALLING>;
		interrupt-parent = <&gpiof>;
		pinctrl-names = "default";
		pinctrl-0 = <&fusb302_pins_a>;
		status = "okay";
	
		typec_con: connector {
			compatible = "usb-c-connector";
			label = "USB-C";
			power-role = "dual";
			power-opmode = "default";

			port {
				con_usbotg_hs_ep: endpoint {
					remote-endpoint = <&usbotg_hs_ep>;
				};
			};
		};
	};
};

&i2c4 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&i2c4_pins_a>;
	pinctrl-1 = <&i2c4_sleep_pins_a>;
	i2c-scl-rising-time-ns = <185>;
	i2c-scl-falling-time-ns = <20>;
	clock-frequency = <400000>;
	status = "okay";
	/* spare dmas for other usage */
	/delete-property/dmas;
	/delete-property/dma-names;

	/* 删除这个节点
	stusb1600@28 {
		// 此处代码已省略
	};
	*/
};

2.2.7 修改ethernet

100ASK_STM32MP157_V11开发板使用的phy芯片是AR8035,而且复位引脚是连接在G0引脚上的,所以要添加reset这些属性。qca,clk-out-frequency = <125000000>; qca,keep-pll-enabled;是AR8035的属性,应该添加在phy节点里,但是U-Boot得添加在这里,Linux里是添加在phy节点里的。

//修改stm32mp157d-100ask.dtsi文件

#include  //增加这个头文件

&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>;
		};
	};
};

添加AR8035驱动,将REALTEK改为ATHEROS。

#修改stm32mp15_100ask_defconfig文件

CONFIG_PHY_REALTEK=y
#改为
CONFIG_PHY_ATHEROS=y

2.2.8 修改LED

设置我们的LED,U-Boot正常运行这个灯常亮,Linux下这个灯是心跳灯。

//修改stm32mp157d-100ask.dtsi文件

/ {
	led {
		compatible = "gpio-leds";
		led-blue {
			label = "heartbeat";
			//gpios = <&gpiod 11 GPIO_ACTIVE_HIGH>;改为下面这行
			gpios = <&gpioa 10 GPIO_ACTIVE_LOW>;
			linux,default-trigger = "heartbeat";
			default-state = "off";
		};
	};
};

出现错误,这个灯会闪烁。

//修改stm32mp157d-100ask-u-boot.dtsi文件

/ {
	config {
		u-boot,boot-led = "heartbeat";
		u-boot,error-led = "error";
		u-boot,mmc-env-partition = "u-boot-env";
		//st,fastboot-gpios = <&gpiog 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; 按键不知道干什么,改成我们自己的
		//st,stm32prog-gpios = <&gpiog 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;按键不知道干什么,改成我们自己的
		st,fastboot-gpios = <&gpioa 13 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
		st,stm32prog-gpios = <&gpioa 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
	};

	led {
		led-red {
			label = "error";
			//gpios = <&gpiog 8 GPIO_ACTIVE_LOW>; 错误指示灯
			gpios = <&gpioa 13 GPIO_ACTIVE_LOW>;
			default-state = "off";
			status = "okay";
		};
	};
};

3. 编译下载

3.1 编译

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

$ make -f $PWD/../Makefile.sdk DEPLOYDIR=$FIP_DEPLOYDIR_ROOT/u-boot -j12 all

3.2 下载

烧写验证,烧写脚本如下。烧写SD或EMMC如果超时,勾选掉最底下的两行檫除。

#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

#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

#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

#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

烧写并设置好拨码开关,启动。错误是因为没有设置MAC地址,设置地址并保存。
STM32MP157 u-boot2021.10移植_第4张图片

setenv ipaddr 192.168.0.250
setenv ethaddr 00:04:9f:04:d2:33
setenv gatewayip 192.168.0.1
setenv netmask 255.255.255.0
setenv serverip 192.168.0.100
saveenv

重启没有错误,dhcp向路由器从新申请一个IP,ping服务器成功。
STM32MP157 u-boot2021.10移植_第5张图片

4. 总结

对于上层代码兼容要更好些,无需修改源码就调好了这些驱动,Linux移植我们将直接使用U-Boot的设备树。这些代码只启动板子,其他功能问题并没有解决。

学习笔记仅供参考,欢迎指正错误,如有侵权请及时联系。移植源码获取:

git clone https://github.com/Sonboy97/arm-ostl-linux-gnueabi.git
版本:9ae04fa8dbea4c984243179d1faa6e39cd18d2dd

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