Skip to contentSkip to conversation

*** Introduce get_boot_device() for K3 platform ***

PATCH In review Wadim Egorov 2 participants 5 messages Apr 3, 2024 – Apr 12, 2024

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

v2 cover *** Introduce get_boot_device() for K3 platform ***

It is handy to have some u-boot environment variables set based on the current booting device.
Provide a way to obtain the boot device for non SPLs by factoring out spl_boot_device() into an own function get_boot_device().

v2:
- Relocate bootindex to OCRAM, drop misleading comments and remove not needed changes
- Make get_boot_device() read bootindex out of OCRAM
- Add user for get_boot_device(), patch 3

v1: https://lists.denx.de/pipermail/u-boot/2024-February/546770.html

Wadim Egorov (3):
arm: mach-k3: am625: copy bootindex to OCRAM for main domain SPL
arm: mach-k3: am625: Provide a way to obtain boot device for non SPLs
board: phycore-am62x: Extend for better environment handling

 arch/arm/mach-k3/Makefile                     |   1 +
 arch/arm/mach-k3/am625_init.c                 | 103 ++----------------
 arch/arm/mach-k3/am62x/Makefile               |   2 +
 arch/arm/mach-k3/am62x/boot.c                 | 103 ++++++++++++++++++
 arch/arm/mach-k3/include/mach/am62_hardware.h |   1 +
 arch/arm/mach-k3/include/mach/hardware.h      |   1 +
 board/phytec/phycore_am62x/phycore-am62x.c    |  64 +++++++++++
 configs/phycore_am62x_a53_defconfig           |   1 +
 8 files changed, 182 insertions(+), 94 deletions(-)
 create mode 100644 arch/arm/mach-k3/am62x/Makefile
 create mode 100644 arch/arm/mach-k3/am62x/boot.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/3 arm: mach-k3: am625: copy bootindex to OCRAM for main domain SPL

Relocate booindex to OCRAM region after it gets opened by TIFS so the main domain bootloaders can have access to this data.

---
v2:
- Relocate bootindex to OCRAM, drop misleading comments and remove not needed changes

---
 arch/arm/mach-k3/am625_init.c                 | 8 ++++++++
 arch/arm/mach-k3/include/mach/am62_hardware.h | 1 +
 2 files changed, 9 insertions(+)
arch/arm/mach-k3/am625_init.c +8 -0
index 6c96e881146..c9c97b6ce19 100644
@@ -175,6 +175,14 @@ void board_init_f(ulong dummy)
 		k3_sysfw_loader(true, NULL, NULL);
 	}
 
+	/*
+	 * Relocate boot information to OCRAM (after TIFS has opend this
+	 * region for us) so the next bootloader stages can keep access to
+	 * primary vs backup bootmodes.
+	 */
+	if (IS_ENABLED(CONFIG_CPU_V7R))
+		writel(bootindex, K3_BOOT_PARAM_TABLE_INDEX_OCRAM);
+
 	/*
 	 * Force probe of clk_k3 driver here to ensure basic default clock
 	 * configuration is always done.
arch/arm/mach-k3/include/mach/am62_hardware.h +1 -0
index 54380f36e16..30c2f11062c 100644
@@ -76,6 +76,7 @@
 #define CTRLMMR_MCU_RST_CTRL			(MCU_CTRL_MMR0_BASE + 0x18170)
 
 #define ROM_EXTENDED_BOOT_DATA_INFO		0x43c3f1e0
+#define K3_BOOT_PARAM_TABLE_INDEX_OCRAM		0x7000F290
 
 #define TI_SRAM_SCRATCH_BOARD_EEPROM_START	0x43c30000
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/3 arm: mach-k3: am625: Provide a way to obtain boot device for non SPLs

In reply to Wadim Egorov

Introduce get_boot_device() to obtain the booting device. Make it also available for non SPL builds so u-boot can also know the device it is booting from.

---
v2:
- Make get_boot_device() read bootindex out of OCRAM

---
 arch/arm/mach-k3/Makefile                |   1 +
 arch/arm/mach-k3/am625_init.c            |  95 +--------------------
 arch/arm/mach-k3/am62x/Makefile          |   2 +
 arch/arm/mach-k3/am62x/boot.c            | 103 +++++++++++++++++++++++
 arch/arm/mach-k3/include/mach/hardware.h |   1 +
 5 files changed, 108 insertions(+), 94 deletions(-)
 create mode 100644 arch/arm/mach-k3/am62x/Makefile
 create mode 100644 arch/arm/mach-k3/am62x/boot.c
arch/arm/mach-k3/Makefile +1 -0
index 42161376469..61ec4ea13cf 100644
@@ -22,3 +22,4 @@ obj-$(CONFIG_SOC_K3_AM625) += am625_init.o
 obj-$(CONFIG_SOC_K3_AM62A7) += am62a7_init.o
 endif
 obj-y += common.o security.o
+obj-$(CONFIG_SOC_K3_AM625) += am62x/
arch/arm/mach-k3/am625_init.c +1 -94

101 lines not on this page · raw message

arch/arm/mach-k3/am62x/Makefile new file +2 -0
new file mode 100644
index 00000000000..acf09c3426c
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier:	GPL-2.0+
+obj-y += boot.o
arch/arm/mach-k3/am62x/boot.c new file +103 -0

103 lines not on this page · raw message

arch/arm/mach-k3/include/mach/hardware.h +1 -0
index 52ef82e70b0..81a8c612f3c 100644
@@ -96,4 +96,5 @@ struct rom_extended_boot_data {
 	u32 num_components;
 };
 
+u32 get_boot_device(void);
 #endif /* _ASM_ARCH_HARDWARE_H_ */
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/3 board: phycore-am62x: Extend for better environment handling

In reply to Wadim Egorov

Select environment location based on the device we boot from. Also, introduce a "boot" variable that represents the current boot device and can be used by scripts.

---
 board/phytec/phycore_am62x/phycore-am62x.c | 64 ++++++++++++++++++++++
 configs/phycore_am62x_a53_defconfig        |  1 +
 2 files changed, 65 insertions(+)
board/phytec/phycore_am62x/phycore-am62x.c +64 -0
index 91a24018c40..618b4c370d1 100644
@@ -57,3 +57,67 @@ void spl_board_init(void)
 	       MCU_CTRL_DEVICE_CLKOUT_32K_CTRL);
 }
 #endif
+
+#if IS_ENABLED(CONFIG_ENV_IS_IN_FAT) || IS_ENABLED(CONFIG_ENV_IS_IN_MMC)
+int mmc_get_env_dev(void)
+{
+	u32 boot_device = get_boot_device();
+
+	switch (boot_device) {
+	case BOOT_DEVICE_MMC1:
+		return 0;
+	case BOOT_DEVICE_MMC2:
+		return 1;
+	};
+
+	return CONFIG_SYS_MMC_ENV_DEV;
+}
+#endif
+
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+	u32 boot_device = get_boot_device();
+
+	if (prio)
+		return ENVL_UNKNOWN;
+
+	switch (boot_device) {
+	case BOOT_DEVICE_MMC1:
+	case BOOT_DEVICE_MMC2:
+		if (CONFIG_IS_ENABLED(ENV_IS_IN_FAT))
+			return ENVL_FAT;
+		if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
+			return ENVL_MMC;
+	case BOOT_DEVICE_SPI:
+		if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
+			return ENVL_SPI_FLASH;
+	default:
+		return ENVL_NOWHERE;
+	};
+}
+
+#if IS_ENABLED(CONFIG_BOARD_LATE_INIT)
+int board_late_init(void)
+{
+	u32 boot_device = get_boot_device();
+
+	switch (boot_device) {
+	case BOOT_DEVICE_MMC1:
+		env_set_ulong("mmcdev", 0);
+		env_set("boot", "mmc");
+		break;
+	case BOOT_DEVICE_MMC2:
+		env_set_ulong("mmcdev", 1);
+		env_set("boot", "mmc");
+		break;
+	case BOOT_DEVICE_SPI:
+		env_set("boot", "spi");
+		break;
+	case BOOT_DEVICE_ETHERNET:
+		env_set("boot", "net");
+		break;
+	};
+
+	return 0;
+}
+#endif
configs/phycore_am62x_a53_defconfig +1 -0
index ef6d08591a2..8e6f1786d81 100644
@@ -34,6 +34,7 @@ CONFIG_BOOTSTD_FULL=y
 CONFIG_SYS_BOOTM_LEN=0x800000
 CONFIG_BOOTCOMMAND="run mmcboot; bootflow scan -lb"
 CONFIG_DEFAULT_FDT_FILE="oftree"
+CONFIG_BOARD_LATE_INIT=y
 CONFIG_SPL_MAX_SIZE=0x58000
 CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
 CONFIG_SPL_BSS_START_ADDR=0x80c80000
Signature · 1 line
2.34.1
#4 lore raw
In reply to Wadim Egorov
Quoted 4 lines · Wadim Egorov

It is handy to have some u-boot environment variables set based on the current booting device.
Provide a way to obtain the boot device for non SPLs by factoring out spl_boot_device() into an own function get_boot_device().

Applied to u-boot/master now (but I seem to have missed this in b4 ty), thanks.

Signature · 1 line
Tom