Skip to contentSkip to conversation

test: Quote variables in 'test -n' expressions across boards

PATCH In review Simon Glass 5 participants 12 messages May 3 – May 14 Arm i.MX and Layerscape

lore
Share & tools
lore
#0 lore raw

cover test: Quote variables in 'test -n' expressions across boards

Several boards use 'test -n ${var}' (unquoted) in env scripts to detect an empty variable and trigger a fallback or skip a hook. That works only because of a U-Boot 'test' quirk where calls with argc < 3 returned false; an empty variable made the expression 'test -n' (one operand) and hit that path.

8b0619579b22 ("cmd: test: fix handling of single-argument form of test") aligned 'test' with POSIX so those expressions flipped to true. f7e7c55e53e8 ("cmd: test: add bug-compatibility special case for 'test -n'") restored the old behaviour for the exact 'test -n' (one arg) case, so the boards are not broken at runtime today, but the reliance on a bug-compat path isn't great.

This series updates various boards to quote each affected variable so the emptiness check is explicit and does not depend on the special-case path.

Each commit carries a Fixes: tag pointing at 8b0619579b22

Simon Glass (6):
toradex: Quote fdtfile in preboot test
ti: Quote board_init in ti_common.env
siemens: Quote A/B flags in env tests
beaglev_fire: Quote no_of_overlays in design test
mccmon6: Quote recovery_status in bootcmd test
aristainetos2: Quote rescue_reason in rescueboot test

 configs/apalis-imx8_defconfig          |  2 +-
 configs/apalis_imx6_defconfig          |  2 +-
 configs/colibri-imx6ull-emmc_defconfig |  2 +-
 configs/colibri-imx6ull_defconfig      |  2 +-
 configs/colibri-imx8x_defconfig        |  2 +-
 configs/colibri_imx6_defconfig         |  2 +-
 configs/colibri_imx7_defconfig         |  2 +-
 configs/colibri_imx7_emmc_defconfig    |  2 +-
 configs/colibri_vf_defconfig           |  2 +-
 configs/toradex-smarc-imx8mp_defconfig |  2 +-
 configs/toradex-smarc-imx95_defconfig  |  2 +-
 configs/verdin-am62_a53_defconfig      |  2 +-
 configs/verdin-am62p_a53_defconfig     |  2 +-
 configs/verdin-imx8mm_defconfig        |  2 +-
 configs/verdin-imx8mp_defconfig        |  2 +-
 include/configs/aristainetos2.h        |  2 +-
 include/configs/beaglev_fire.h         |  2 +-
 include/configs/draco-etamin.h         |  4 ++--
 include/configs/mccmon6.h              |  2 +-
 include/configs/siemens-am33x-common.h | 12 ++++++------
 include/configs/siemens-env-common.h   |  8 ++++----
 include/env/ti/ti_common.env           |  2 +-
 22 files changed, 31 insertions(+), 31 deletions(-)

---
base-commit: bb0f3eebb3c196d9b6efbbd1e5aa9b16abbb9ad6
branch: env-test-us

Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/6 toradex: Quote fdtfile in preboot test

The 15 Toradex defconfigs (apalis-imx8, apalis_imx6, the colibri imx6/imx6ull/imx7/imx8x/vf families, the toradex-smarc-imx8mp/imx95 boards and the verdin am62/am62p/imx8mm/imx8mp boards) all carry the same preboot expression:

    test -n ${fdtfile} || setenv fdtfile ...

When fdtfile is empty, the unquoted variable expands to nothing and the command becomes 'test -n' with no operand, relying on a U-Boot 'test' quirk that treats a missing operand as false so the '||' fallback runs and sets the DTB name.

Quote the variable so an empty fdtfile expands to 'test -n ""' (two operands, three argv) and the emptiness check is explicit.

Fixes 8b0619579b22 ("cmd: test: fix handling of single-argument form of test")

---

 configs/apalis-imx8_defconfig          | 2 +-
 configs/apalis_imx6_defconfig          | 2 +-
 configs/colibri-imx6ull-emmc_defconfig | 2 +-
 configs/colibri-imx6ull_defconfig      | 2 +-
 configs/colibri-imx8x_defconfig        | 2 +-
 configs/colibri_imx6_defconfig         | 2 +-
 configs/colibri_imx7_defconfig         | 2 +-
 configs/colibri_imx7_emmc_defconfig    | 2 +-
 configs/colibri_vf_defconfig           | 2 +-
 configs/toradex-smarc-imx8mp_defconfig | 2 +-
 configs/toradex-smarc-imx95_defconfig  | 2 +-
 configs/verdin-am62_a53_defconfig      | 2 +-
 configs/verdin-am62p_a53_defconfig     | 2 +-
 configs/verdin-imx8mm_defconfig        | 2 +-
 configs/verdin-imx8mp_defconfig        | 2 +-
 15 files changed, 15 insertions(+), 15 deletions(-)
configs/apalis-imx8_defconfig +1 -1
index 6ab4dd3dc57..17090ac682b 100644
@@ -25,7 +25,7 @@ CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=1
 CONFIG_OF_SYSTEM_SETUP=y
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile ${soc}-apalis${variant}-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile ${soc}-apalis${variant}-${fdt_board}.dtb"
 CONFIG_SYS_CBSIZE=2048
 CONFIG_SYS_PBSIZE=2068
 CONFIG_LOG=y
configs/apalis_imx6_defconfig +1 -1
index cd9811aca61..791be4df283 100644
@@ -31,7 +31,7 @@ CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=1
 CONFIG_BOOTCOMMAND="run distro_bootcmd; usb start; setenv stdout serial,vidconsole; setenv stdin serial,usbkbd"
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile imx6q-apalis${variant}-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile imx6q-apalis${variant}-${fdt_board}.dtb"
 CONFIG_SYS_CBSIZE=1024
 CONFIG_SYS_PBSIZE=1055
 CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
configs/colibri-imx6ull-emmc_defconfig +1 -1
index 439ddeb8f0b..c54ff48fdf7 100644
@@ -18,7 +18,7 @@ CONFIG_FIT_VERBOSE=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=1
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile imx6ull-colibri${variant}-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile imx6ull-colibri${variant}-${fdt_board}.dtb"
 CONFIG_SYS_PBSIZE=547
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
 # CONFIG_DISPLAY_BOARDINFO is not set
configs/colibri-imx6ull_defconfig +1 -1
index 1c400f9534d..cda7a6ada3a 100644
@@ -21,7 +21,7 @@ CONFIG_BOOTDELAY=1
 CONFIG_OF_ENV_SETUP=y
 CONFIG_BOOTCOMMAND="run ubiboot || run distro_bootcmd;"
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile imx6ull-colibri${variant}-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile imx6ull-colibri${variant}-${fdt_board}.dtb"
 CONFIG_SYS_PBSIZE=547
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
 # CONFIG_DISPLAY_BOARDINFO is not set
configs/colibri-imx8x_defconfig +1 -1
index fd6a6b47fcf..3300922b172 100644
@@ -26,7 +26,7 @@ CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=1
 CONFIG_OF_SYSTEM_SETUP=y
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile ${soc}-colibri-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile ${soc}-colibri-${fdt_board}.dtb"
 CONFIG_SYS_CBSIZE=2048
 CONFIG_SYS_PBSIZE=2068
 CONFIG_LOG=y
configs/colibri_imx6_defconfig +1 -1
index 0f5abb51f76..34037e1c134 100644
@@ -30,7 +30,7 @@ CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=1
 CONFIG_BOOTCOMMAND="run distro_bootcmd; usb start; setenv stdout serial,vidconsole; setenv stdin serial,usbkbd"
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile imx6dl-colibri${variant}-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile imx6dl-colibri${variant}-${fdt_board}.dtb"
 CONFIG_SYS_CBSIZE=1024
 CONFIG_SYS_PBSIZE=1056
 CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
configs/colibri_imx7_defconfig +1 -1
index 2a3cb84c3b6..8a84f49f42f 100644
@@ -22,7 +22,7 @@ CONFIG_BOOTDELAY=1
 CONFIG_OF_ENV_SETUP=y
 CONFIG_BOOTCOMMAND="run ubiboot ; echo ; echo ubiboot failed ; run distro_bootcmd;"
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile ${soc}-colibri${variant}-${fdt_board}.dtb "
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile ${soc}-colibri${variant}-${fdt_board}.dtb "
 CONFIG_SYS_PBSIZE=544
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
 # CONFIG_DISPLAY_BOARDINFO is not set
configs/colibri_imx7_emmc_defconfig +1 -1
index a95a3214d0c..4c661d4cda1 100644
@@ -19,7 +19,7 @@ CONFIG_FIT_VERBOSE=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=1
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile ${soc}-colibri${variant}-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile ${soc}-colibri${variant}-${fdt_board}.dtb"
 CONFIG_SYS_PBSIZE=544
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
 # CONFIG_DISPLAY_BOARDINFO is not set
configs/colibri_vf_defconfig +1 -1
index 1364fe45291..4ce14baef4f 100644
@@ -23,7 +23,7 @@ CONFIG_FDT_FIXUP_PARTITIONS=y
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="run ubiboot || run distro_bootcmd;"
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile ${soc}-colibri-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile ${soc}-colibri-${fdt_board}.dtb"
 CONFIG_SYS_PBSIZE=1056
 CONFIG_LOGLEVEL=3
 # CONFIG_DISPLAY_BOARDINFO is not set
configs/toradex-smarc-imx8mp_defconfig +1 -1
index 13a0e5f028b..7be67df3130 100644
@@ -40,7 +40,7 @@ CONFIG_BOOTDELAY=1
 CONFIG_OF_SYSTEM_SETUP=y
 CONFIG_BOOTCOMMAND="bootflow scan -b"
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile imx8mp-toradex-smarc-dev.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile imx8mp-toradex-smarc-dev.dtb"
 CONFIG_SYS_CBSIZE=2048
 CONFIG_SYS_PBSIZE=2081
 CONFIG_LOG=y
configs/toradex-smarc-imx95_defconfig +1 -1
index 61abeff1afb..144d8501ce7 100644
@@ -37,7 +37,7 @@ CONFIG_BOOTDELAY=1
 CONFIG_OF_SYSTEM_SETUP=y
 CONFIG_BOOTCOMMAND="bootflow scan -b"
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile imx95-toradex-smarc-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile imx95-toradex-smarc-${fdt_board}.dtb"
 CONFIG_SYS_CBSIZE=2048
 CONFIG_SYS_PBSIZE=2074
 CONFIG_LOG=y
configs/verdin-am62_a53_defconfig +1 -1
index f04858099da..3f3cd2a53b1 100644
@@ -34,7 +34,7 @@ CONFIG_FIT_VERBOSE=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=1
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile k3-am625-verdin-${variant}-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile k3-am625-verdin-${variant}-${fdt_board}.dtb"
 CONFIG_LOG=y
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
configs/verdin-am62p_a53_defconfig +1 -1
index 3dbffa78662..6cca7427485 100644
@@ -36,7 +36,7 @@ CONFIG_BOOTDELAY=1
 CONFIG_OF_BOARD_SETUP_EXTENDED=y
 CONFIG_BOOTCOMMAND="bootflow scan -b"
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile k3-am62p5-verdin-${variant}-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile k3-am62p5-verdin-${variant}-${fdt_board}.dtb"
 CONFIG_LOG=y
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
configs/verdin-imx8mm_defconfig +1 -1
index 45437205837..88f337bd347 100644
@@ -33,7 +33,7 @@ CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=1
 CONFIG_OF_SYSTEM_SETUP=y
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile imx8mm-verdin-${variant}-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile imx8mm-verdin-${variant}-${fdt_board}.dtb"
 CONFIG_SYS_CBSIZE=2048
 CONFIG_SYS_PBSIZE=2081
 CONFIG_LOG=y
configs/verdin-imx8mp_defconfig +1 -1
index 455a601b07d..368bd4aeeeb 100644
@@ -38,7 +38,7 @@ CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=1
 CONFIG_OF_SYSTEM_SETUP=y
 CONFIG_USE_PREBOOT=y
-CONFIG_PREBOOT="test -n ${fdtfile} || setenv fdtfile imx8mp-verdin-${variant}-${fdt_board}.dtb"
+CONFIG_PREBOOT="test -n \"${fdtfile}\" || setenv fdtfile imx8mp-verdin-${variant}-${fdt_board}.dtb"
 CONFIG_SYS_CBSIZE=2048
 CONFIG_SYS_PBSIZE=2081
 CONFIG_LOG=y
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/6] toradex: Quote fdtfile in preboot test

Hello Simon,

Quoted 6 lines · Simon Glass

The 15 Toradex defconfigs (apalis-imx8, apalis_imx6, the colibri imx6/imx6ull/imx7/imx8x/vf families, the toradex-smarc-imx8mp/imx95 boards and the verdin am62/am62p/imx8mm/imx8mp boards) all carry the same preboot expression:

    test -n ${fdtfile} || setenv fdtfile ...

Thanks for the patch.

This was already sent weeks ago, see https://lore.kernel.org/all/[email protected]/

Francesco

#3 lore raw

Re: [PATCH 1/6] toradex: Quote fdtfile in preboot test

Hi Francesco,

Quoted 9 lines · Francesco Dolcini

Hello Simon,

Quoted 5 lines · Simon Glass

The 15 Toradex defconfigs (apalis-imx8, apalis_imx6, the colibri imx6/imx6ull/imx7/imx8x/vf families, the toradex-smarc-imx8mp/imx95 boards and the verdin am62/am62p/imx8mm/imx8mp boards) all carry the same preboot expression:

Quoted 6 lines
Quoted 1 line
    test -n ${fdtfile} || setenv fdtfile ...

Thanks for the patch.

This was already sent weeks ago, see https://lore.kernel.org/all/[email protected]/

Thanks, I'll reply on that.

Regards,
Simon

#4 lore raw

PATCH 2/6 ti: Quote board_init in ti_common.env

In reply to Simon Glass

bootcmd_ti_mmc skips a per-board init hook with:

    if test -n ${board_init}; then run board_init; fi;

The default case is "no board override", i.e. board_init unset. The expression then expands to 'test -n' with no operand and relies on a U-Boot 'test' quirk that treats a missing operand as false to skip the run.

Quote the variable so an unset board_init expands to 'test -n ""' and the emptiness check is explicit.

Fixes 8b0619579b22 ("cmd: test: fix handling of single-argument form of test")

---

 include/env/ti/ti_common.env | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/env/ti/ti_common.env +1 -1
index 62b93eb25c4..e6ceaa17adc 100644
@@ -24,7 +24,7 @@ get_fit_config=setexpr name_fit_config gsub / _ conf-${fdtfile}
 run_fit=run get_fit_config; bootm ${addr_fit}#${name_fit_config}${overlaystring}
 bootcmd_ti_mmc=
 	run init_${boot};
-	if test -n ${board_init}; then
+	if test -n "${board_init}"; then
 		echo Running board_init ...;
 		run board_init;
 	fi;
Signature · 1 line
2.43.0
#5 lore raw

PATCH 3/6 siemens: Quote A/B flags in env tests

In reply to Simon Glass

The Siemens am33x-common, env-common and draco-etamin headers gate boot-partition selection logic on:

    if test -n ${A}; then ...
    if test -n ${B}; then ...

A and B are flags that the upgrade machinery sets to mark "the other partition just became active". The default state is unset, in which case the expression expands to 'test -n' with no operand and relies on a U-Boot 'test' quirk that treats a missing operand as false to skip the branch.

Quote each variable so an unset A or B expands to 'test -n ""' and the emptiness check is explicit.

Fixes 8b0619579b22 ("cmd: test: fix handling of single-argument form of test")

---

 include/configs/draco-etamin.h         |  4 ++--
 include/configs/siemens-am33x-common.h | 12 ++++++------
 include/configs/siemens-env-common.h   |  8 ++++----
 3 files changed, 12 insertions(+), 12 deletions(-)
include/configs/draco-etamin.h +2 -2
index 6ae85b575b7..b1b403980b1 100644
@@ -99,10 +99,10 @@
 	"nand_args=run bootargs_defaults;" \
 		"mtdparts default;" \
 		"setenv ${partitionset_active} true;" \
-		"if test -n ${A}; then " \
+		"if test -n \"${A}\"; then " \
 			"setenv nand_active_ubi_vol ${rootfs_name}_a;" \
 		"fi;" \
-		"if test -n ${B}; then " \
+		"if test -n \"${B}\"; then " \
 			"setenv nand_active_ubi_vol ${rootfs_name}_b;" \
 		"fi;" \
 		"setenv nand_root ubi0:${nand_active_ubi_vol} rw " \
include/configs/siemens-am33x-common.h +6 -6
index a918dc1350c..da822556909 100644
@@ -104,11 +104,11 @@
 				"then " \
 				"setenv upgrade_available 0;" \
 				"setenv ${partitionset_active} true;" \
-				"if test -n ${A}; then " \
+				"if test -n \"${A}\"; then " \
 					"setenv partitionset_active B; " \
 					"env delete A; " \
 				"fi;" \
-				"if test -n ${B}; then " \
+				"if test -n \"${B}\"; then " \
 					"setenv partitionset_active A; " \
 					"env delete B; " \
 				"fi;" \
@@ -205,11 +205,11 @@
 	"nand_args=run bootargs_defaults;" \
 		"mtdparts default;" \
 		"setenv ${partitionset_active} true;" \
-		"if test -n ${A}; then " \
+		"if test -n \"${A}\"; then " \
 			"setenv nand_active_ubi_vol ${nand_active_ubi_vol_A};" \
 			"setenv nand_src_addr ${nand_src_addr_A};" \
 		"fi;" \
-		"if test -n ${B}; then " \
+		"if test -n \"${B}\"; then " \
 			"setenv nand_active_ubi_vol ${nand_active_ubi_vol_B};" \
 			"setenv nand_src_addr ${nand_src_addr_B};" \
 		"fi;" \
@@ -279,10 +279,10 @@
 	"nand_args=run bootargs_defaults;" \
 		"mtdparts default;" \
 		"setenv ${partitionset_active} true;" \
-		"if test -n ${A}; then " \
+		"if test -n \"${A}\"; then " \
 			"setenv nand_active_ubi_vol ${rootfs_name}_a;" \
 		"fi;" \
-		"if test -n ${B}; then " \
+		"if test -n \"${B}\"; then " \
 			"setenv nand_active_ubi_vol ${rootfs_name}_b;" \
 		"fi;" \
 		"setenv nand_root ubi0:${nand_active_ubi_vol} rw " \
include/configs/siemens-env-common.h +4 -4
index c028823e1eb..8ced77cc5e2 100644
@@ -81,12 +81,12 @@
  */
 #define ENV_FCT_TOGGLE_PARTITION "toggle_partition="\
 	"setenv ${partitionset_active} true;" \
-	"if test -n ${A}; " \
+	"if test -n \"${A}\"; " \
 	"then " \
 		"setenv partitionset_active B; " \
 		"env delete A; " \
 	"fi;" \
-	"if test -n ${B}; "\
+	"if test -n \"${B}\"; "\
 	"then " \
 		"setenv partitionset_active A; " \
 		"env delete B; " \
@@ -103,11 +103,11 @@
  */
 #define ENV_EMMC_FCT_SET_ACTIVE_PARTITION "set_partition=" \
 	"setenv ${partitionset_active} true;" \
-	"if test -n ${A}; " \
+	"if test -n \"${A}\"; " \
 	"then " \
 		"setenv mmc_part_nr 1;" \
 	"fi;" \
-	"if test -n ${B}; " \
+	"if test -n \"${B}\"; " \
 	"then " \
 		"setenv mmc_part_nr 2;" \
 	"fi;" \
Signature · 1 line
2.43.0
#6 lore raw

PATCH 4/6 beaglev_fire: Quote no_of_overlays in design test

In reply to Simon Glass

On beaglev_fire, design_overlays gates an overlay-application loop on:

    if test -n ${no_of_overlays}; then ...

The default state is "no overlays", i.e. no_of_overlays unset. The expression then expands to 'test -n' with no operand and relies on a U-Boot 'test' quirk that treats a missing operand as false to skip the loop.

Quote the variable so an unset no_of_overlays expands to 'test -n ""' and the emptiness check is explicit.

Fixes 8b0619579b22 ("cmd: test: fix handling of single-argument form of test")

---

 include/configs/beaglev_fire.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/configs/beaglev_fire.h +1 -1
index e3ee0f02f2d..8724a71504c 100644
@@ -30,7 +30,7 @@
 
 #define BOOTENV_DESIGN_OVERLAYS \
 	"design_overlays=" \
-	"if test -n ${no_of_overlays}; then " \
+	"if test -n \"${no_of_overlays}\"; then " \
 		"setenv inc 1; " \
 		"setenv idx 0; " \
 		"fdt resize ${dtbo_size}; " \
Signature · 1 line
2.43.0
#7 lore raw

PATCH 5/6 mccmon6: Quote recovery_status in bootcmd test

In reply to Simon Glass

The mccmon6 bootcmd starts with:

    if test -n ${recovery_status}; then run boot_recovery; ...

The default state is "no recovery requested", i.e. recovery_status unset. The expression then expands to 'test -n' with no operand and relies on a U-Boot 'test' quirk that treats a missing operand as false to skip recovery.

Quote the variable so an unset recovery_status expands to 'test -n ""' and the emptiness check is explicit.

Fixes 8b0619579b22 ("cmd: test: fix handling of single-argument form of test")

---

 include/configs/mccmon6.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/configs/mccmon6.h +1 -1
index 9f401718bfb..0cf62d6bda8 100644
@@ -88,7 +88,7 @@
 		     "bootm $loadaddr};reset;" \
 		"fi\0" \
 	"bootcmd=" \
-		"if test -n ${recovery_status}; then " \
+		"if test -n \"${recovery_status}\"; then " \
 		     "run boot_recovery;" \
 		"else " \
 		     "if test ! -n ${boot_medium}; then " \
Signature · 1 line
2.43.0
Reviewed-by on v1 5/6
#8 lore raw

Re: [PATCH 5/6] mccmon6: Quote recovery_status in bootcmd test

Quoted 24 lines · On Sun, 3 May 2026 14:49:23 -0600 Simon Glass <[email protected]> wrote:

The mccmon6 bootcmd starts with:

    if test -n ${recovery_status}; then run boot_recovery; ...

The default state is "no recovery requested", i.e. recovery_status unset. The expression then expands to 'test -n' with no operand and relies on a U-Boot 'test' quirk that treats a missing operand as false to skip recovery.

Quote the variable so an unset recovery_status expands to 'test -n ""' and the emptiness check is explicit.

Fixes 8b0619579b22 ("cmd: test: fix handling of single-argument form

of test") Signed-off-by: Simon Glass <[email protected]>
---

 include/configs/mccmon6.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/configs/mccmon6.h +0 -0
index 9f401718bfb..0cf62d6bda8 100644

include/configs/mccmon6.h line 94

Quoted 8 lines
include/configs/mccmon6.h +1 -1
@@ -88,7 +88,7 @@
 		     "bootm $loadaddr};reset;" \
 		"fi\0" \
 	"bootcmd=" \
-		"if test -n ${recovery_status}; then " \
+		"if test -n \"${recovery_status}\"; then " \
 		     "run boot_recovery;" \
 		"else " \
 		     "if test ! -n ${boot_medium}; then " \
Signature · 10 lines
Best regards,

Lukasz Majewski

--
Nabla Software Engineering GmbH
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Managing Director : Stefano Babic
#9 lore raw

PATCH 6/6 aristainetos2: Quote rescue_reason in rescueboot test

In reply to Simon Glass

The rescueboot script optionally runs a per-board rescue_reason hook with:

    if test -n ${rescue_reason}; then run rescue_reason; fi;

The default state is "no rescue reason script", i.e. rescue_reason unset. The expression then expands to 'test -n' with no operand and relies on a U-Boot 'test' quirk that treats a missing operand as false to skip the run.

Quote the variable so an unset rescue_reason expands to 'test -n ""' and the emptiness check is explicit.

Fixes 8b0619579b22 ("cmd: test: fix handling of single-argument form of test")

---

 include/configs/aristainetos2.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/configs/aristainetos2.h +1 -1
index 8a66b1275df..2078ebc5282 100644
@@ -211,7 +211,7 @@
 		"${pubkey}\0" \
 	"rescueboot=echo Booting rescue system ...; " \
 		"run addmtd addmisc;" \
-		"if test -n ${rescue_reason}; then run rescue_reason;fi;" \
+		"if test -n \"${rescue_reason}\"; then run rescue_reason;fi;" \
 		"run boot_board_type;" \
 		"if bootm ${fit_addr_r}; then ; " \
 		"else " \
Signature · 1 line
2.43.0
Reviewed-by on v1 6/6
#10 lore raw

Re: [PATCH 6/6] aristainetos2: Quote rescue_reason in rescueboot test

Hello Simon,

Quoted 13 lines · Simon Glass

The rescueboot script optionally runs a per-board rescue_reason hook with:

     if test -n ${rescue_reason}; then run rescue_reason; fi;

The default state is "no rescue reason script", i.e. rescue_reason unset. The expression then expands to 'test -n' with no operand and relies on a U-Boot 'test' quirk that treats a missing operand as false to skip the run.

Quote the variable so an unset rescue_reason expands to 'test -n ""' and the emptiness check is explicit.

Quoted 6 lines
Fixes 8b0619579b22 ("cmd: test: fix handling of single-argument form of test")

---

  include/configs/aristainetos2.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks!

bye,
Heiko

Signature · 5 lines
Nabla Software Engineering
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Geschäftsführer : Stefano Babic
#11 lore raw

Re: (subset) [PATCH 0/6] test: Quote variables in 'test -n' expressions across boards

In reply to Simon Glass
Quoted 6 lines · Simon Glass

Several boards use 'test -n ${var}' (unquoted) in env scripts to detect an empty variable and trigger a fallback or skip a hook. That works only because of a U-Boot 'test' quirk where calls with argc < 3 returned false; an empty variable made the expression 'test -n' (one operand) and hit that path.

Quoted 8 lines

8b0619579b22 ("cmd: test: fix handling of single-argument form of test") aligned 'test' with POSIX so those expressions flipped to true. f7e7c55e53e8 ("cmd: test: add bug-compatibility special case for 'test -n'") restored the old behaviour for the exact 'test -n' (one arg) case, so the boards are not broken at runtime today, but the reliance on a bug-compat path isn't great.

[...]

Applied to u-boot/next, thanks!

[2/6] ti: Quote board_init in ti_common.env

      commit: 825f8ee2fcf64ef5875a0bc0a3e2d8650acdc298
[3/6] siemens: Quote A/B flags in env tests
      commit: 6b109a1304a03b35ad489e551964737ad80f6a82
[4/6] beaglev_fire: Quote no_of_overlays in design test
      commit: 2120834c25d525b754a8473565d4e0f9c158d806
[5/6] mccmon6: Quote recovery_status in bootcmd test
      commit: 9458e39c6595e2e00a1d0a645676eaf935e783c7
[6/6] aristainetos2: Quote rescue_reason in rescueboot test
      commit: 93d7dc20e80e33ace9b871de44877548642f86cb
Signature · 1 line
Tom