Skip to contentSkip to conversation

spl: remove usage of CMD_BOOTx from image parsing

PATCH Superseded Anshul Dalal 2 participants 5 messages Apr 3, 2025

Subsystems (3)

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/4 spl: remove usage of CMD_BOOTx from image parsing

Using CMD_* configs from spl doesn't make logical sense. Therefore this patch replaces the checks for CMD_BOOTx with newly added configs SPL_HAS_BOOTx.

SPL_HAS_BOOTZ is enabled by default for 32-bit ARM systems and SPL_HAS_BOOTI is enabled by default for 64-bit ARM and RISCV.

The respective C files (image.c/zimage.c) are compiled based on library symbols LIB_BOOTx instead which are in turn selected by both CMD_BOOTx and SPL_HAS_BOOTx.

---
Tested:
* U-Boot CI: https://github.com/u-boot/u-boot/pull/757
Changes in v6:
* Add LIB_BOOTx library symbols
* Update existing configs ensuring no change in size or build failure
v5:
https://lore.kernel.org/all/[email protected]/
Changes in v5:
* Remove imply clause for CMD_BOOTZ instead add default y for
SPL_HAS_BOOTZ
* Update commit message to reflect the changes
* Remove 'More info' link
v4:
https://lore.kernel.org/u-boot/[email protected]/
Changes in v4:
* Don't set SPL_HAS_BOOTI for sandbox by default
* Updated prompts for SPL_HAS_BOOT[IZ]
* Removed check for SPL_HAS_FRAMEWORK from Makefile
v3:
https://lore.kernel.org/u-boot/[email protected]/
Changes in v3:
* Add imply clause for CMD_BOOTZ to enable SPL_HAS_BOOTZ
* Fix broken check for bootz_setup
v2:
https://lore.kernel.org/u-boot/[email protected]/
Changes in v2:
* Add SPL_HAS_BOOT[IZ] configs
v1:
https://lore.kernel.org/u-boot/[email protected]/

---
 arch/arm/lib/Makefile |  9 +++------
 cmd/Kconfig           |  2 ++
 common/spl/Kconfig    | 16 ++++++++++++++++
 common/spl/spl.c      |  5 +++--
 lib/Kconfig           |  6 ++++++
 5 files changed, 30 insertions(+), 8 deletions(-)
arch/arm/lib/Makefile +3 -6
index 1c95dd6fed2..c0a0e1dad0e 100644
@@ -7,6 +7,9 @@ lib-$(CONFIG_USE_PRIVATE_LIBGCC) += ashldi3.o ashrdi3.o lshrdi3.o \
 				    lib1funcs.o uldivmod.o div0.o \
 				    div64.o muldi3.o
 
+obj-$(CONFIG_LIB_BOOTI) += image.o
+obj-$(CONFIG_LIB_BOOTZ) += zimage.o
+
 ifdef CONFIG_CPU_V7M
 obj-y	+= vectors_m.o crt0.o
 else ifdef CONFIG_ARM64
@@ -30,15 +33,9 @@ endif
 
 obj-$(CONFIG_CPU_V7M) += cmd_boot.o
 obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
-obj-$(CONFIG_CMD_BOOTI) += bootm.o image.o
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
-obj-$(CONFIG_CMD_BOOTZ) += bootm.o zimage.o
 else
 obj-$(CONFIG_$(PHASE_)FRAMEWORK) += spl.o
-ifdef CONFIG_SPL_FRAMEWORK
-obj-$(CONFIG_CMD_BOOTI) += image.o
-obj-$(CONFIG_CMD_BOOTZ) += zimage.o
-endif
 obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
 endif
 ifdef CONFIG_ARM64
cmd/Kconfig +2 -0
index 642cc1116e8..45224f1ae21 100644
@@ -352,6 +352,7 @@ config BOOTM_ELF
 
 config CMD_BOOTZ
 	bool "bootz"
+	select LIB_BOOTZ
 	help
 	  Boot the Linux zImage
 
@@ -359,6 +360,7 @@ config CMD_BOOTI
 	bool "booti"
 	depends on ARM64 || RISCV || SANDBOX
 	default y
+	select LIB_BOOTI
 	help
 	  Boot an AArch64 Linux Kernel image from memory.
 
common/spl/Kconfig +16 -0
index 94e118f8465..7d7fd37cac6 100644
@@ -1153,6 +1153,22 @@ config SPL_OS_BOOT
 	  Enable booting directly to an OS from SPL.
 	  for more info read doc/README.falcon
 
+config SPL_HAS_BOOTZ
+	bool "Allow booting a zImage style Linux kernel from SPL"
+	depends on SPL_OS_BOOT
+	default y if ARM && !ARM64
+	select LIB_BOOTZ
+	help
+	  Boot a linux zimage from memory in falcon boot.
+
+config SPL_HAS_BOOTI
+	bool "Allow booting an Image style Linux kernel from SPL"
+	depends on SPL_OS_BOOT
+	default y if ARM64 || RISCV
+	select LIB_BOOTI
+	help
+	  Boot an uncompressed linux kernel image from memory in falcon boot.
+
 config SPL_PAYLOAD_ARGS_ADDR
 	hex "Address in memory to load 'args' file for Falcon Mode to"
 	depends on SPL_OS_BOOT || SPL_LOAD_FIT_OPENSBI_OS_BOOT
common/spl/spl.c +3 -2
index 76fd56dfe4b..445c3ef24fe 100644
@@ -335,7 +335,7 @@ int spl_parse_image_header(struct spl_image_info *spl_image,
 		panic("** no mkimage signature but raw image not supported");
 	}
 
-	if (CONFIG_IS_ENABLED(OS_BOOT) && IS_ENABLED(CONFIG_CMD_BOOTI)) {
+	if (CONFIG_IS_ENABLED(OS_BOOT) && IS_ENABLED(CONFIG_SPL_HAS_BOOTI)) {
 		ulong start, size;
 
 		if (!booti_setup((ulong)header, &start, &size, 0)) {
@@ -349,7 +349,8 @@ int spl_parse_image_header(struct spl_image_info *spl_image,
 			      spl_image->load_addr, spl_image->size);
 			return 0;
 		}
-	} else if (CONFIG_IS_ENABLED(OS_BOOT) && IS_ENABLED(CONFIG_CMD_BOOTZ)) {
+	} else if (CONFIG_IS_ENABLED(OS_BOOT) &&
+		   IS_ENABLED(CONFIG_SPL_HAS_BOOTZ)) {
 		ulong start, end;
 
 		if (!bootz_setup((ulong)header, &start, &end)) {
lib/Kconfig +6 -0
index 1a683dea670..8c39b3af7ad 100644
@@ -1202,6 +1202,12 @@ config TEST_FDTDEC
 	bool "enable fdtdec test"
 	depends on OF_LIBFDT
 
+config LIB_BOOTI
+	bool
+
+config LIB_BOOTZ
+	bool
+
 config LIB_DATE
 	bool
 
Signature · 1 line
2.49.0
#1 lore raw

PATCH v6 2/4 configs: disable SPL_HAS_BOOTZ to preserve spl size

In the existing behaviour, CMD_BOOTZ is not enabled by default which means zimage.o is not compiled in the SPL in falcon mode unless explicitly enabled. This changes now as SPL_HAS_BOOTZ is default y which leads to larger SPL size with zimage.o being present.

This patch modifies the defconfigs that used falcon mode but don't require zimage support.

---
 configs/imx28_xea_defconfig          | 1 +
 configs/imx6qdl_icore_mipi_defconfig | 1 +
 configs/imx6qdl_icore_mmc_defconfig  | 1 +
 configs/imx6qdl_icore_rqs_defconfig  | 1 +
 4 files changed, 4 insertions(+)
configs/imx28_xea_defconfig +1 -0
index 38282e6ea92..216b9f0fe78 100644
@@ -128,3 +128,4 @@ CONFIG_DM_SPI=y
 CONFIG_MXS_SPI=y
 CONFIG_SPL_CRC8=y
 # CONFIG_SPL_OF_LIBFDT is not set
+CONFIG_SPL_HAS_BOOTZ=n
configs/imx6qdl_icore_mipi_defconfig +1 -0
index cf4c2d9c6f1..65cded5bff3 100644
@@ -74,3 +74,4 @@ CONFIG_PINCTRL_IMX6=y
 CONFIG_DM_SERIAL=y
 CONFIG_MXC_UART=y
 CONFIG_IMX_THERMAL=y
+CONFIG_SPL_HAS_BOOTZ=n
configs/imx6qdl_icore_mmc_defconfig +1 -0
index fb0787d1beb..0ce3de92079 100644
@@ -101,3 +101,4 @@ CONFIG_SPLASH_SCREEN=y
 CONFIG_SPLASH_SCREEN_ALIGN=y
 CONFIG_BMP_16BPP=y
 CONFIG_IMX_WATCHDOG=y
+CONFIG_SPL_HAS_BOOTZ=n
configs/imx6qdl_icore_rqs_defconfig +1 -0
index 49feb1af830..d0967096379 100644
@@ -71,3 +71,4 @@ CONFIG_PINCTRL=y
 CONFIG_PINCTRL_IMX6=y
 CONFIG_DM_SERIAL=y
 CONFIG_MXC_UART=y
+CONFIG_SPL_HAS_BOOTZ=n
Signature · 1 line
2.49.0
#2 lore raw

PATCH v6 3/4 configs: migrate falcon configs to SPL_HAS_BOOTx

In reply to Anshul Dalal

Replace usage of CMD_BOOTx in falcon mode configs with the newly added SPL_HAS_BOOTx.

---
 configs/display5_defconfig         | 2 +-
 configs/display5_factory_defconfig | 2 +-
 configs/gwventana_emmc_defconfig   | 2 +-
 configs/gwventana_nand_defconfig   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
configs/display5_defconfig +1 -1
index 765920bd5d1..c3012f1dce6 100644
@@ -56,7 +56,7 @@ CONFIG_SYS_SPI_U_BOOT_OFFS=0x20000
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="display5 > "
 CONFIG_SYS_MAXARGS=32
-CONFIG_CMD_BOOTZ=y
+CONFIG_SPL_HAS_BOOTZ=y
 # CONFIG_CMD_ELF is not set
 CONFIG_CMD_SPL=y
 CONFIG_CMD_ASKENV=y
configs/display5_factory_defconfig +1 -1
index 4007c8900ce..b9137969a15 100644
@@ -51,7 +51,7 @@ CONFIG_SYS_SPI_U_BOOT_OFFS=0x20000
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="display5 factory > "
 CONFIG_SYS_MAXARGS=32
-CONFIG_CMD_BOOTZ=y
+CONFIG_SPL_HAS_BOOTZ=y
 # CONFIG_CMD_ELF is not set
 CONFIG_CMD_SPL=y
 CONFIG_CMD_ASKENV=y
configs/gwventana_emmc_defconfig +1 -1
index 95d5b1172ff..e7bf0ecfab8 100644
@@ -59,7 +59,7 @@ CONFIG_SPL_POWER=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="Ventana > "
 CONFIG_SYS_MAXARGS=32
-CONFIG_CMD_BOOTZ=y
+CONFIG_SPL_HAS_BOOTZ=y
 CONFIG_CMD_SPL_WRITE_SIZE=0x20000
 CONFIG_CMD_UNZIP=y
 CONFIG_CMD_GPIO=y
configs/gwventana_nand_defconfig +1 -1
index 1d8af5ce103..30462953263 100644
@@ -61,7 +61,7 @@ CONFIG_SPL_POWER=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="Ventana > "
 CONFIG_SYS_MAXARGS=32
-CONFIG_CMD_BOOTZ=y
+CONFIG_SPL_HAS_BOOTZ=y
 CONFIG_CMD_SPL_NAND_OFS=0x1100000
 CONFIG_CMD_SPL_WRITE_SIZE=0x20000
 CONFIG_CMD_UNZIP=y
Signature · 1 line
2.49.0
#3 lore raw

PATCH v6 4/4 configs: colibri_vf: set CMD_BOOTM

In reply to Anshul Dalal

Currently, CMD_BOOTx selects both bootm.o and the respective image.o or zimage.o for compilation. After the addition of LIB_BOOTx, the behaviour changes so CMD_BOOTx would not select bootm.o. This leads to build failure on calibri_vf since it unsets BOOTM wile still using BOOTZ.

This was added in commit c5954431eb6c ("configs: colibri_vf: disable obscure options") to save size but unsetting BOOTM specifically does not seem to save any space.

---
 configs/colibri_vf_defconfig | 1 -
 1 file changed, 1 deletion(-)
configs/colibri_vf_defconfig +0 -1
index 3a806243b19..823b4f07460 100644
@@ -34,7 +34,6 @@ CONFIG_HUSH_PARSER=y
 # CONFIG_SYS_LONGHELP is not set
 CONFIG_SYS_PROMPT="Colibri VFxx # "
 # CONFIG_CMD_BOOTD is not set
-# CONFIG_CMD_BOOTM is not set
 CONFIG_CMD_BOOTZ=y
 # CONFIG_CMD_ELF is not set
 # CONFIG_CMD_IMI is not set
Signature · 1 line
2.49.0
#4 lore raw
In reply to Anshul Dalal

Hi Anshul,

Quoted 43 lines · Anshul Dalal

Using CMD_* configs from spl doesn't make logical sense. Therefore this patch replaces the checks for CMD_BOOTx with newly added configs SPL_HAS_BOOTx.

SPL_HAS_BOOTZ is enabled by default for 32-bit ARM systems and SPL_HAS_BOOTI is enabled by default for 64-bit ARM and RISCV.

The respective C files (image.c/zimage.c) are compiled based on library symbols LIB_BOOTx instead which are in turn selected by both CMD_BOOTx and SPL_HAS_BOOTx.

---
Tested:
* U-Boot CI: https://github.com/u-boot/u-boot/pull/757
Changes in v6:
* Add LIB_BOOTx library symbols
* Update existing configs ensuring no change in size or build failure
v5:
https://lore.kernel.org/all/[email protected]/
Changes in v5:
* Remove imply clause for CMD_BOOTZ instead add default y for
SPL_HAS_BOOTZ
* Update commit message to reflect the changes
* Remove 'More info' link
v4:
https://lore.kernel.org/u-boot/[email protected]/
Changes in v4:
* Don't set SPL_HAS_BOOTI for sandbox by default
* Updated prompts for SPL_HAS_BOOT[IZ]
* Removed check for SPL_HAS_FRAMEWORK from Makefile
v3:
https://lore.kernel.org/u-boot/[email protected]/
Changes in v3:
* Add imply clause for CMD_BOOTZ to enable SPL_HAS_BOOTZ
* Fix broken check for bootz_setup
v2:
https://lore.kernel.org/u-boot/[email protected]/
Changes in v2:
* Add SPL_HAS_BOOT[IZ] configs
v1:
https://lore.kernel.org/u-boot/[email protected]/

Quoted 8 lines
---
 arch/arm/lib/Makefile |  9 +++------
 cmd/Kconfig           |  2 ++
 common/spl/Kconfig    | 16 ++++++++++++++++
 common/spl/spl.c      |  5 +++--
 lib/Kconfig           |  6 ++++++
 5 files changed, 30 insertions(+), 8 deletions(-)

I'm sorry that I am late to the party.

But you should start by creating BOOTM, BOOTI, etc. and select them from CMD_BOOTM, etc.

Then you can create SPL_BOOTM, SPL_BOOTI, etc.

Then we can use CONFIG_IS_ENABLED(BOOTM)

LIB_BOOTx doesn't really make any sense, this the code is in boot/ , not /lib

Also, HAS_BOOTZ doesn't make any sense either. We use HAS_ or HAVE for things which could be enabled (with a separate option) if the user wants them enabled; they should not be used to actually enable something.

Also, please check if this conflicts with my PXE series[1], part of which Tom has so far not been willing to apply.

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=435516&state=*