[PATCH u-boot-marvell 2/2] arm: mvebu: turris_omnia: support invoking rescue boot from console
Stefan Roese
sr at denx.de
Fri Jun 4 15:12:52 CEST 2021
On 28.05.21 10:00, Marek Behún wrote:
> Make it possible to invoke rescue boot from U-Boot console, without
> having to press the factory reset button. This is needed when accessing
> the device remotely, for example.
>
> Achieve this by putting rescue command into `bootcmd_rescue` default
> environment variable and setting some distroboot environment variables
> to their default values when the factory button is pressed.
>
> Rescue boot from console can be invoked by running
> run bootcmd_rescue
>
> Signed-off-by: Marek Behún <marek.behun at nic.cz>
Applied to u-boot-marvell/master
Thanks,
Stefan
> ---
> board/CZ.NIC/turris_omnia/turris_omnia.c | 53 +++++++++++++-----------
> include/configs/turris_omnia.h | 23 ++++++++++
> 2 files changed, 52 insertions(+), 24 deletions(-)
>
> diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c
> index d3de8004eb..ade923f599 100644
> --- a/board/CZ.NIC/turris_omnia/turris_omnia.c
> +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c
> @@ -337,29 +337,6 @@ static int set_regdomain(void)
> return env_set("regdomain", rd);
> }
>
> -/*
> - * default factory reset bootcommand on Omnia first sets all the front LEDs
> - * to green and then tries to load the rescue image from SPI flash memory and
> - * boot it
> - */
> -#define OMNIA_FACTORY_RESET_BOOTCMD \
> - "i2c dev 2; " \
> - "i2c mw 0x2a.1 0x3 0x1c 1; " \
> - "i2c mw 0x2a.1 0x4 0x1c 1; " \
> - "mw.l 0x01000000 0x00ff000c; " \
> - "i2c write 0x01000000 0x2a.1 0x5 4 -s; " \
> - "setenv bootargs \"earlyprintk console=ttyS0,115200" \
> - " omniarescue=$omnia_reset rescue_mode=$omnia_reset\"; " \
> - "sf probe; " \
> - "sf read 0x1000000 0x100000 0x700000; " \
> - "lzmadec 0x1000000 0x1700000; " \
> - "if gpio input gpio at 71_4; then " \
> - "bootm 0x1700000#sfp; " \
> - "else " \
> - "bootm 0x1700000; " \
> - "fi; " \
> - "bootz 0x1000000"
> -
> static void handle_reset_button(void)
> {
> int ret;
> @@ -375,8 +352,36 @@ static void handle_reset_button(void)
> env_set_ulong("omnia_reset", reset_status);
>
> if (reset_status) {
> + const char * const vars[3] = {
> + "bootcmd",
> + "bootcmd_rescue",
> + "distro_bootcmd",
> + };
> +
> + /*
> + * Set the above envs to their default values, in case the user
> + * managed to break them.
> + */
> + env_set_default_vars(3, (char * const *)vars, 0);
> +
> + /* Ensure bootcmd_rescue is used by distroboot */
> + env_set("boot_targets", "rescue");
> +
> printf("RESET button was pressed, overwriting bootcmd!\n");
> - env_set("bootcmd", OMNIA_FACTORY_RESET_BOOTCMD);
> + } else {
> + /*
> + * In case the user somehow managed to save environment with
> + * boot_targets=rescue, reset boot_targets to default value.
> + * This could happen in subsequent commands if bootcmd_rescue
> + * failed.
> + */
> + if (!strcmp(env_get("boot_targets"), "rescue")) {
> + const char * const vars[1] = {
> + "boot_targets",
> + };
> +
> + env_set_default_vars(1, (char * const *)vars, 0);
> + }
> }
> }
> #endif
> diff --git a/include/configs/turris_omnia.h b/include/configs/turris_omnia.h
> index 0b55c14d8b..7da18f97db 100644
> --- a/include/configs/turris_omnia.h
> +++ b/include/configs/turris_omnia.h
> @@ -108,12 +108,35 @@
>
> #include <config_distro_bootcmd.h>
>
> +/*
> + * The factory reset bootcommand on Omnia first sets all the front LEDs to green
> + * and then tries to load the rescue image from SPI flash memory and boot it
> + */
> +#define TURRIS_OMNIA_BOOTCMD_RESCUE \
> + "i2c dev 2; " \
> + "i2c mw 0x2a.1 0x3 0x1c 1; " \
> + "i2c mw 0x2a.1 0x4 0x1c 1; " \
> + "mw.l 0x01000000 0x00ff000c; " \
> + "i2c write 0x01000000 0x2a.1 0x5 4 -s; " \
> + "setenv bootargs \"earlyprintk console=ttyS0,115200" \
> + " omniarescue=$omnia_reset rescue_mode=$omnia_reset\"; " \
> + "sf probe; " \
> + "sf read 0x1000000 0x100000 0x700000; " \
> + "lzmadec 0x1000000 0x1700000; " \
> + "if gpio input gpio at 71_4; then " \
> + "bootm 0x1700000#sfp; " \
> + "else " \
> + "bootm 0x1700000; " \
> + "fi; " \
> + "bootz 0x1000000"
> +
> #define CONFIG_EXTRA_ENV_SETTINGS \
> RELOCATION_LIMITS_ENV_SETTINGS \
> LOAD_ADDRESS_ENV_SETTINGS \
> "fdtfile=" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
> "console=ttyS0,115200\0" \
> "ethact=ethernet at 34000\0" \
> + "bootcmd_rescue=" TURRIS_OMNIA_BOOTCMD_RESCUE "\0" \
> BOOTENV
>
> #endif /* CONFIG_SPL_BUILD */
>
Viele Grüße,
Stefan
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
More information about the U-Boot
mailing list