• (六)正点原子STM32MP135移植——内核移植


    目录

    一、概述

    二、编译官方代码

    三、移植

    四、编译


    一、概述

            前面已经移植好了TF-A、optee、u-boot,在u-boot能正常跑起来的情况下,现在来移植内核。

    二、编译官方代码

            进入kernel目录

    2.1 解压源码、打补丁

    1. /* 解压源码 */
    2. tar xf linux-6.1.28.tar.xz
    3. /* 进入源码目录 */
    4. cd linux-6.1.28/
    5. /* 打补丁 */
    6. for p in `ls -1 ../*.patch`; do patch -p1 < $p; done

    2.2 配置Kernel

            根据官方手册进行配置即可

    1. /* 配置交叉编译器 */
    2. source /opt/st/stm32mp1/4.2.1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
    3. /* 输出文件夹 */
    4. export OUTPUT_BUILD_DIR=$PWD/../build
    5. mkdir -p ${OUTPUT_BUILD_DIR}
    6. /* 默认配置文件 */
    7. make ARCH=arm O="${OUTPUT_BUILD_DIR}" multi_v7_defconfig fragment*.config

    2.3 编译内核

            编译模块好像要好久,可以不要编译

    1. /* 编译uImage 设备树 */
    2. make ARCH=arm uImage vmlinux dtbs LOADADDR=0xC2000040 O="${OUTPUT_BUILD_DIR}"
    3. /* 编译模块 */
    4. make ARCH=arm modules O="${OUTPUT_BUILD_DIR}"
    5. /* 配置输出文件路径 */
    6. make ARCH=arm INSTALL_MOD_PATH="${OUTPUT_BUILD_DIR}/install_artifact" modules_install O="${OUTPUT_BUILD_DIR}"
    7. mkdir -p ${OUTPUT_BUILD_DIR}/install_artifact/boot/
    8. /* 拷贝输出文件 */
    9. cp ${OUTPUT_BUILD_DIR}/arch/arm/boot/uImage ${OUTPUT_BUILD_DIR}/install_artifact/boot/
    10. cp ${OUTPUT_BUILD_DIR}/arch/arm/boot/dts/st*.dtb ${OUTPUT_BUILD_DIR}/install_artifact/boot/

            这时候去查看build/install_artifact目录下,有boot和lib两个文件夹,boot里有uImage和设备树,lib里是内核模块

    三、移植

    3.1 复制文件

    1. /* 进入设备树目录 */
    2. cd arch/arm/boot/dts/
    3. cp stm32mp135f-dk.dts stm32mp135-atk.dts
    4. cp stm32mp13-pinctrl.dtsi stm32mp135-pinctrl-atk.dtsi
    5. /* 回到源码根目录 */
    6. cd ../../../../

    3.2 修改头文件

            打开stm32mp135-atk.dts,把引脚头文件改成我们的

    1. // #include "stm32mp13-pinctrl.dtsi"
    2. #include "stm32mp13-pinctrl-atk.dtsi"

    3.3 修改电源

            首先找到&scmi_regu节点,全都干掉

    1. // &scmi_regu {
    2. // scmi_vddcpu: voltd-vddcpu {
    3. // reg = ;
    4. // regulator-name = "vddcpu";
    5. // };
    6. // scmi_vdd: voltd-vdd {
    7. // reg = ;
    8. // regulator-name = "vdd";
    9. // };
    10. // scmi_vddcore: voltd-vddcore {
    11. // reg = ;
    12. // regulator-name = "vddcore";
    13. // };
    14. // scmi_vdd_adc: voltd-vdd-adc {
    15. // reg = ;
    16. // regulator-name = "vdd_adc";
    17. // };
    18. // scmi_vdd_usb: voltd-vdd-usb {
    19. // reg = ;
    20. // regulator-name = "vdd_usb";
    21. // };
    22. // scmi_vdd_sd: voltd-vdd-sd {
    23. // reg = ;
    24. // regulator-name = "vdd_sd";
    25. // };
    26. // scmi_v1v8_periph: voltd-v1v8-periph {
    27. // reg = ;
    28. // regulator-name = "v1v8_periph";
    29. // };
    30. // scmi_v3v3_sw: voltd-v3v3-sw {
    31. // reg = ;
    32. // regulator-name = "v3v3_sw";
    33. // };
    34. // };

            去根节点下添加我们对电源的描述,找到v3v3_ao这个节点,把它删了,替换成我们的

    1. // v3v3_ao: v3v3-ao {
    2. // compatible = "regulator-fixed";
    3. // regulator-name = "v3v3_ao";
    4. // regulator-min-microvolt = <3300000>;
    5. // regulator-max-microvolt = <3300000>;
    6. // regulator-always-on;
    7. // };
    8. vddcore: vddcore {
    9. compatible = "regulator-fixed";
    10. regulator-name = "vddcore";
    11. regulator-min-microvolt = <1250000>;
    12. regulator-max-microvolt = <1250000>;
    13. regulator-off-in-suspend;
    14. regulator-always-on;
    15. };
    16. vddcpu: vddcpu {
    17. compatible = "regulator-fixed";
    18. regulator-name = "vddcpu";
    19. regulator-min-microvolt = <1350000>;
    20. regulator-max-microvolt = <1350000>;
    21. regulator-off-in-suspend;
    22. regulator-always-on;
    23. };
    24. v3v3: v3v3 {
    25. compatible = "regulator-fixed";
    26. regulator-name = "v3v3";
    27. regulator-min-microvolt = <3300000>;
    28. regulator-max-microvolt = <3300000>;
    29. regulator-off-in-suspend;
    30. regulator-always-on;
    31. };
    32. vbus_otg: vbus_otg {
    33. compatible = "regulator-fixed";
    34. regulator-name = "vbus_otg";
    35. regulator-min-microvolt = <5000000>;
    36. regulator-max-microvolt = <5000000>;
    37. regulator-off-in-suspend;
    38. regulator-always-on;
    39. };
    40. vdd: vdd {
    41. compatible = "regulator-fixed";
    42. regulator-name = "vdd";
    43. regulator-min-microvolt = <3300000>;
    44. regulator-max-microvolt = <3300000>;
    45. regulator-off-in-suspend;
    46. regulator-always-on;
    47. };
    48. vdd_usb: vdd_usb {
    49. compatible = "regulator-fixed";
    50. regulator-name = "vdd_usb";
    51. regulator-min-microvolt = <3300000>;
    52. regulator-max-microvolt = <3300000>;
    53. regulator-off-in-suspend;
    54. regulator-always-on;
    55. };
    56. v1v8_audio: regulator-v1v8_audio {
    57. compatible = "regulator-fixed";
    58. regulator-name = "v1v8_audio";
    59. regulator-min-microvolt = <1800000>;
    60. regulator-max-microvolt = <1800000>;
    61. regulator-always-on;
    62. regulator-boot-on;
    63. };
    64. v3v3_hdmi: regulator-v3v3-hdmi {
    65. compatible = "regulator-fixed";
    66. regulator-name = "v3v3_hdmi";
    67. regulator-min-microvolt = <3300000>;
    68. regulator-max-microvolt = <3300000>;
    69. regulator-always-on;
    70. regulator-boot-on;
    71. };
    72. v1v2_hdmi: regulator-v1v2-hdmi {
    73. compatible = "regulator-fixed";
    74. regulator-name = "v1v2_hdmi";
    75. regulator-min-microvolt = <1200000>;
    76. regulator-max-microvolt = <1200000>;
    77. regulator-always-on;
    78. regulator-boot-on;
    79. };

    3.4 添加看门狗

            由于笔者前面移植u-boot、optee、TF-A哪里遗忘了一个iwdg2,正点原子使用的是iwdg2,而ST官方使用的是arm_wdt,如果前面用到了iwdg2,那就在这里添加上,如果没有则pass这一部分

    1. &iwdg2 {
    2. timeout-sec = <32>;
    3. status = "okay";
    4. };

    3.5 修改网络

            找到eth1和eth2,修改成正点原子的

    1. ð1 {
    2. status = "okay";
    3. pinctrl-0 = <ð1_rgmii_pins_a>;
    4. pinctrl-1 = <ð1_rgmii_sleep_pins_a>;
    5. pinctrl-names = "default", "sleep";
    6. phy-mode = "rgmii-id";
    7. max-speed = <1000>;
    8. phy-handle = <&phy0_eth1>;
    9. nvmem-cells = <ðernet_mac1_address>;
    10. nvmem-cell-names = "mac-address";
    11. mdio1 {
    12. #address-cells = <1>;
    13. #size-cells = <0>;
    14. compatible = "snps,dwmac-mdio";
    15. phy0_eth1: ethernet-phy@1 {
    16. reg = <1>;
    17. };
    18. };
    19. };
    20. ð2 {
    21. status = "okay";
    22. pinctrl-0 = <ð2_rgmii_pins_a>;
    23. pinctrl-1 = <ð2_rgmii_sleep_pins_a>;
    24. pinctrl-names = "default", "sleep";
    25. phy-mode = "rgmii-id";
    26. max-speed = <1000>;
    27. phy-handle = <&phy0_eth2>;
    28. phy-supply = <&v3v3>;
    29. nvmem-cells = <ðernet_mac2_address>;
    30. nvmem-cell-names = "mac-address";
    31. mdio1 {
    32. #address-cells = <1>;
    33. #size-cells = <0>;
    34. compatible = "snps,dwmac-mdio";
    35. phy0_eth2: ethernet-phy@2 {
    36. reg = <2>;
    37. };
    38. };
    39. };

    3.6 修改sdmmc

            找到sdmmc1和sdmmc2,修改成我们的

    1. &sdmmc1 {
    2. pinctrl-names = "default", "opendrain", "sleep";
    3. pinctrl-0 = <&sdmmc1_b4_pins_a &sdmmc1_clk_pins_a>;
    4. pinctrl-1 = <&sdmmc1_b4_od_pins_a &sdmmc1_clk_pins_a>;
    5. pinctrl-2 = <&sdmmc1_b4_sleep_pins_a>;
    6. cd-gpios = <&gpiof 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
    7. st,neg-edge;
    8. no-1-8-v;
    9. bus-width = <4>;
    10. vmmc-supply = <&v3v3>;
    11. #address-cells = <1>;
    12. #size-cells = <0>;
    13. status = "okay";
    14. };
    15. /* EMMC */
    16. &sdmmc2 {
    17. pinctrl-names = "default", "opendrain", "sleep";
    18. pinctrl-0 = <&sdmmc2_b4_pins_a &sdmmc2_b4_b7_pins_a &sdmmc2_clk_pins_a>;
    19. pinctrl-1 = <&sdmmc2_b4_od_pins_a &sdmmc2_b4_b7_od_pins_a &sdmmc2_clk_pins_a>;
    20. pinctrl-2 = <&sdmmc2_b4_sleep_pins_a &sdmmc2_b4_b7_sleep_pins_a>;
    21. non-removable;
    22. st,neg-edge;
    23. mmc-ddr-3_3v;
    24. no-1-8-v;
    25. bus-width = <8>;
    26. vmmc-supply = <&v3v3>;
    27. keep-power-in-suspend;
    28. #address-cells = <1>;
    29. #size-cells = <0>;
    30. status = "okay";
    31. };

    3.7 删掉其它

            如果根文件系统是在emmc里,只需要修改一个sdmmc2能用就行;如果根文件系统需要通过nfs挂载,那就需要修改eth1和eth2节点。而对于其他部分,USB、OTG、LCD等外设,都是可以删除的,这些都是正点原子会讲会移植的东西,所以笔者在这里把不需要的外设全部移除

    1.        usbh_ehci、usbotg_hs、usbphyc、usbphyc_port0、usbphyc_port1

    2.        usart1、 usart2、uart8

    3.        timers3、timers4、timers8、timers14

    4.        spi5

    5.        rtc

    6.        ltdc

    7.        i2c1、i2c5

    8.        dcmipp

    9.        adc1

    10.      根节点下:gpio-keys、leds、panel_backlight、panel_rgb、wake_up、wifi_pwrseq

            删除之后可以得到一个相对精简的设备树

    1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
    2. /*
    3. * Copyright (C) STMicroelectronics 2021 - All Rights Reserved
    4. * Author: Alexandre Torgue for STMicroelectronics.
    5. */
    6. /dts-v1/;
    7. #include
    8. #include
    9. #include
    10. #include
    11. #include
    12. #include "stm32mp135.dtsi"
    13. #include "stm32mp13xf.dtsi"
    14. #include "stm32mp13-pinctrl-atk.dtsi"
    15. / {
    16. model = "ATK STM32MP135-ATK Discovery Board";
    17. compatible = "st,stm32mp135-ATK", "st,stm32mp135";
    18. aliases {
    19. ethernet0 = ð1;
    20. ethernet1 = ð2;
    21. serial0 = &uart4;
    22. };
    23. chosen {
    24. stdout-path = "serial0:115200n8";
    25. #address-cells = <1>;
    26. #size-cells = <1>;
    27. ranges;
    28. framebuffer {
    29. compatible = "simple-framebuffer";
    30. clocks = <&rcc LTDC_PX>;
    31. status = "disabled";
    32. };
    33. };
    34. clocks {
    35. clk_ext_camera: clk-ext-camera {
    36. #clock-cells = <0>;
    37. compatible = "fixed-clock";
    38. clock-frequency = <24000000>;
    39. };
    40. clk_mco1: clk-mco1 {
    41. #clock-cells = <0>;
    42. compatible = "fixed-clock";
    43. clock-frequency = <24000000>;
    44. };
    45. };
    46. memory@c0000000 {
    47. device_type = "memory";
    48. reg = <0xc0000000 0x20000000>;
    49. };
    50. reserved-memory {
    51. #address-cells = <1>;
    52. #size-cells = <1>;
    53. ranges;
    54. optee@dd000000 {
    55. reg = <0xdd000000 0x3000000>;
    56. no-map;
    57. };
    58. };
    59. vddcore: vddcore {
    60. compatible = "regulator-fixed";
    61. regulator-name = "vddcore";
    62. regulator-min-microvolt = <1250000>;
    63. regulator-max-microvolt = <1250000>;
    64. regulator-off-in-suspend;
    65. regulator-always-on;
    66. };
    67. vddcpu: vddcpu {
    68. compatible = "regulator-fixed";
    69. regulator-name = "vddcpu";
    70. regulator-min-microvolt = <1350000>;
    71. regulator-max-microvolt = <1350000>;
    72. regulator-off-in-suspend;
    73. regulator-always-on;
    74. };
    75. v3v3: v3v3 {
    76. compatible = "regulator-fixed";
    77. regulator-name = "v3v3";
    78. regulator-min-microvolt = <3300000>;
    79. regulator-max-microvolt = <3300000>;
    80. regulator-off-in-suspend;
    81. regulator-always-on;
    82. };
    83. vbus_otg: vbus_otg {
    84. compatible = "regulator-fixed";
    85. regulator-name = "vbus_otg";
    86. regulator-min-microvolt = <5000000>;
    87. regulator-max-microvolt = <5000000>;
    88. regulator-off-in-suspend;
    89. regulator-always-on;
    90. };
    91. vdd: vdd {
    92. compatible = "regulator-fixed";
    93. regulator-name = "vdd";
    94. regulator-min-microvolt = <3300000>;
    95. regulator-max-microvolt = <3300000>;
    96. regulator-off-in-suspend;
    97. regulator-always-on;
    98. };
    99. vdd_usb: vdd_usb {
    100. compatible = "regulator-fixed";
    101. regulator-name = "vdd_usb";
    102. regulator-min-microvolt = <3300000>;
    103. regulator-max-microvolt = <3300000>;
    104. regulator-off-in-suspend;
    105. regulator-always-on;
    106. };
    107. v1v8_audio: regulator-v1v8_audio {
    108. compatible = "regulator-fixed";
    109. regulator-name = "v1v8_audio";
    110. regulator-min-microvolt = <1800000>;
    111. regulator-max-microvolt = <1800000>;
    112. regulator-always-on;
    113. regulator-boot-on;
    114. };
    115. v3v3_hdmi: regulator-v3v3-hdmi {
    116. compatible = "regulator-fixed";
    117. regulator-name = "v3v3_hdmi";
    118. regulator-min-microvolt = <3300000>;
    119. regulator-max-microvolt = <3300000>;
    120. regulator-always-on;
    121. regulator-boot-on;
    122. };
    123. v1v2_hdmi: regulator-v1v2-hdmi {
    124. compatible = "regulator-fixed";
    125. regulator-name = "v1v2_hdmi";
    126. regulator-min-microvolt = <1200000>;
    127. regulator-max-microvolt = <1200000>;
    128. regulator-always-on;
    129. regulator-boot-on;
    130. };
    131. };
    132. &iwdg2 {
    133. timeout-sec = <32>;
    134. status = "okay";
    135. };
    136. &arm_wdt {
    137. timeout-sec = <32>;
    138. status = "okay";
    139. };
    140. &crc1 {
    141. status = "okay";
    142. };
    143. &cryp {
    144. status = "okay";
    145. };
    146. &dts {
    147. status = "okay";
    148. };
    149. ð1 {
    150. status = "okay";
    151. pinctrl-0 = <ð1_rgmii_pins_a>;
    152. pinctrl-1 = <ð1_rgmii_sleep_pins_a>;
    153. pinctrl-names = "default", "sleep";
    154. phy-mode = "rgmii-id";
    155. max-speed = <1000>;
    156. phy-handle = <&phy0_eth1>;
    157. nvmem-cells = <ðernet_mac1_address>;
    158. nvmem-cell-names = "mac-address";
    159. mdio1 {
    160. #address-cells = <1>;
    161. #size-cells = <0>;
    162. compatible = "snps,dwmac-mdio";
    163. phy0_eth1: ethernet-phy@1 {
    164. reg = <1>;
    165. };
    166. };
    167. };
    168. ð2 {
    169. status = "okay";
    170. pinctrl-0 = <ð2_rgmii_pins_a>;
    171. pinctrl-1 = <ð2_rgmii_sleep_pins_a>;
    172. pinctrl-names = "default", "sleep";
    173. phy-mode = "rgmii-id";
    174. max-speed = <1000>;
    175. phy-handle = <&phy0_eth2>;
    176. phy-supply = <&v3v3>;
    177. nvmem-cells = <ðernet_mac2_address>;
    178. nvmem-cell-names = "mac-address";
    179. mdio1 {
    180. #address-cells = <1>;
    181. #size-cells = <0>;
    182. compatible = "snps,dwmac-mdio";
    183. phy0_eth2: ethernet-phy@2 {
    184. reg = <2>;
    185. };
    186. };
    187. };
    188. &sdmmc1 {
    189. pinctrl-names = "default", "opendrain", "sleep";
    190. pinctrl-0 = <&sdmmc1_b4_pins_a &sdmmc1_clk_pins_a>;
    191. pinctrl-1 = <&sdmmc1_b4_od_pins_a &sdmmc1_clk_pins_a>;
    192. pinctrl-2 = <&sdmmc1_b4_sleep_pins_a>;
    193. cd-gpios = <&gpiof 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
    194. st,neg-edge;
    195. no-1-8-v;
    196. bus-width = <4>;
    197. vmmc-supply = <&v3v3>;
    198. #address-cells = <1>;
    199. #size-cells = <0>;
    200. status = "okay";
    201. };
    202. /* EMMC */
    203. &sdmmc2 {
    204. pinctrl-names = "default", "opendrain", "sleep";
    205. pinctrl-0 = <&sdmmc2_b4_pins_a &sdmmc2_b4_b7_pins_a &sdmmc2_clk_pins_a>;
    206. pinctrl-1 = <&sdmmc2_b4_od_pins_a &sdmmc2_b4_b7_od_pins_a &sdmmc2_clk_pins_a>;
    207. pinctrl-2 = <&sdmmc2_b4_sleep_pins_a &sdmmc2_b4_b7_sleep_pins_a>;
    208. non-removable;
    209. st,neg-edge;
    210. mmc-ddr-3_3v;
    211. no-1-8-v;
    212. bus-width = <8>;
    213. vmmc-supply = <&v3v3>;
    214. keep-power-in-suspend;
    215. #address-cells = <1>;
    216. #size-cells = <0>;
    217. status = "okay";
    218. };
    219. &uart4 {
    220. pinctrl-names = "default", "sleep", "idle";
    221. pinctrl-0 = <&uart4_pins_a>;
    222. pinctrl-1 = <&uart4_sleep_pins_a>;
    223. pinctrl-2 = <&uart4_idle_pins_a>;
    224. /delete-property/dmas;
    225. /delete-property/dma-names;
    226. status = "okay";
    227. };

    3.8 修改引脚

            由于前面删了很多无关外设,引脚我们只需要复制原子的部分即可:eth1、eth2、emmc1、emmc2

    1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
    2. /*
    3. * Copyright (C) STMicroelectronics 2021 - All Rights Reserved
    4. * Author: Alexandre Torgue
    5. */
    6. #include
    7. &pinctrl {
    8. eth1_rgmii_pins_a: eth1-rgmii-1 {
    9. pins1 {
    10. pinmux = <STM32_PINMUX('F', 12, AF11)>, /* ETH1_RGMII_CLK125 */
    11. <STM32_PINMUX('C', 1, AF11)>, /* ETH1_RGMII_GTX_CLK */
    12. <STM32_PINMUX('G', 13, AF11)>, /* ETH1_RGMII_TXD0 */
    13. <STM32_PINMUX('G', 14, AF11)>, /* ETH1_RGMII_TXD1 */
    14. <STM32_PINMUX('C', 2, AF11)>, /* ETH1_RGMII_TXD2 */
    15. <STM32_PINMUX('E', 5, AF10)>, /* ETH1_RGMII_TXD3 */
    16. <STM32_PINMUX('B', 11, AF11)>, /* ETH1_RGMII_TX_CTL */
    17. <STM32_PINMUX('A', 2, AF11)>, /* ETH1_MDIO */
    18. <STM32_PINMUX('G', 2, AF11)>; /* ETH1_MDC */
    19. bias-disable;
    20. drive-push-pull;
    21. slew-rate = <2>;
    22. };
    23. pins2 {
    24. pinmux = <STM32_PINMUX('C', 4, AF11)>, /* ETH1_RGMII_RXD0 */
    25. <STM32_PINMUX('C', 5, AF11)>, /* ETH1_RGMII_RXD1 */
    26. <STM32_PINMUX('B', 0, AF11)>, /* ETH1_RGMII_RXD2 */
    27. <STM32_PINMUX('B', 1, AF11)>, /* ETH1_RGMII_RXD3 */
    28. <STM32_PINMUX('A', 1, AF11)>, /* ETH1_RGMII_RX_CLK */
    29. <STM32_PINMUX('A', 7, AF11)>; /* ETH1_RGMII_RX_CTL */
    30. bias-disable;
    31. };
    32. };
    33. eth1_rgmii_sleep_pins_a: eth1-rgmii-sleep-1 {
    34. pins1 {
    35. pinmux = <STM32_PINMUX('F', 12, ANALOG)>, /* ETH1_RGMII_CLK125 */
    36. <STM32_PINMUX('C', 1, ANALOG)>, /* ETH1_RGMII_GTX_CLK */
    37. <STM32_PINMUX('G', 13, ANALOG)>, /* ETH1_RGMII_TXD0 */
    38. <STM32_PINMUX('G', 14, ANALOG)>, /* ETH1_RGMII_TXD1 */
    39. <STM32_PINMUX('C', 2, ANALOG)>, /* ETH1_RGMII_TXD2 */
    40. <STM32_PINMUX('E', 5, ANALOG)>, /* ETH1_RGMII_TXD3 */
    41. <STM32_PINMUX('B', 11, ANALOG)>, /* ETH1_RGMII_TX_CTL */
    42. <STM32_PINMUX('A', 2, ANALOG)>, /* ETH1_MDIO */
    43. <STM32_PINMUX('G', 2, ANALOG)>, /* ETH1_MDC */
    44. <STM32_PINMUX('C', 4, ANALOG)>, /* ETH1_RGMII_RXD0 */
    45. <STM32_PINMUX('C', 5, ANALOG)>, /* ETH1_RGMII_RXD1 */
    46. <STM32_PINMUX('B', 0, ANALOG)>, /* ETH1_RGMII_RXD2 */
    47. <STM32_PINMUX('B', 1, ANALOG)>, /* ETH1_RGMII_RXD3 */
    48. <STM32_PINMUX('A', 1, ANALOG)>, /* ETH1_RGMII_RX_CLK */
    49. <STM32_PINMUX('A', 7, ANALOG)>; /* ETH1_RGMII_RX_CTL */
    50. };
    51. };
    52. eth2_rgmii_pins_a: eth2-rgmii-2 {
    53. pins1 {
    54. pinmux = <STM32_PINMUX('H', 2, AF13)>, /* ETH2_RGMII_CLK125 */
    55. <STM32_PINMUX('F', 7, AF11)>, /* ETH2_RGMII_TXD0 */
    56. <STM32_PINMUX('G', 11, AF10)>, /* ETH2_RGMII_TXD1 */
    57. <STM32_PINMUX('G', 1, AF10)>, /* ETH2_RGMII_TXD2 */
    58. <STM32_PINMUX('E', 6, AF11)>, /* ETH2_RGMII_TXD3 */
    59. <STM32_PINMUX('G', 3, AF10)>, /* ETH2_RGMII_GTX_CLK */
    60. <STM32_PINMUX('F', 6, AF11)>, /* ETH2_RGMII_TX_CTL */
    61. <STM32_PINMUX('B', 2, AF11)>, /* ETH2_MDIO */
    62. <STM32_PINMUX('G', 5, AF10)>; /* ETH2_MDC */
    63. bias-disable;
    64. drive-push-pull;
    65. slew-rate = <2>;
    66. };
    67. pins2 {
    68. pinmux = <STM32_PINMUX('F', 4, AF11)>, /* ETH2_RGMII_RXD0 */
    69. <STM32_PINMUX('E', 2, AF10)>, /* ETH2_RGMII_RXD1 */
    70. <STM32_PINMUX('H', 6, AF12)>, /* ETH2_RGMII_RXD2 */
    71. <STM32_PINMUX('A', 8, AF11)>, /* ETH2_RGMII_RXD3 */
    72. <STM32_PINMUX('H', 11, AF11)>, /* ETH2_RGMII_RX_CLK */
    73. <STM32_PINMUX('G', 12, AF12)>; /* ETH2_RGMII_RX_CTL */
    74. bias-disable;
    75. };
    76. };
    77. eth2_rgmii_sleep_pins_a: eth2-rgmii-sleep-2 {
    78. pins1 {
    79. pinmux = <STM32_PINMUX('H', 2, ANALOG)>, /* ETH2_RGMII_CLK125 */
    80. <STM32_PINMUX('F', 7, ANALOG)>, /* ETH2_RGMII_TXD0 */
    81. <STM32_PINMUX('G', 11, ANALOG)>, /* ETH2_RGMII_TXD1 */
    82. <STM32_PINMUX('G', 1, ANALOG)>, /* ETH2_RGMII_TXD2 */
    83. <STM32_PINMUX('E', 6, ANALOG)>, /* ETH2_RGMII_TXD3 */
    84. <STM32_PINMUX('G', 3, ANALOG)>, /* ETH2_RGMII_GTX_CLK */
    85. <STM32_PINMUX('F', 6, ANALOG)>, /* ETH2_RGMII_TX_CTL */
    86. <STM32_PINMUX('B', 2, ANALOG)>, /* ETH2_MDIO */
    87. <STM32_PINMUX('G', 5, ANALOG)>, /* ETH2_MDC */
    88. <STM32_PINMUX('F', 4, ANALOG)>, /* ETH2_RGMII_RXD0 */
    89. <STM32_PINMUX('E', 2, ANALOG)>, /* ETH2_RGMII_RXD1 */
    90. <STM32_PINMUX('H', 6, ANALOG)>, /* ETH2_RGMII_RXD2 */
    91. <STM32_PINMUX('A', 8, ANALOG)>, /* ETH2_RGMII_RXD3 */
    92. <STM32_PINMUX('H', 11, ANALOG)>, /* ETH2_RGMII_RX_CLK */
    93. <STM32_PINMUX('G', 12, ANALOG)>; /* ETH2_RGMII_RX_CTL */
    94. };
    95. };
    96. sdmmc1_b4_pins_a: sdmmc1-b4-0 {
    97. pins {
    98. pinmux = <STM32_PINMUX('C', 8, AF12)>, /* SDMMC1_D0 */
    99. <STM32_PINMUX('C', 9, AF12)>, /* SDMMC1_D1 */
    100. <STM32_PINMUX('C', 10, AF12)>, /* SDMMC1_D2 */
    101. <STM32_PINMUX('C', 11, AF12)>, /* SDMMC1_D3 */
    102. <STM32_PINMUX('D', 2, AF12)>; /* SDMMC1_CMD */
    103. slew-rate = <1>;
    104. drive-push-pull;
    105. bias-disable;
    106. };
    107. };
    108. sdmmc1_b4_od_pins_a: sdmmc1-b4-od-0 {
    109. pins1 {
    110. pinmux = <STM32_PINMUX('C', 8, AF12)>, /* SDMMC1_D0 */
    111. <STM32_PINMUX('C', 9, AF12)>, /* SDMMC1_D1 */
    112. <STM32_PINMUX('C', 10, AF12)>, /* SDMMC1_D2 */
    113. <STM32_PINMUX('C', 11, AF12)>; /* SDMMC1_D3 */
    114. slew-rate = <1>;
    115. drive-push-pull;
    116. bias-disable;
    117. };
    118. pins2 {
    119. pinmux = <STM32_PINMUX('D', 2, AF12)>; /* SDMMC1_CMD */
    120. slew-rate = <1>;
    121. drive-open-drain;
    122. bias-disable;
    123. };
    124. };
    125. sdmmc1_b4_sleep_pins_a: sdmmc1-b4-sleep-0 {
    126. pins {
    127. pinmux = <STM32_PINMUX('C', 8, ANALOG)>, /* SDMMC1_D0 */
    128. <STM32_PINMUX('C', 9, ANALOG)>, /* SDMMC1_D1 */
    129. <STM32_PINMUX('C', 10, ANALOG)>, /* SDMMC1_D2 */
    130. <STM32_PINMUX('C', 11, ANALOG)>, /* SDMMC1_D3 */
    131. <STM32_PINMUX('C', 12, ANALOG)>, /* SDMMC1_CK */
    132. <STM32_PINMUX('D', 2, ANALOG)>; /* SDMMC1_CMD */
    133. };
    134. };
    135. sdmmc1_clk_pins_a: sdmmc1-clk-0 {
    136. pins {
    137. pinmux = <STM32_PINMUX('C', 12, AF12)>; /* SDMMC1_CK */
    138. slew-rate = <1>;
    139. drive-push-pull;
    140. bias-disable;
    141. };
    142. };
    143. sdmmc2_b4_pins_a: sdmmc2-b4-0 {
    144. pins {
    145. pinmux = <STM32_PINMUX('B', 14, AF10)>, /* SDMMC2_D0 */
    146. <STM32_PINMUX('B', 15, AF10)>, /* SDMMC2_D1 */
    147. <STM32_PINMUX('B', 3, AF10)>, /* SDMMC2_D2 */
    148. <STM32_PINMUX('B', 4, AF10)>, /* SDMMC2_D3 */
    149. <STM32_PINMUX('G', 6, AF10)>; /* SDMMC2_CMD */
    150. slew-rate = <1>;
    151. drive-push-pull;
    152. bias-pull-up;
    153. };
    154. };
    155. sdmmc2_b4_b7_pins_a: sdmmc2-b4-b7-0 {
    156. pins {
    157. pinmux = <STM32_PINMUX('F', 0, AF10)>, /* SDMMC2_D4 */
    158. <STM32_PINMUX('B', 9, AF10)>, /* SDMMC2_D5 */
    159. <STM32_PINMUX('C', 6, AF10)>, /* SDMMC2_D6 */
    160. <STM32_PINMUX('C', 7, AF10)>; /* SDMMC2_D7 */
    161. slew-rate = <1>;
    162. drive-push-pull;
    163. bias-pull-up;
    164. };
    165. };
    166. sdmmc2_b4_od_pins_a: sdmmc2-b4-od-0 {
    167. pins1 {
    168. pinmux = <STM32_PINMUX('B', 14, AF10)>, /* SDMMC2_D0 */
    169. <STM32_PINMUX('B', 15, AF10)>, /* SDMMC2_D1 */
    170. <STM32_PINMUX('B', 3, AF10)>, /* SDMMC2_D2 */
    171. <STM32_PINMUX('B', 4, AF10)>; /* SDMMC2_D3 */
    172. slew-rate = <1>;
    173. drive-push-pull;
    174. bias-pull-up;
    175. };
    176. pins2 {
    177. pinmux = <STM32_PINMUX('G', 6, AF10)>; /* SDMMC2_CMD */
    178. slew-rate = <1>;
    179. drive-open-drain;
    180. bias-pull-up;
    181. };
    182. };
    183. sdmmc2_b4_b7_od_pins_a: sdmmc2-b4-b7-od-0 {
    184. pins {
    185. pinmux = <STM32_PINMUX('F', 0, AF10)>, /* SDMMC2_D4 */
    186. <STM32_PINMUX('B', 9, AF10)>, /* SDMMC2_D5 */
    187. <STM32_PINMUX('C', 6, AF10)>, /* SDMMC2_D6 */
    188. <STM32_PINMUX('C', 7, AF10)>; /* SDMMC2_D7 */
    189. slew-rate = <1>;
    190. drive-push-pull;
    191. bias-pull-up;
    192. };
    193. };
    194. sdmmc2_b4_sleep_pins_a: sdmmc2-b4-sleep-0 {
    195. pins {
    196. pinmux = <STM32_PINMUX('B', 14, ANALOG)>, /* SDMMC2_D0 */
    197. <STM32_PINMUX('B', 15, ANALOG)>, /* SDMMC2_D1 */
    198. <STM32_PINMUX('B', 3, ANALOG)>, /* SDMMC2_D2 */
    199. <STM32_PINMUX('B', 4, ANALOG)>, /* SDMMC2_D3 */
    200. <STM32_PINMUX('E', 3, ANALOG)>, /* SDMMC2_CK */
    201. <STM32_PINMUX('G', 6, ANALOG)>; /* SDMMC2_CMD */
    202. };
    203. };
    204. sdmmc2_b4_b7_sleep_pins_a: sdmmc2-b4-b7-sleep-0 {
    205. pins {
    206. pinmux = <STM32_PINMUX('F', 0, ANALOG)>, /* SDMMC2_D4 */
    207. <STM32_PINMUX('B', 9, ANALOG)>, /* SDMMC2_D5 */
    208. <STM32_PINMUX('C', 6, ANALOG)>, /* SDMMC2_D6 */
    209. <STM32_PINMUX('C', 7, ANALOG)>; /* SDMMC2_D7 */
    210. };
    211. };
    212. sdmmc2_clk_pins_a: sdmmc2-clk-0 {
    213. pins {
    214. pinmux = <STM32_PINMUX('E', 3, AF10)>; /* SDMMC2_CK */
    215. slew-rate = <1>;
    216. drive-push-pull;
    217. bias-pull-up;
    218. };
    219. };
    220. uart4_pins_a: uart4-0 {
    221. pins1 {
    222. pinmux = <STM32_PINMUX('D', 6, AF8)>; /* UART4_TX */
    223. bias-disable;
    224. drive-push-pull;
    225. slew-rate = <0>;
    226. };
    227. pins2 {
    228. pinmux = <STM32_PINMUX('D', 8, AF8)>; /* UART4_RX */
    229. bias-pull-up;
    230. };
    231. };
    232. uart4_idle_pins_a: uart4-idle-0 {
    233. pins1 {
    234. pinmux = <STM32_PINMUX('D', 6, ANALOG)>; /* UART4_TX */
    235. };
    236. pins2 {
    237. pinmux = <STM32_PINMUX('D', 8, AF8)>; /* UART4_RX */
    238. bias-pull-up;
    239. };
    240. };
    241. uart4_sleep_pins_a: uart4-sleep-0 {
    242. pins {
    243. pinmux = <STM32_PINMUX('D', 6, ANALOG)>, /* UART4_TX */
    244. <STM32_PINMUX('D', 8, ANALOG)>; /* UART4_RX */
    245. };
    246. };
    247. };

    3.9 修改Makefile

            在源码目录下arch/arm/boot/dts/这个目录里有一个Makefile,找到里面的stm32

    1. dtb-$(CONFIG_ARCH_STM32) += \
    2. stm32f429-disco.dtb \
    3. stm32f469-disco.dtb \
    4. stm32f746-disco.dtb \
    5. stm32f769-disco.dtb \
    6. stm32429i-eval.dtb \
    7. stm32746g-eval.dtb \
    8. stm32h743i-eval.dtb \
    9. stm32h743i-disco.dtb \
    10. stm32h750i-art-pi.dtb \
    11. stm32mp135f-dk.dtb \
    12. stm32mp135f-dk-a7-examples.dtb \
    13. stm32mp151a-prtt1a.dtb \
    14. stm32mp151a-prtt1c.dtb \
    15. stm32mp151a-prtt1s.dtb \
    16. stm32mp153c-dhcom-drc02.dtb \
    17. stm32mp153c-dhcor-drc-compact.dtb \
    18. stm32mp157a-avenger96.dtb \
    19. stm32mp157a-dhcor-avenger96.dtb \
    20. stm32mp157a-dk1.dtb \
    21. stm32mp157a-dk1-a7-examples.dtb \
    22. stm32mp157a-dk1-m4-examples.dtb \
    23. stm32mp157a-ed1.dtb \
    24. stm32mp157a-ev1.dtb \
    25. stm32mp157a-ev1-a7-examples.dtb \
    26. stm32mp157a-ev1-m4-examples.dtb \
    27. stm32mp157a-iot-box.dtb \
    28. stm32mp157a-microgea-stm32mp1-microdev2.0.dtb \
    29. stm32mp157a-microgea-stm32mp1-microdev2.0-of7.dtb \
    30. stm32mp157a-icore-stm32mp1-ctouch2.dtb \
    31. stm32mp157a-icore-stm32mp1-ctouch2-of10.dtb \
    32. stm32mp157a-icore-stm32mp1-edimm2.2.dtb \
    33. stm32mp157a-stinger96.dtb \
    34. stm32mp157c-dhcom-pdk2.dtb \
    35. stm32mp157c-dhcom-picoitx.dtb \
    36. stm32mp157c-dk2.dtb \
    37. stm32mp157c-dk2-a7-examples.dtb \
    38. stm32mp157c-dk2-m4-examples.dtb \
    39. stm32mp157c-ed1.dtb \
    40. stm32mp157c-emsbc-argon.dtb \
    41. stm32mp157c-ev1.dtb \
    42. stm32mp157c-ev1-a7-examples.dtb \
    43. stm32mp157c-ev1-m4-examples.dtb \
    44. stm32mp157c-lxa-mc1.dtb \
    45. stm32mp157c-odyssey.dtb \
    46. stm32mp157d-dk1.dtb \
    47. stm32mp157d-dk1-a7-examples.dtb \
    48. stm32mp157d-dk1-m4-examples.dtb \
    49. stm32mp157d-ed1.dtb \
    50. stm32mp157d-ev1.dtb \
    51. stm32mp157d-ev1-a7-examples.dtb \
    52. stm32mp157d-ev1-m4-examples.dtb \
    53. stm32mp157f-dk2.dtb \
    54. stm32mp157f-dk2-a7-examples.dtb \
    55. stm32mp157f-dk2-m4-examples.dtb \
    56. stm32mp157f-ed1.dtb \
    57. stm32mp157f-ev1.dtb \
    58. stm32mp157f-ev1-a7-examples.dtb \
    59. stm32mp157f-ev1-m4-examples.dtb \

            添加上我们的设备树,或者全删了只留我们自己的设备树

    1. dtb-$(CONFIG_ARCH_STM32) += \
    2. stm32mp135-atk.dtb

    至此,内核所需要修改的文件已全部完成。

    四、编译

    4.1 配置内核

            在这里笔者遇到一个问题,内核编译后直接跑,会提示无法修改CPU主频,然后上网找到了需要配置内核:

    1. /* 打开Linux图形化配置界面 */
    2. make ARCH=arm O="${OUTPUT_BUILD_DIR}" menuconfig

    ->CPU Power Management

            ->CPU Frequency scaling

                    ->[*]        CPU frequency transition statistics

                            ->        Default CPUFreq governor(userspace)

             把CPUFreq改为userspace这个选项

    cp ../build/.config arch/arm/configs/stm32mp135_atk_defconfig

            把配置文件保存为我们的默认配置文件,以便下次使用

    4.2 编译

    1. /* 编译内核、设备树 */
    2. make ARCH=arm uImage vmlinux dtbs LOADADDR=0xC2000040 O="${OUTPUT_BUILD_DIR}"
    3. /* 复制文件到输出文件夹 */
    4. cp ${OUTPUT_BUILD_DIR}/arch/arm/boot/uImage ${OUTPUT_BUILD_DIR}/install_artifact/boot/
    5. cp ${OUTPUT_BUILD_DIR}/arch/arm/boot/dts/st*.dtb ${OUTPUT_BUILD_DIR}/install_artifact/boot/

            这时候查看build/install_artifact/boot文件夹,会发现有刚刚编译好的uImage和stm32mp135-atk.dtb,剩下的烧写就就可以根据原子的详细教程就行了

    4.3 nfs挂载根文件系统

            这里可能有个小小的坑,在设备树中,ethernet0是eth1,ethernet1是eth2,所以用nfs挂根文件系统的时候,应该选eth0或eth1。反正大家可以多尝试几个。

            笔者用tftp和nfs启动内核:

    1. setenv bootcmd 'tftp c2000000 uImage;tftp c4000000 stm32mp135-atk.dtb;bootm c2000000 - c4000000'
    2. setenv bootargs 'console=ttySTM0,115200 root=/dev/nfs nfsroot=192.168.1.2:/home/zhangrl/Linux/nfs/rootfs,proto=tcp rw ip=192.168.1.3:192.168.1.2:192.168.1.1:255.255.255.0::eth1:off'

    4.4 emmc挂根文件系统

            烧写到emmc中的时候,先去uboot里查看自己的内核在emmc的哪一个分区,rootfs在哪一个分区:

            使用ext4ls命令,对一个一个分区进行扫描,直到看到自己的分区(笔者只会这个笨方法)

            ext4ls:

            第一个参数mmc,设备,选择mmc设备

            第二个参数1,选择mmc1,就是我们的emmc

            第三个参数,选择分区,一个一个试

            知道自己的分区之后,就可以该bootcmd和bootargs:

    1. setenv bootcmd 'ext4load mmc 1:6 c2000000 uImage;ext4load mmc 1:6 c4000000 stm32mp135-atk.dtb;bootm c2000000 - c4000000'
    2. setenv bootargs 'console=ttySTM0,115200 root=/dev/mmcblk1p7 rootwait rw'

            至此,STM32MP135的全套移植教程完成,补上了正点原子的空白,剩下的根文件系统直接跟正点原子的教程即可,使用buildroot和busybox都可以。笔者今年刚学Linux,从i.mx6ull学完过来,对Linux的理解可能并不到位

            如果文章有错误,希望大家指正

  • 相关阅读:
    2023年重水(氧化氘)市场规模:现状及未来发展趋
    算法基础学习笔记——⑦位运算
    字符串匹配DP问题合集
    Create a new window with NSWindow
    Ubuntu 20.04中docker-compose部署Nightingale
    【干货分享】.NET人脸识别解决方案
    【原创教程】埃斯顿机器人:弯管机推力解决方式(上)
    如何判断一款软件的安全性?
    laravel中 指定字段 指定数值排序
    Mockito单元测试说明
  • 原文地址:https://blog.csdn.net/qq_42697289/article/details/133577351