060f78f
From fd3434c754b3b8dddb345352a2434b6b8445343a Mon Sep 17 00:00:00 2001
262b414
From: Peter Robinson <pbrobinson@gmail.com>
060f78f
Date: Sun, 18 Apr 2021 14:05:45 +0100
060f78f
Subject: [PATCH] distro: load FDT from any partition on boot device
262b414
262b414
In the EFI_LOADER boot path, we were only checking the FAT partition
262b414
containing the EFI payload for dtb files.  But this is somewhat of a
262b414
fiction.  In reality there will be one small (V)FAT partition containing
262b414
grub (or whatever the payload may be), and a second boot partition
262b414
containing kernel/initrd/fdt (typically ext4).  It is this second
262b414
partition where we should be looking for a FDT to load.
262b414
262b414
So instead scan all the partitions of the disk containing the EFI
262b414
payload.  This matches where grub looks for kernel/initrd (barring
262b414
custom grub.cfg, in which case the user can use grub's 'devicetree'
262b414
command to load the correct FDT).
262b414
262b414
The other option is somehow passing the ${fdtfile} to grub so that it
262b414
can load the FDT based on selected kernel version location (which grub
262b414
knows) and SoC/board specific ${fdtfile} (which grub does not know).
262b414
262b414
Signed-off-by: Rob Clark <robdclark@gmail.com>
ad36d48
Signed-off-by: Peter Robinson <pbrobinson@gmail.com>
262b414
---
060f78f
 include/config_distro_bootcmd.h | 35 ++++++++++++++++++++++-----------
060f78f
 1 file changed, 23 insertions(+), 12 deletions(-)
262b414
262b414
diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
060f78f
index 2627c2a6a5..eadd1080b3 100644
262b414
--- a/include/config_distro_bootcmd.h
262b414
+++ b/include/config_distro_bootcmd.h
060f78f
@@ -148,26 +148,37 @@
060f78f
 		"fi\0"                                                    \
060f78f
 	\
262b414
 	"load_efi_dtb="                                                   \
060f78f
-		"load ${devtype} ${devnum}:${distro_bootpart} "           \
060f78f
-			"${fdt_addr_r} ${prefix}${efi_fdtfile}\0"         \
262b414
+		"load ${devtype} ${devnum}:${dtb_devp} "                  \
262b414
+			"${fdt_addr_r} ${prefix}${efi_fdtfile} && "       \
262b414
+		"run boot_efi_binary\0"                                   \
262b414
 	\
262b414
 	"efi_dtb_prefixes=/ /dtb/ /dtb/current/\0"                        \
262b414
-	"scan_dev_for_efi="                                               \
262b414
+	"scan_dev_for_dtb="                                               \
262b414
 		"setenv efi_fdtfile ${fdtfile}; "                         \
262b414
 		BOOTENV_EFI_SET_FDTFILE_FALLBACK                          \
262b414
-		"for prefix in ${efi_dtb_prefixes}; do "                  \
262b414
-			"if test -e ${devtype} "                          \
262b414
-					"${devnum}:${distro_bootpart} "   \
262b414
-					"${prefix}${efi_fdtfile}; then "  \
262b414
-				"run load_efi_dtb; "                      \
262b414
-			"fi;"                                             \
262b414
-		"done;"                                                   \
5fa2e92
-		"run boot_efi_bootmgr;"                                   \
262b414
+		"part list ${devtype} ${devnum} dtb_devplist; "           \
262b414
+		"env exists dtb_devplist || setenv dtb_devplist "         \
262b414
+			"${distro_bootpart}; "                            \
262b414
+		"for dtb_devp in ${dtb_devplist}; do "                    \
262b414
+			"for prefix in ${efi_dtb_prefixes}; do "          \
262b414
+				"if test -e ${devtype} "                  \
262b414
+						"${devnum}:${dtb_devp} "  \
262b414
+						"${prefix}${efi_fdtfile};"\
262b414
+						" then "                  \
262b414
+					"echo Found DTB ${devtype} "      \
262b414
+						"${devnum}:${dtb_devp} "  \
262b414
+						"${prefix}${efi_fdtfile};"\
262b414
+					"run load_efi_dtb; "              \
262b414
+				"fi;"                                     \
262b414
+			"done; "                                          \
262b414
+		"done; "                                                  \
74de6cf
+		"run boot_efi_binary\0"                                   \
262b414
+	"scan_dev_for_efi="                                               \
262b414
 		"if test -e ${devtype} ${devnum}:${distro_bootpart} "     \
c529a6c
 					"efi/boot/"BOOTEFI_NAME"; then "  \
262b414
 				"echo Found EFI removable media binary "  \
c529a6c
 					"efi/boot/"BOOTEFI_NAME"; "       \
262b414
-				"run boot_efi_binary; "                   \
262b414
+				"run scan_dev_for_dtb; "                  \
262b414
 				"echo EFI LOAD FAILED: continuing...; "   \
262b414
 		"fi; "                                                    \
262b414
 		"setenv efi_fdtfile\0"
262b414
-- 
060f78f
2.31.1
262b414