* [PATCH v2 0/3] *** Introduce get_boot_device() for K3 platform ***
@ 2024-04-03 13:59 Wadim Egorov
2024-04-03 13:59 ` [PATCH v2 1/3] arm: mach-k3: am625: copy bootindex to OCRAM for main domain SPL Wadim Egorov
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Wadim Egorov @ 2024-04-03 13:59 UTC (permalink / raw)
To: u-boot; +Cc: nm, upstream, bb, vigneshr
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
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] arm: mach-k3: am625: copy bootindex to OCRAM for main domain SPL
2024-04-03 13:59 [PATCH v2 0/3] *** Introduce get_boot_device() for K3 platform *** Wadim Egorov
@ 2024-04-03 13:59 ` Wadim Egorov
2024-04-03 13:59 ` [PATCH v2 2/3] arm: mach-k3: am625: Provide a way to obtain boot device for non SPLs Wadim Egorov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Wadim Egorov @ 2024-04-03 13:59 UTC (permalink / raw)
To: u-boot; +Cc: nm, upstream, bb, vigneshr
Relocate booindex to OCRAM region after it gets opened by TIFS so
the main domain bootloaders can have access to this data.
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
---
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(+)
diff --git a/arch/arm/mach-k3/am625_init.c b/arch/arm/mach-k3/am625_init.c
index 6c96e881146..c9c97b6ce19 100644
--- a/arch/arm/mach-k3/am625_init.c
+++ b/arch/arm/mach-k3/am625_init.c
@@ -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.
diff --git a/arch/arm/mach-k3/include/mach/am62_hardware.h b/arch/arm/mach-k3/include/mach/am62_hardware.h
index 54380f36e16..30c2f11062c 100644
--- a/arch/arm/mach-k3/include/mach/am62_hardware.h
+++ b/arch/arm/mach-k3/include/mach/am62_hardware.h
@@ -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
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] arm: mach-k3: am625: Provide a way to obtain boot device for non SPLs
2024-04-03 13:59 [PATCH v2 0/3] *** Introduce get_boot_device() for K3 platform *** Wadim Egorov
2024-04-03 13:59 ` [PATCH v2 1/3] arm: mach-k3: am625: copy bootindex to OCRAM for main domain SPL Wadim Egorov
@ 2024-04-03 13:59 ` Wadim Egorov
2024-04-03 13:59 ` [PATCH v2 3/3] board: phycore-am62x: Extend for better environment handling Wadim Egorov
2024-04-12 14:52 ` [PATCH v2 0/3] *** Introduce get_boot_device() for K3 platform *** Tom Rini
3 siblings, 0 replies; 5+ messages in thread
From: Wadim Egorov @ 2024-04-03 13:59 UTC (permalink / raw)
To: u-boot; +Cc: nm, upstream, bb, vigneshr
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.
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
---
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
diff --git a/arch/arm/mach-k3/Makefile b/arch/arm/mach-k3/Makefile
index 42161376469..61ec4ea13cf 100644
--- a/arch/arm/mach-k3/Makefile
+++ b/arch/arm/mach-k3/Makefile
@@ -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/
diff --git a/arch/arm/mach-k3/am625_init.c b/arch/arm/mach-k3/am625_init.c
index c9c97b6ce19..56078099f09 100644
--- a/arch/arm/mach-k3/am625_init.c
+++ b/arch/arm/mach-k3/am625_init.c
@@ -243,100 +243,7 @@ u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
}
}
-static u32 __get_backup_bootmedia(u32 devstat)
-{
- u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
- MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
- u32 bkup_bootmode_cfg =
- (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
- MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
-
- switch (bkup_bootmode) {
- case BACKUP_BOOT_DEVICE_UART:
- return BOOT_DEVICE_UART;
-
- case BACKUP_BOOT_DEVICE_USB:
- return BOOT_DEVICE_USB;
-
- case BACKUP_BOOT_DEVICE_ETHERNET:
- return BOOT_DEVICE_ETHERNET;
-
- case BACKUP_BOOT_DEVICE_MMC:
- if (bkup_bootmode_cfg)
- return BOOT_DEVICE_MMC2;
- return BOOT_DEVICE_MMC1;
-
- case BACKUP_BOOT_DEVICE_SPI:
- return BOOT_DEVICE_SPI;
-
- case BACKUP_BOOT_DEVICE_I2C:
- return BOOT_DEVICE_I2C;
-
- case BACKUP_BOOT_DEVICE_DFU:
- if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
- return BOOT_DEVICE_USB;
- return BOOT_DEVICE_DFU;
- };
-
- return BOOT_DEVICE_RAM;
-}
-
-static u32 __get_primary_bootmedia(u32 devstat)
-{
- u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
- MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
- u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
- MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
-
- switch (bootmode) {
- case BOOT_DEVICE_OSPI:
- fallthrough;
- case BOOT_DEVICE_QSPI:
- fallthrough;
- case BOOT_DEVICE_XSPI:
- fallthrough;
- case BOOT_DEVICE_SPI:
- return BOOT_DEVICE_SPI;
-
- case BOOT_DEVICE_ETHERNET_RGMII:
- fallthrough;
- case BOOT_DEVICE_ETHERNET_RMII:
- return BOOT_DEVICE_ETHERNET;
-
- case BOOT_DEVICE_EMMC:
- return BOOT_DEVICE_MMC1;
-
- case BOOT_DEVICE_MMC:
- if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
- MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
- return BOOT_DEVICE_MMC2;
- return BOOT_DEVICE_MMC1;
-
- case BOOT_DEVICE_DFU:
- if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
- MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
- return BOOT_DEVICE_USB;
- return BOOT_DEVICE_DFU;
-
- case BOOT_DEVICE_NOBOOT:
- return BOOT_DEVICE_RAM;
- }
-
- return bootmode;
-}
-
u32 spl_boot_device(void)
{
- u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
- u32 bootmedia;
-
- if (bootindex == K3_PRIMARY_BOOTMODE)
- bootmedia = __get_primary_bootmedia(devstat);
- else
- bootmedia = __get_backup_bootmedia(devstat);
-
- debug("am625_init: %s: devstat = 0x%x bootmedia = 0x%x bootindex = %d\n",
- __func__, devstat, bootmedia, bootindex);
-
- return bootmedia;
+ return get_boot_device();
}
diff --git a/arch/arm/mach-k3/am62x/Makefile b/arch/arm/mach-k3/am62x/Makefile
new file mode 100644
index 00000000000..acf09c3426c
--- /dev/null
+++ b/arch/arm/mach-k3/am62x/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0+
+obj-y += boot.o
diff --git a/arch/arm/mach-k3/am62x/boot.c b/arch/arm/mach-k3/am62x/boot.c
new file mode 100644
index 00000000000..132b42f7edb
--- /dev/null
+++ b/arch/arm/mach-k3/am62x/boot.c
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0+
+#include <asm/io.h>
+#include <asm/arch/hardware.h>
+#include <asm/arch/am62_spl.h>
+
+static u32 __get_backup_bootmedia(u32 devstat)
+{
+ u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
+ MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
+ u32 bkup_bootmode_cfg =
+ (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
+ MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
+
+ switch (bkup_bootmode) {
+ case BACKUP_BOOT_DEVICE_UART:
+ return BOOT_DEVICE_UART;
+
+ case BACKUP_BOOT_DEVICE_USB:
+ return BOOT_DEVICE_USB;
+
+ case BACKUP_BOOT_DEVICE_ETHERNET:
+ return BOOT_DEVICE_ETHERNET;
+
+ case BACKUP_BOOT_DEVICE_MMC:
+ if (bkup_bootmode_cfg)
+ return BOOT_DEVICE_MMC2;
+ return BOOT_DEVICE_MMC1;
+
+ case BACKUP_BOOT_DEVICE_SPI:
+ return BOOT_DEVICE_SPI;
+
+ case BACKUP_BOOT_DEVICE_I2C:
+ return BOOT_DEVICE_I2C;
+
+ case BACKUP_BOOT_DEVICE_DFU:
+ if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
+ return BOOT_DEVICE_USB;
+ return BOOT_DEVICE_DFU;
+ };
+
+ return BOOT_DEVICE_RAM;
+}
+
+static u32 __get_primary_bootmedia(u32 devstat)
+{
+ u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
+ MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
+ u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
+ MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
+
+ switch (bootmode) {
+ case BOOT_DEVICE_OSPI:
+ fallthrough;
+ case BOOT_DEVICE_QSPI:
+ fallthrough;
+ case BOOT_DEVICE_XSPI:
+ fallthrough;
+ case BOOT_DEVICE_SPI:
+ return BOOT_DEVICE_SPI;
+
+ case BOOT_DEVICE_ETHERNET_RGMII:
+ fallthrough;
+ case BOOT_DEVICE_ETHERNET_RMII:
+ return BOOT_DEVICE_ETHERNET;
+
+ case BOOT_DEVICE_EMMC:
+ return BOOT_DEVICE_MMC1;
+
+ case BOOT_DEVICE_MMC:
+ if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
+ MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
+ return BOOT_DEVICE_MMC2;
+ return BOOT_DEVICE_MMC1;
+
+ case BOOT_DEVICE_DFU:
+ if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
+ MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
+ return BOOT_DEVICE_USB;
+ return BOOT_DEVICE_DFU;
+
+ case BOOT_DEVICE_NOBOOT:
+ return BOOT_DEVICE_RAM;
+ }
+
+ return bootmode;
+}
+
+u32 get_boot_device(void)
+{
+ u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
+ u32 bootmode = *(u32 *)(K3_BOOT_PARAM_TABLE_INDEX_OCRAM);
+ u32 bootmedia;
+
+ if (bootmode == K3_PRIMARY_BOOTMODE)
+ bootmedia = __get_primary_bootmedia(devstat);
+ else
+ bootmedia = __get_backup_bootmedia(devstat);
+
+ debug("%s: devstat = 0x%x bootmedia = 0x%x bootmode = %d\n",
+ __func__, devstat, bootmedia, bootmode);
+
+ return bootmedia;
+}
diff --git a/arch/arm/mach-k3/include/mach/hardware.h b/arch/arm/mach-k3/include/mach/hardware.h
index 52ef82e70b0..81a8c612f3c 100644
--- a/arch/arm/mach-k3/include/mach/hardware.h
+++ b/arch/arm/mach-k3/include/mach/hardware.h
@@ -96,4 +96,5 @@ struct rom_extended_boot_data {
u32 num_components;
};
+u32 get_boot_device(void);
#endif /* _ASM_ARCH_HARDWARE_H_ */
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] board: phycore-am62x: Extend for better environment handling
2024-04-03 13:59 [PATCH v2 0/3] *** Introduce get_boot_device() for K3 platform *** Wadim Egorov
2024-04-03 13:59 ` [PATCH v2 1/3] arm: mach-k3: am625: copy bootindex to OCRAM for main domain SPL Wadim Egorov
2024-04-03 13:59 ` [PATCH v2 2/3] arm: mach-k3: am625: Provide a way to obtain boot device for non SPLs Wadim Egorov
@ 2024-04-03 13:59 ` Wadim Egorov
2024-04-12 14:52 ` [PATCH v2 0/3] *** Introduce get_boot_device() for K3 platform *** Tom Rini
3 siblings, 0 replies; 5+ messages in thread
From: Wadim Egorov @ 2024-04-03 13:59 UTC (permalink / raw)
To: u-boot; +Cc: nm, upstream, bb, vigneshr
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.
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
---
board/phytec/phycore_am62x/phycore-am62x.c | 64 ++++++++++++++++++++++
configs/phycore_am62x_a53_defconfig | 1 +
2 files changed, 65 insertions(+)
diff --git a/board/phytec/phycore_am62x/phycore-am62x.c b/board/phytec/phycore_am62x/phycore-am62x.c
index 91a24018c40..618b4c370d1 100644
--- a/board/phytec/phycore_am62x/phycore-am62x.c
+++ b/board/phytec/phycore_am62x/phycore-am62x.c
@@ -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
diff --git a/configs/phycore_am62x_a53_defconfig b/configs/phycore_am62x_a53_defconfig
index ef6d08591a2..8e6f1786d81 100644
--- a/configs/phycore_am62x_a53_defconfig
+++ b/configs/phycore_am62x_a53_defconfig
@@ -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
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] *** Introduce get_boot_device() for K3 platform ***
2024-04-03 13:59 [PATCH v2 0/3] *** Introduce get_boot_device() for K3 platform *** Wadim Egorov
` (2 preceding siblings ...)
2024-04-03 13:59 ` [PATCH v2 3/3] board: phycore-am62x: Extend for better environment handling Wadim Egorov
@ 2024-04-12 14:52 ` Tom Rini
3 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2024-04-12 14:52 UTC (permalink / raw)
To: Wadim Egorov; +Cc: u-boot, nm, upstream, bb, vigneshr
[-- Attachment #1: Type: text/plain, Size: 396 bytes --]
On Wed, Apr 03, 2024 at 03:59:08PM +0200, Wadim Egorov wrote:
> 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.
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-12 14:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-03 13:59 [PATCH v2 0/3] *** Introduce get_boot_device() for K3 platform *** Wadim Egorov
2024-04-03 13:59 ` [PATCH v2 1/3] arm: mach-k3: am625: copy bootindex to OCRAM for main domain SPL Wadim Egorov
2024-04-03 13:59 ` [PATCH v2 2/3] arm: mach-k3: am625: Provide a way to obtain boot device for non SPLs Wadim Egorov
2024-04-03 13:59 ` [PATCH v2 3/3] board: phycore-am62x: Extend for better environment handling Wadim Egorov
2024-04-12 14:52 ` [PATCH v2 0/3] *** Introduce get_boot_device() for K3 platform *** Tom Rini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox