Skip to contentSkip to conversation

Set /chosen/bootsource for the next boot stage and the OS

PATCH New Wadim Egorov 1 participant 4 messages Nov 17

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover Set /chosen/bootsource for the next boot stage and the OS

Changes in v3:
- Drop the check that the device tree has a node at the bootsource path.
- Use log_warning() instead of printf()
- Update doc strings to match the dropped check
- Collect tags from Quentin

v2: https://lore.kernel.org/u-boot/[email protected]/

Wadim Egorov (3):
fdt_support: Add /chosen/bootsource fixup
arm: mach-k3: Set /chosen/bootsource for the next boot stage
rockchip: Use the generic /chosen/bootsource fixup

 arch/arm/mach-k3/am62x/boot.c           | 26 ++++++++++++++++++
 arch/arm/mach-k3/common.c               |  1 +
 arch/arm/mach-rockchip/spl-boot-order.c | 11 ++++----
 boot/fdt_support.c                      | 35 +++++++++++++++++++++++++
 include/fdt_support.h                   | 25 ++++++++++++++++++
 5 files changed, 93 insertions(+), 5 deletions(-)
Signature · 1 line
2.48.1
#1 lore raw

PATCH v3 1/3 fdt_support: Add /chosen/bootsource fixup

Set /chosen/bootsource to the node of the device the BootROM booted from. Platforms provide the path via bootsource_get_ofpath(). By default we pass on what a previous boot stage has set in the control device tree.

---
 boot/fdt_support.c    | 35 +++++++++++++++++++++++++++++++++++
 include/fdt_support.h | 25 +++++++++++++++++++++++++
 2 files changed, 60 insertions(+)
boot/fdt_support.c +35 -0
index 2941df55996..0557b4d8506 100644
@@ -334,6 +334,39 @@ __weak const char *board_fdt_chosen_bootargs(const struct fdt_property *fdt_ba)
 	return env_get("bootargs");
 }
 
+/*
+ * By default pass on what a previous boot stage recorded in the control
+ * device tree of this stage.
+ */
+__weak const char *bootsource_get_ofpath(void)
+{
+	if (CONFIG_IS_ENABLED(OF_REAL))
+		return ofnode_read_chosen_string("bootsource");
+
+	return NULL;
+}
+
+int fdt_fixup_bootsource(void *fdt)
+{
+	const char *path;
+	int chosen, err;
+
+	path = bootsource_get_ofpath();
+	if (!path)
+		return 0;
+
+	chosen = fdt_find_or_add_subnode(fdt, 0, "chosen");
+	if (chosen < 0)
+		return chosen;
+
+	err = fdt_setprop_string(fdt, chosen, "bootsource", path);
+	if (err < 0)
+		log_warning("could not set bootsource %s.\n",
+			    fdt_strerror(err));
+
+	return err;
+}
+
 int fdt_chosen(void *fdt)
 {
 	struct abuf buf = {};
@@ -353,6 +386,8 @@ int fdt_chosen(void *fdt)
 	if (nodeoffset < 0)
 		return nodeoffset;
 
+	fdt_fixup_bootsource(fdt);
+
 	/* if DM_RNG enabled automatically inject kaslr-seed node unless:
 	 * CONFIG_MEASURED_BOOT enabled: as dt modifications break measured boot
 	 * CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT enabled: as that implementation does not use dm yet
include/fdt_support.h +25 -0
index 47b8b63d13d..f287c81e755 100644
@@ -55,6 +55,31 @@ int fdt_root(void *fdt);
  */
 int fdt_chosen(void *fdt);
 
+/**
+ * bootsource_get_ofpath() - get the path of the node of the boot medium the
+ *                           BootROM loaded the first boot stage from
+ *
+ * Platforms implement this so that /chosen/bootsource can be recorded in the
+ * device tree handed to the next boot stage and to the OS. The default
+ * implementation passes on what a previous stage recorded in the control
+ * device tree of the current stage.
+ *
+ * Return: full node path of the boot medium, or NULL if unknown
+ */
+const char *bootsource_get_ofpath(void);
+
+/**
+ * fdt_fixup_bootsource() - record the BootROM boot medium in /chosen
+ *
+ * @fdt: FDT address in memory
+ *
+ * Sets /chosen/bootsource to the path returned by bootsource_get_ofpath(),
+ * if that path is known. The /chosen node is created if necessary.
+ *
+ * Return: 0 if ok or nothing to do, or -FDT_ERR_... on error
+ */
+int fdt_fixup_bootsource(void *fdt);
+
 /**
  * fdt_initrd() - add initrd information to the FDT before booting the OS
  *
Signature · 1 line
2.48.1
#2 lore raw

PATCH v3 2/3 arm: mach-k3: Set /chosen/bootsource for the next boot stage

In reply to Wadim Egorov

Call fdt_fixup_bootsource() from spl_perform_arch_fixups() so the next boot stage knows the device the ROM booted from.

Implement bootsource_get_ofpath() for AM62x by mapping the boot device from get_boot_device() to its device tree node. For OSPI boot the path points to the flash chip and not the controller, since the flash node is what the OS maps to an MTD device. All AM62 boards name it flash@0.

---
 arch/arm/mach-k3/am62x/boot.c | 26 ++++++++++++++++++++++++++
 arch/arm/mach-k3/common.c     |  1 +
 2 files changed, 27 insertions(+)
arch/arm/mach-k3/am62x/boot.c +26 -0
index a3a6cda6bdb..db07a550caf 100644
@@ -2,6 +2,7 @@
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/am62_spl.h>
+#include <fdt_support.h>
 
 static u32 __get_backup_bootmedia(u32 devstat)
 {
@@ -102,6 +103,31 @@ u32 get_boot_device(void)
 	return bootmedia;
 }
 
+const char *bootsource_get_ofpath(void)
+{
+	switch (get_boot_device()) {
+	case BOOT_DEVICE_MMC1:
+		return "/bus@f0000/mmc@fa10000";
+	case BOOT_DEVICE_MMC2:
+		return "/bus@f0000/mmc@fa00000";
+	case BOOT_DEVICE_SPI:
+		/*
+		 * The flash chip is described by the board device tree. All
+		 * AM62 boards name it flash@0.
+		 */
+		return "/bus@f0000/bus@fc00000/spi@fc40000/flash@0";
+	case BOOT_DEVICE_ETHERNET:
+		return "/bus@f0000/ethernet@8000000/ethernet-ports/port@1";
+	case BOOT_DEVICE_UART:
+		return "/bus@f0000/serial@2800000";
+	case BOOT_DEVICE_USB:
+	case BOOT_DEVICE_DFU:
+		return "/bus@f0000/dwc3-usb@f900000/usb@31000000";
+	}
+
+	return NULL;
+}
+
 const char *get_reset_reason(void)
 {
 	u32 reset_reason = readl(CTRLMMR_MCU_RST_SRC);
arch/arm/mach-k3/common.c +1 -0
index 6e382efdb3b..c7fd7b4f44c 100644
@@ -570,6 +570,7 @@ void spl_perform_arch_fixups(struct spl_image_info *spl_image)
 		return;
 
 	fdt_fixup_reserved(fdt);
+	fdt_fixup_bootsource(fdt);
 
 	if (IS_ENABLED(CONFIG_SPL_OS_BOOT))
 		k3_falcon_fdt_fixup(fdt);
Signature · 1 line
2.48.1
#3 lore raw

PATCH v3 3/3 rockchip: Use the generic /chosen/bootsource fixup

In reply to Wadim Egorov

Implement bootsource_get_ofpath() on top of board_spl_was_booted_from() and use fdt_fixup_bootsource() in spl_perform_arch_fixups(). With this U-Boot proper also passes the path on to the OS.

---
 arch/arm/mach-rockchip/spl-boot-order.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
arch/arm/mach-rockchip/spl-boot-order.c +6 -5
index d2dd5e10935..1a2fdc420d9 100644
@@ -262,9 +262,13 @@ int spl_decode_boot_device(u32 boot_device, char *buf, size_t buflen)
 #endif
 }
 
+const char *bootsource_get_ofpath(void)
+{
+	return board_spl_was_booted_from();
+}
+
 void spl_perform_arch_fixups(struct spl_image_info *spl_image)
 {
-	const char *bootrom_ofpath = board_spl_was_booted_from();
 	void *blob = spl_image_fdt_addr(spl_image);
 	char boot_ofpath[512];
 	int chosen, ret;
@@ -293,9 +297,6 @@ void spl_perform_arch_fixups(struct spl_image_info *spl_image)
 	 * Inject the ofpath of the device the BootROM loaded the very first
 	 * stage from into the FDT.
 	 */
-	if (!bootrom_ofpath)
-		pr_err("%s: could not map BootROM boot device to ofpath\n", __func__);
-	else
-		fdt_setprop_string(blob, chosen, "bootsource", bootrom_ofpath);
+	fdt_fixup_bootsource(blob);
 }
 #endif
Signature · 1 line
2.48.1