Patch u-boot device tree with Yocto

I’m trying to patch the u-boot device tree for a verdin imx8mp board. The image builds fine, but my change is not reflected. Here is what I tried.

I built the tdx-reference-minimal image using Yocto. I added a bbappend in the workspace layer. I can see that the bbappend is being picked up by Yocto.

arah@ubuntu:/media/sarah/drive/build/tmp/work/verdin_imx8mp-tdx-linux$ bitbake-layers show-appends u-boot-toradex
/usr/lib/python3/dist-packages/html5lib/_trie/_base.py:3: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
  from collections import Mapping
NOTE: Starting bitbake server...
WARNING: You have included the meta-tpm layer, but 'tpm or tpm2' has not been enabled in your DISTRO_FEATURES. Some bbappend files and preferred version setting may not take effect. See the meta-tpm README for details on enabling tpm support.
Loading cache: 100% |########################################################################################################| Time: 0:00:03
Loaded 4751 entries from dependency cache.
WARNING: No recipes in default available for:
  /media/sarah/drive/build/../layers/meta-toradex-nxp/recipes-bsp/imx-mkimage/imx-mkimage_1.0.bbappend
  /media/sarah/drive/build/../layers/meta-toradex-nxp/recipes-multimedia/gstreamer/gstreamer1.0-plugins-base_1.20.0.imx.bbappend

Summary: There were 2 WARNING messages.
=== Matched appended recipes ===
u-boot-toradex_2022.07.bb:
  /media/sarah/drive/build/../layers/workspace/appends/u-boot-toradex_%.bbappend
u-boot-toradex_2022.04.bb:
  /media/sarah/drive/build/../layers/workspace/appends/u-boot-toradex_%.bbappend

Here is my bbappend:

SRC_URI:append = " file://0001-change-gpio-mode.patch "
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"

And my patch

From 827387a090b43573c2004c7dd5e01d0d70f88ef8 Mon Sep 17 00:00:00 2001
From: sarah
Date: Tue, 12 Mar 2024 09:27:28 -0700
Subject: [PATCH] change gpio mode

---
 arch/arm/dts/imx8mp-verdin.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/dts/imx8mp-verdin.dts b/arch/arm/dts/imx8mp-verdin.dts
index 19ce3ee193..d61bf989e9 100644
--- a/arch/arm/dts/imx8mp-verdin.dts
+++ b/arch/arm/dts/imx8mp-verdin.dts
@@ -374,7 +374,7 @@
 
 	pinctrl_ctrl_sleep_moci: ctrlsleepmocigrp {
 		fsl,pins = <
-			MX8MP_IOMUXC_SAI3_RXC__GPIO4_IO29		0x1c4	/* SODIMM 256 */
+			MX8MP_IOMUXC_SAI3_RXC__GPIO4_IO29		0x104	/* SODIMM 256 */
 		>;
 	};
 
-- 
2.25.1

After the image is built, I can go to the build directory and see that the imx8mp-verdin.dts file does reflect my change.

I then put my board into recovery mode and used the easy installer to install the image. The installation succeeded, but the git hash of u-boot was not updated to reflect my patch. It still shows

ver=U-Boot 2022.04-6.6.0-devel+git.ef90b0f339f2 (Jan 31 2024 - 17:51:48 +0000)

I also checked in u-boot to see what dtb was being used, and then extracted the tezi image generated by my yocto build and decompiled the corresponding dtb file with this command

dtc -I dtb -O dts -o devicetree.dts imx8mp-verdin-wifi-dev.dtb

I checked the resulting devicetree.dts file and saw that my change was not applied (the value was still 0x1c4, not 0x104).

Is there something different I should be doing to get my patch applied? Should I be patching a different file? Is u-boot-toradex not the right recipe to be appending?

Hi Sarah, I’m surprise of the location of your file you’re trying to patch! I was expect it to be located in arch\arm64\boot\dts\freescale !!!

@fboulanger, as I understand it, that would be the path for the linux device tree, not the u-boot device tree, which is what I’m trying to patch. Here it is in the u-boot source: u-boot/arch/arm/dts/imx8mp-verdin.dtsi at master · u-boot/u-boot · GitHub

I tried to manually edit the dtb included in the easy installer image by unzipping the bootfs.tar.xz file and decompiling the imx8mp-verdin-wifi-dev.dtb file. Then I made my edit and recompiled it.

dtc -I dts -O dtb -o imx8mp-verdin-wifi-dev.dtb devicetree.dts

Then I tarred it up again with this command and used the easy installer to flash the image.

tar -cJf Reference-Minimal-Image-verdin-imx8mp.bootfs.tar.xz Reference-Minimal-Image-verdin-imx8mp.bootfs

I figured it would be fine, since it was just a change of 1 byte, so the file size would be the same… but it seems like there’s more going on, maybe a hash somewhere that is now mismatched. The change didn’t work (the gpio I’m trying to change is still high), and now my board won’t boot.

Verdin iMX8MP # boot
MMC: no card present
switch to partitions #0, OK
mmc2(part 0) is current device
Scanning mmc 2:1...
libfdt fdt_check_header(): FDT_ERR_BADMAGIC
MMC: no card present
Scanning disk mmc@30b50000.blk...
Disk mmc@30b50000.blk not ready
Scanning disk mmc@30b60000.blk...
Found 3 disks
No EFI system partition
BootOrder not defined
EFI boot manager: Cannot load any image
starting USB...
Bus usb@38100000: Register 2000140 NbrPorts 2
Starting the controller
USB XHCI 1.10
Bus usb@38200000: Register 2000140 NbrPorts 2
Starting the controller
USB XHCI 1.10
scanning bus usb@38100000 for devices... 1 USB Device(s) found
scanning bus usb@38200000 for devices... Device NOT ready
   Request Sense returned 02 3A 00
3 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
ethernet@30bf0000 Waiting for PHY auto negotiation to complete......... TIMEOUT !
phy_startup() failed: -110FAILED: -110BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
BOOTP broadcast 4
BOOTP broadcast 5

Abort
BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
BOOTP broadcast 4
BOOTP broadcast 5
BOOTP broadcast 6
BOOTP broadcast 7
BOOTP broadcast 8
BOOTP broadcast 9
BOOTP broadcast 10

Trying to use the fdt command to inspect the device tree doesn’t work, for the same reason that it won’t boot. I also tried setting the fdtfile variable to a different dtb that should exist, but that has the same result.

Verdin iMX8MP # fdt print
No FDT memory address configured. Please configure
the FDT address via "fdt addr <address>" command.
Aborting!
Verdin iMX8MP # fdt addr 0x50200000
libfdt fdt_check_header(): FDT_ERR_BADMAGIC

It doesn’t even work to put it into recovery mode and reload the easy installer. I tried to boot from an SD card with a .wic image generated by Yocto, but that also fails. I’ll try a few more things to re-flash a working u-boot, but if anyone knows of an easier solution, I’m all ears :slight_smile:.

I finally figured it out :smiley: Here’s what worked:

  • Patch the u-boot device tree. To do this in Yocto, I placed the patch file in meta-toradex-nxp/recipes-bsp/u-boot/files/0001-gpio4_29.patch
From 9c237761f4bbd8a725a99ee6f5828f195f21c801 Mon Sep 17 00:00:00 2001
From: sarah
Date: Tue, 19 Mar 2024 08:11:47 -0700
Subject: [PATCH] gpio4_29

---
 arch/arm/dts/imx8mp-verdin.dts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/imx8mp-verdin.dts b/arch/arm/dts/imx8mp-verdin.dts
index 19ce3ee193..189c065cff 100644
--- a/arch/arm/dts/imx8mp-verdin.dts
+++ b/arch/arm/dts/imx8mp-verdin.dts
@@ -96,7 +96,7 @@
 		/* Verdin CTRL_SLEEP_MOCI# (SODIMM 256) */
 		gpios = <29 GPIO_ACTIVE_HIGH>;
 		line-name = "CTRL_SLEEP_MOCI#";
-		output-high;
+		output-low;
 		pinctrl-names = "default";
 		pinctrl-0 = <&pinctrl_ctrl_sleep_moci>;
 	};
@@ -374,7 +374,7 @@
 
 	pinctrl_ctrl_sleep_moci: ctrlsleepmocigrp {
 		fsl,pins = <
-			MX8MP_IOMUXC_SAI3_RXC__GPIO4_IO29		0x1c4	/* SODIMM 256 */
+			MX8MP_IOMUXC_SAI3_RXC__GPIO4_IO29		0x104	/* SODIMM 256 */
 		>;
 	};
 
-- 
2.25.1

I also added this line to u-boot-toradex_2022.04.bb

SRC_URI:append = " file://0001-gpio4_29.patch "
  • Patch the linux-toradex recipe. I placed 2 patch files in meta-toradex-nxp/recipes-kernel/linux/linux-toradex-5.15-2.2.x/
From 6473061305eac31454da543346af143bc45c5c17 Mon Sep 17 00:00:00 2001
From: sarah
Date: Tue, 19 Mar 2024 06:27:45 -0700
Subject: [PATCH] gpio4_io29

---
 arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi b/arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi
index 9d6298748c4d..cc43c90a0c41 100644
--- a/arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi
@@ -1018,7 +1018,7 @@ pinctrl_bt_uart: btuartgrp {
 
 	pinctrl_ctrl_sleep_moci: ctrlsleepmocigrp {
 		fsl,pins =
-			<MX8MP_IOMUXC_SAI3_RXC__GPIO4_IO29		0x1c4>;	/* SODIMM 256 */
+			<MX8MP_IOMUXC_SAI3_RXC__GPIO4_IO29		0x104>;	/* SODIMM 256 */
 	};
 
 	pinctrl_ecspi1: ecspi1grp {
-- 
2.25.1
From d29ea56b55d14094edcd0b49f67f3ec203994ae5 Mon Sep 17 00:00:00 2001
From: sarah
Date: Tue, 19 Mar 2024 07:28:51 -0700
Subject: [PATCH] output low

---
 arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi b/arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi
index cc43c90a0c41..ae9b2612dd48 100644
--- a/arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mp-verdin.dtsi
@@ -495,7 +495,7 @@ ctrl-sleep-moci-hog {
 		/* Verdin CTRL_SLEEP_MOCI# (SODIMM 256) */
 		gpios = <29 GPIO_ACTIVE_HIGH>;
 		line-name = "CTRL_SLEEP_MOCI#";
-		output-high;
+		output-low;
 		pinctrl-names = "default";
 		pinctrl-0 = <&pinctrl_ctrl_sleep_moci>;
 	};
-- 
2.25.1

I added these files to SRC_URI in linux-toradex_5.15-2.2.x.bb

  • Built the tdx-reference-minimal-image
  • Copied the tezi files to an SD card
  • Put the module into recovery mode, loaded the tezi image with the easy installer
  • Interrupted boot and ran gpio status to verify the change
Verdin iMX8MP # gpio status
Bank GPIO2_:
GPIO2_12: input: 0 [x] mmc@30b50000.cd-gpios
GPIO2_20: output: 1 [x] reg_ethphy.gpio-hog

Bank GPIO4_:
GPIO4_29: output: 0 [x] CTRL_SLEEP_MOCI#.gpio-hog

Booted as normal and verified that the change is also in linux

root@verdin-imx8mp-15006019:~# cat /sys/kernel/debug/gpio | grep 256
 gpio-125 (SODIMM_256          |CTRL_SLEEP_MOCI#    ) out lo

I also manually set gpio4_29 and then rebooted to see if the change was reverted. As expected, it was.

hi @sarah ,
I had to modify the bootloader device tree as well and the process is actually very simple with devtool:

  1. “devtool modify u-boot-toradex”
  2. make your changes in build-torizon/workspace/source/u-boot-toradex/arch/arm/dts
  3. add and commit your changes: cd build-torizon/workspace/source/u-boot-toradex && git add -A && git commit -m “<whatever_you_want>”
  4. “devtool update-recipe u-boot-toradex -a <path/to/your/custom/layer>”
  5. “devtool reset u-boot-toradex”
  6. delete workspace from your bblayers.conf and add your custom layer
  7. important : make sure your layer as a lower priority than meta-toradex-torizon layer. this layer has 90 as priority so I gave my layer priority 99, in this way my changes are actually applied at the very end
  8. rebuild your image and that’s it!

Regards,
Rocco

1 Like