public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@nabladev.com>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Fabio Estevam <festevam@gmail.com>,
	Heiko Schocher <hs@nabladev.com>,
	Walter Schweizer <walter.schweizer@siemens.com>,
	Alexander Sverdlin <alexander.sverdlin@siemens.com>,
	Tom Rini <trini@konsulko.com>
Subject: [PATCH v1 07/11] siemens: capricorn: add logic to U-Boot to avoid zig-zag boot
Date: Sat, 24 Jan 2026 06:54:48 +0100	[thread overview]
Message-ID: <20260124055452.8799-8-hs@nabladev.com> (raw)
In-Reply-To: <20260124055452.8799-1-hs@nabladev.com>

add logic in board code for detecting the real boot
partition and set a local hush shell variable fallback
which can be used later in boot variables for detecting
a ROMbootloader fallback case.

We use the local hush shell variable, as we do not want
to save in any case the fallback variable in U-Boot
Environment, as the default Environment is may saved
in boards, which are downgraded to older U-Boot versions.

And than the board code does not run, and fallback never
gets the correct value.

Introduce also hush shell variable envvers to value "v2_"
so we can use them in Environment for running different
versions of variables between new and old U-Boot images.

Signed-off-by: Heiko Schocher <hs@nabladev.com>
Signed-off-by: Walter Schweizer <walter.schweizer@siemens.com>
---

 board/siemens/capricorn/Kconfig |  2 ++
 board/siemens/capricorn/board.c | 43 +++++++++++++++++++++++++++------
 2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/board/siemens/capricorn/Kconfig b/board/siemens/capricorn/Kconfig
index fe230971e97..d6d1aad75b2 100644
--- a/board/siemens/capricorn/Kconfig
+++ b/board/siemens/capricorn/Kconfig
@@ -1,5 +1,7 @@
 if TARGET_CAPRICORN
 
+config HUSH_INIT_VAR
+	def_bool y
 
 config SYS_BOARD
 	default "capricorn"
diff --git a/board/siemens/capricorn/board.c b/board/siemens/capricorn/board.c
index 390a7b0d841..d4f26b6ff7f 100644
--- a/board/siemens/capricorn/board.c
+++ b/board/siemens/capricorn/board.c
@@ -5,6 +5,7 @@
  * Copyright 2019 Siemens AG
  *
  */
+#include <cli_hush.h>
 #include <command.h>
 #include <dm.h>
 #include <env.h>
@@ -29,6 +30,7 @@
 #include "../common/board.h"
 #include "../common/eeprom.h"
 #include "../common/factoryset.h"
+#include <firmware/imx/sci/sci.h>
 
 #define GPIO_PAD_CTRL \
 		((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
@@ -373,23 +375,48 @@ __weak int mmc_map_to_kernel_blk(int dev_no)
 
 void board_late_mmc_env_init(void)
 {
-	char cmd[32];
-	char mmcblk[32];
 	u32 dev_no = mmc_get_env_dev();
 
 	if (!check_mmc_autodetect())
 		return;
 
 	env_set_ulong("mmcdev", dev_no);
+}
+
+#if defined(CONFIG_HUSH_INIT_VAR)
+int hush_init_var(void)
+{
+	sc_misc_bt_t boot_type;
 
-	/* Set mmcblk env */
-	sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
-		mmc_map_to_kernel_blk(dev_no));
-	env_set("mmcroot", mmcblk);
+	if (sc_misc_get_boot_type(-1, &boot_type) != 0) {
+		puts("boottype cannot be retrieved\n");
+		return 0;
+	}
+
+	/*
+	 * Set here explicitly a hush shell variable, so if a saveenv
+	 * happens, this variable is *not* saved in U-Boot environment.
+	 *
+	 * This is for devices which are already in the field essential,
+	 * as if such a device breaks, the cutsomer gets a new device
+	 * with a new U-Boot version (and so a new U-Boot environment).
+	 *
+	 * But the customer makes a downgrade to an older U-bootversion,
+	 * which does not have this code in, and runs now with a new
+	 * U-Boot Environment (yes, protected Environment is not enabled
+	 * there) and the old U-Boot must still work with the new U-Boot
+	 * Environment. So we cannot store this variable in U-Boot
+	 * Environment as a stored value will in this case never be over-
+	 * written.
+	 */
+	if (boot_type == 1) {
+		printf("boot-container fallback ocured\n");
+		set_local_var("fallback=1", 0);
+	}
 
-	sprintf(cmd, "mmc dev %d", dev_no);
-	run_command(cmd, 0);
+	return 0;
 }
+#endif
 
 #ifndef CONFIG_XPL_BUILD
 static int load_parameters_from_factoryset(void)
-- 
2.20.1


  parent reply	other threads:[~2026-01-24  5:56 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-24  5:54 [PATCH v1 00/11] imx8qxp: siemens: small board updates Heiko Schocher
2026-01-24  5:54 ` [PATCH v1 01/11] arm: dts: capricorn: pinctrl_usdhc1 cleanup Heiko Schocher
2026-01-26  1:12   ` Peng Fan
2026-01-24  5:54 ` [PATCH v1 02/11] siemens: capricorn: set max-frequency for usdhc1 Heiko Schocher
2026-01-26  1:14   ` Peng Fan
2026-01-24  5:54 ` [PATCH v1 03/11] arm: dts: capricorn: remove pinctrl_usdhc2 Heiko Schocher
2026-01-26  1:15   ` Peng Fan
2026-01-24  5:54 ` [PATCH v1 04/11] arm: dts: capricorn: move fec2 config Heiko Schocher
2026-01-26  1:18   ` Peng Fan
2026-01-24  5:54 ` [PATCH v1 05/11] imx8qxp_capricorn config: add wget command Heiko Schocher
2026-01-26  1:17   ` Peng Fan
2026-01-24  5:54 ` [PATCH v1 06/11] capricorn: config: add bootcounter command Heiko Schocher
2026-01-26  1:22   ` Peng Fan
2026-01-26  5:20     ` Heiko Schocher
2026-01-24  5:54 ` Heiko Schocher [this message]
2026-01-26  1:29   ` [PATCH v1 07/11] siemens: capricorn: add logic to U-Boot to avoid zig-zag boot Peng Fan
2026-01-26  5:30     ` Heiko Schocher
2026-01-24  5:54 ` [PATCH v1 08/11] siemens: capricorn: always detect emmc device Heiko Schocher
2026-01-26  1:18   ` Peng Fan
2026-01-24  5:54 ` [PATCH v1 09/11] siemens: capricorn: fix fallback bootm call for fitImage Heiko Schocher
2026-01-26  1:31   ` Peng Fan
2026-01-24  5:54 ` [PATCH v1 10/11] siemens: capricorn: rework bootcmd environment variables Heiko Schocher
2026-01-26  1:32   ` Peng Fan
2026-01-24  5:54 ` [PATCH v1 11/11] siemens: capricorn: protect environment Heiko Schocher
2026-01-26  1:24   ` Peng Fan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260124055452.8799-8-hs@nabladev.com \
    --to=hs@nabladev.com \
    --cc=alexander.sverdlin@siemens.com \
    --cc=festevam@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=walter.schweizer@siemens.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox