[PATCH v4 3/6] rockchip: factor out spl_perform_fixups into common spl-boot-order
Quentin Schulz
foss+uboot at 0leil.net
Thu Jan 18 12:41:16 CET 2024
From: Quentin Schulz <quentin.schulz at theobroma-systems.com>
All SoCs are susceptible to wanting to know which storage medium was
used to load U-Boot SPL. So instead of reimplementing the same functions
in SoCs over and over again (here just rk3399 and px30 but rk3588 is
coming), let's just put all this in common into spl-boot-order.c
allowing to support a new SoC just by defining the spl_boot_devices
array in the appropriate SoC file.
Note that spl_perform_fixups() now calls spl_image_fdt_addr() to get the
address of the fdt instead of directly reading the
spl_image_info->fdt_addr member, because that member is not guaranteed
to be present (guarded with compile flags). This is essential because we
move the logic away from px30 and rk3399 which had those compile flags
enabled to code run for all Rockchip SoCs.
Cc: Quentin Schulz <foss+uboot at 0leil.net>
Reviewed-by: Kever Yang <kever.yang at rock-chips.com>
Signed-off-by: Quentin Schulz <quentin.schulz at theobroma-systems.com>
---
arch/arm/mach-rockchip/px30/px30.c | 46 -------------------------------
arch/arm/mach-rockchip/rk3399/rk3399.c | 46 -------------------------------
arch/arm/mach-rockchip/spl-boot-order.c | 49 +++++++++++++++++++++++++++++++++
3 files changed, 49 insertions(+), 92 deletions(-)
diff --git a/arch/arm/mach-rockchip/px30/px30.c b/arch/arm/mach-rockchip/px30/px30.c
index 8937677d79e..7676adcb044 100644
--- a/arch/arm/mach-rockchip/px30/px30.c
+++ b/arch/arm/mach-rockchip/px30/px30.c
@@ -449,50 +449,4 @@ const char * const spl_boot_devices[BOOT_DEVICE_NONE + 1] = {
[BOOT_DEVICE_MMC2] = "/mmc at ff370000",
[BOOT_DEVICE_MMC1] = "/mmc at ff390000",
};
-
-const char *spl_decode_boot_device(u32 boot_device)
-{
- const char *spl_bootdevice_ofpath = NULL;
-
- if (boot_device < ARRAY_SIZE(spl_boot_devices))
- spl_bootdevice_ofpath = spl_boot_devices[boot_device];
-
- if (spl_bootdevice_ofpath)
- debug("%s: spl_bootdevice_id %x maps to '%s'\n",
- __func__, boot_device, spl_bootdevice_ofpath);
- else
- debug("%s: failed to resolve spl_bootdevice_id %x\n",
- __func__, boot_device);
-
- return spl_bootdevice_ofpath;
-}
-
-void spl_perform_fixups(struct spl_image_info *spl_image)
-{
- void *blob = spl_image->fdt_addr;
- const char *boot_ofpath;
- int chosen;
-
- /*
- * Inject the ofpath of the device the full U-Boot (or Linux in
- * Falcon-mode) was booted from into the FDT, if a FDT has been
- * loaded at the same time.
- */
- if (!blob)
- return;
-
- boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
- if (!boot_ofpath) {
- pr_err("%s: could not map boot_device to ofpath\n", __func__);
- return;
- }
-
- chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
- if (chosen < 0) {
- pr_err("%s: could not find/create '/chosen'\n", __func__);
- return;
- }
- fdt_setprop_string(blob, chosen,
- "u-boot,spl-boot-device", boot_ofpath);
-}
#endif
diff --git a/arch/arm/mach-rockchip/rk3399/rk3399.c b/arch/arm/mach-rockchip/rk3399/rk3399.c
index 60d95c81cd2..6929de5603c 100644
--- a/arch/arm/mach-rockchip/rk3399/rk3399.c
+++ b/arch/arm/mach-rockchip/rk3399/rk3399.c
@@ -181,52 +181,6 @@ const char * const spl_boot_devices[BOOT_DEVICE_NONE + 1] = {
[BOOT_DEVICE_SPI] = "/spi at ff1d0000/flash at 0",
};
-const char *spl_decode_boot_device(u32 boot_device)
-{
- const char *spl_bootdevice_ofpath = NULL;
-
- if (boot_device < ARRAY_SIZE(spl_boot_devices))
- spl_bootdevice_ofpath = spl_boot_devices[boot_device];
-
- if (spl_bootdevice_ofpath)
- debug("%s: spl_bootdevice_id %x maps to '%s'\n",
- __func__, boot_device, spl_bootdevice_ofpath);
- else
- debug("%s: failed to resolve spl_bootdevice_id %x\n",
- __func__, boot_device);
-
- return spl_bootdevice_ofpath;
-}
-
-void spl_perform_fixups(struct spl_image_info *spl_image)
-{
- void *blob = spl_image->fdt_addr;
- const char *boot_ofpath;
- int chosen;
-
- /*
- * Inject the ofpath of the device the full U-Boot (or Linux in
- * Falcon-mode) was booted from into the FDT, if a FDT has been
- * loaded at the same time.
- */
- if (!blob)
- return;
-
- boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
- if (!boot_ofpath) {
- pr_err("%s: could not map boot_device to ofpath\n", __func__);
- return;
- }
-
- chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
- if (chosen < 0) {
- pr_err("%s: could not find/create '/chosen'\n", __func__);
- return;
- }
- fdt_setprop_string(blob, chosen,
- "u-boot,spl-boot-device", boot_ofpath);
-}
-
static void rk3399_force_power_on_reset(void)
{
ofnode node;
diff --git a/arch/arm/mach-rockchip/spl-boot-order.c b/arch/arm/mach-rockchip/spl-boot-order.c
index 93b8e7de4d0..0cd3da20c95 100644
--- a/arch/arm/mach-rockchip/spl-boot-order.c
+++ b/arch/arm/mach-rockchip/spl-boot-order.c
@@ -5,6 +5,7 @@
#include <common.h>
#include <dm.h>
+#include <fdt_support.h>
#include <log.h>
#include <mmc.h>
#include <spl.h>
@@ -161,4 +162,52 @@ void board_boot_order(u32 *spl_boot_list)
if (idx == 0)
spl_boot_list[0] = spl_boot_device();
}
+
+__weak const char * const spl_boot_devices[BOOT_DEVICE_NONE + 1] = {};
+
+const char *spl_decode_boot_device(u32 boot_device)
+{
+ const char *spl_bootdevice_ofpath = NULL;
+
+ if (boot_device < ARRAY_SIZE(spl_boot_devices))
+ spl_bootdevice_ofpath = spl_boot_devices[boot_device];
+
+ if (spl_bootdevice_ofpath)
+ debug("%s: spl_bootdevice_id %x maps to '%s'\n",
+ __func__, boot_device, spl_bootdevice_ofpath);
+ else
+ debug("%s: failed to resolve spl_bootdevice_id %x\n",
+ __func__, boot_device);
+
+ return spl_bootdevice_ofpath;
+}
+
+void spl_perform_fixups(struct spl_image_info *spl_image)
+{
+ void *blob = spl_image_fdt_addr(spl_image);
+ const char *boot_ofpath;
+ int chosen;
+
+ /*
+ * Inject the ofpath of the device the full U-Boot (or Linux in
+ * Falcon-mode) was booted from into the FDT, if a FDT has been
+ * loaded at the same time.
+ */
+ if (!blob)
+ return;
+
+ boot_ofpath = spl_decode_boot_device(spl_image->boot_device);
+ if (!boot_ofpath) {
+ pr_err("%s: could not map boot_device to ofpath\n", __func__);
+ return;
+ }
+
+ chosen = fdt_find_or_add_subnode(blob, 0, "chosen");
+ if (chosen < 0) {
+ pr_err("%s: could not find/create '/chosen'\n", __func__);
+ return;
+ }
+ fdt_setprop_string(blob, chosen,
+ "u-boot,spl-boot-device", boot_ofpath);
+}
#endif
--
2.43.0
More information about the U-Boot
mailing list