[PATCH v2 1/1] xilinx: Add option to load environment from outside of boot media

Vasileios Amoiridis vassilisamir at gmail.com
Mon Jun 3 18:47:38 CEST 2024


From: Vasileios Amoiridis <vasileios.amoiridis at cern.ch>

Currently, if the environment is not in the current boot media, the
env_get_location() is returning ENVL_UNKNOWN or ENVL_NOWHERE which
is not true (i.e booting from FLASH with environment in eMMC). This
commit adds an extra check to find the environment in the other
supported boot media, keeping the same priority as of now.

Signed-off-by: Vasileios Amoiridis <vasileios.amoiridis at cern.ch>
---
 board/xilinx/versal-net/board.c | 47 ++++++++++++++--------------
 board/xilinx/versal/board.c     | 47 ++++++++++++++--------------
 board/xilinx/zynq/board.c       | 49 +++++++++++++++--------------
 board/xilinx/zynqmp/zynqmp.c    | 55 +++++++++++++++++----------------
 4 files changed, 101 insertions(+), 97 deletions(-)

diff --git a/board/xilinx/versal-net/board.c b/board/xilinx/versal-net/board.c
index da03024e16..5295221aaa 100644
--- a/board/xilinx/versal-net/board.c
+++ b/board/xilinx/versal-net/board.c
@@ -377,29 +377,30 @@ enum env_location env_get_location(enum env_operation op, int prio)
 {
 	u8 bootmode = versal_net_get_bootmode();
 
-	if (prio)
-		return ENVL_UNKNOWN;
-
-	switch (bootmode) {
-	case EMMC_MODE:
-	case SD_MODE:
-	case SD1_LSHFT_MODE:
-	case SD_MODE1:
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
-			return ENVL_FAT;
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
-			return ENVL_EXT4;
-		return ENVL_NOWHERE;
-	case OSPI_MODE:
-	case QSPI_MODE_24BIT:
-	case QSPI_MODE_32BIT:
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
-			return ENVL_SPI_FLASH;
-		return ENVL_NOWHERE;
-	case JTAG_MODE:
-	case SELECTMAP_MODE:
-	default:
-		return ENVL_NOWHERE;
+	if (!prio) {
+		switch (bootmode) {
+		case EMMC_MODE:
+		case SD_MODE:
+		case SD1_LSHFT_MODE:
+		case SD_MODE1:
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
+				return ENVL_FAT;
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
+				return ENVL_EXT4;
+			break;
+		case OSPI_MODE:
+		case QSPI_MODE_24BIT:
+		case QSPI_MODE_32BIT:
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
+				return ENVL_SPI_FLASH;
+			break;
+		case JTAG_MODE:
+		case SELECTMAP_MODE:
+		default:
+			return ENVL_NOWHERE;
+		}
 	}
+
+	return arch_env_get_location(op, prio);
 }
 #endif
diff --git a/board/xilinx/versal/board.c b/board/xilinx/versal/board.c
index 4f6d56119d..4201c3e2ef 100644
--- a/board/xilinx/versal/board.c
+++ b/board/xilinx/versal/board.c
@@ -296,29 +296,30 @@ enum env_location env_get_location(enum env_operation op, int prio)
 {
 	u32 bootmode = versal_get_bootmode();
 
-	if (prio)
-		return ENVL_UNKNOWN;
-
-	switch (bootmode) {
-	case EMMC_MODE:
-	case SD_MODE:
-	case SD1_LSHFT_MODE:
-	case SD_MODE1:
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
-			return ENVL_FAT;
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
-			return ENVL_EXT4;
-		return ENVL_NOWHERE;
-	case OSPI_MODE:
-	case QSPI_MODE_24BIT:
-	case QSPI_MODE_32BIT:
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
-			return ENVL_SPI_FLASH;
-		return ENVL_NOWHERE;
-	case JTAG_MODE:
-	case SELECTMAP_MODE:
-	default:
-		return ENVL_NOWHERE;
+	if (!prio) {
+		switch (bootmode) {
+		case EMMC_MODE:
+		case SD_MODE:
+		case SD1_LSHFT_MODE:
+		case SD_MODE1:
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
+				return ENVL_FAT;
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
+				return ENVL_EXT4;
+			break;
+		case OSPI_MODE:
+		case QSPI_MODE_24BIT:
+		case QSPI_MODE_32BIT:
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
+				return ENVL_SPI_FLASH;
+			break;
+		case JTAG_MODE:
+		case SELECTMAP_MODE:
+		default:
+			return ENVL_NOWHERE;
+		}
 	}
+
+	return arch_env_get_location(op, prio);
 }
 #endif
diff --git a/board/xilinx/zynq/board.c b/board/xilinx/zynq/board.c
index 6c36591001..4c9923de18 100644
--- a/board/xilinx/zynq/board.c
+++ b/board/xilinx/zynq/board.c
@@ -138,31 +138,32 @@ enum env_location env_get_location(enum env_operation op, int prio)
 {
 	u32 bootmode = zynq_slcr_get_boot_mode() & ZYNQ_BM_MASK;
 
-	if (prio)
-		return ENVL_UNKNOWN;
-
-	switch (bootmode) {
-	case ZYNQ_BM_SD:
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
-			return ENVL_FAT;
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
-			return ENVL_EXT4;
-		return ENVL_NOWHERE;
-	case ZYNQ_BM_NAND:
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
-			return ENVL_NAND;
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
-			return ENVL_UBI;
-		return ENVL_NOWHERE;
-	case ZYNQ_BM_NOR:
-	case ZYNQ_BM_QSPI:
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
-			return ENVL_SPI_FLASH;
-		return ENVL_NOWHERE;
-	case ZYNQ_BM_JTAG:
-	default:
-		return ENVL_NOWHERE;
+	if (!prio) {
+		switch (bootmode) {
+		case ZYNQ_BM_SD:
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
+				return ENVL_FAT;
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
+				return ENVL_EXT4;
+			break;
+		case ZYNQ_BM_NAND:
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
+				return ENVL_NAND;
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
+				return ENVL_UBI;
+			break;
+		case ZYNQ_BM_NOR:
+		case ZYNQ_BM_QSPI:
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
+				return ENVL_SPI_FLASH;
+			break;
+		case ZYNQ_BM_JTAG:
+		default:
+			return ENVL_NOWHERE;
+		}
 	}
+
+	return arch_env_get_location(op, prio);
 }
 
 #if defined(CONFIG_SET_DFU_ALT_INFO)
diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index f370fb7347..b610668d28 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -593,34 +593,35 @@ enum env_location env_get_location(enum env_operation op, int prio)
 {
 	u32 bootmode = zynqmp_get_bootmode();
 
-	if (prio)
-		return ENVL_UNKNOWN;
-
-	switch (bootmode) {
-	case EMMC_MODE:
-	case SD_MODE:
-	case SD1_LSHFT_MODE:
-	case SD_MODE1:
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
-			return ENVL_FAT;
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
-			return ENVL_EXT4;
-		return ENVL_NOWHERE;
-	case NAND_MODE:
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
-			return ENVL_NAND;
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
-			return ENVL_UBI;
-		return ENVL_NOWHERE;
-	case QSPI_MODE_24BIT:
-	case QSPI_MODE_32BIT:
-		if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
-			return ENVL_SPI_FLASH;
-		return ENVL_NOWHERE;
-	case JTAG_MODE:
-	default:
-		return ENVL_NOWHERE;
+	if (!prio) {
+		switch (bootmode) {
+		case EMMC_MODE:
+		case SD_MODE:
+		case SD1_LSHFT_MODE:
+		case SD_MODE1:
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
+				return ENVL_FAT;
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
+				return ENVL_EXT4;
+			break;
+		case NAND_MODE:
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
+				return ENVL_NAND;
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
+				return ENVL_UBI;
+			break;
+		case QSPI_MODE_24BIT:
+		case QSPI_MODE_32BIT:
+			if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
+				return ENVL_SPI_FLASH;
+			break;
+		case JTAG_MODE:
+		default:
+			return ENVL_NOWHERE;
+		}
 	}
+
+	return arch_env_get_location(op, prio);
 }
 #endif
 
-- 
2.34.1



More information about the U-Boot mailing list