Skip to content

Commit

Permalink
arm: mvebu: turris_{omnia, mox}: ensure running bootcmd_rescue always…
Browse files Browse the repository at this point in the history
… works

One of the points of putting the rescue boot command into default
environment is that user can invoke it without physical access to the
board (without having to press the factory reset button), by running
  run bootcmd_rescue
in U-Boot's console.

Therefore we have to ensure that bootcmd_rescue is always set to default
value, regardless of whether the factory reset button was pressed.
Otherwise the variable will be empty for example after upgrade from
previous U-Boot.

Fixes: ec3784d ("arm: mvebu: turris_mox: add support for board rescue mode")
Fixes: 176c3e7 ("arm: mvebu: turris_omnia: support invoking rescue boot from console")
Signed-off-by: Pali Rohár <[email protected]>
Signed-off-by: Marek Behún <[email protected]>
Reviewed-by: Stefan Roese <[email protected]>
  • Loading branch information
pali authored and stroese committed Jun 15, 2021
1 parent c4737cd commit 029bb91
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 11 additions & 3 deletions board/CZ.NIC/turris_mox/turris_mox.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,26 @@ static bool read_reset_button(void)

static void handle_reset_button(void)
{
const char * const vars[1] = { "bootcmd_rescue", };

/*
* Ensure that bootcmd_rescue has always stock value, so that running
* run bootcmd_rescue
* always works correctly.
*/
env_set_default_vars(1, (char * const *)vars, 0);

if (read_reset_button()) {
const char * const vars[3] = {
const char * const vars[2] = {
"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);
env_set_default_vars(2, (char * const *)vars, 0);

/* Ensure bootcmd_rescue is used by distroboot */
env_set("boot_targets", "rescue");
Expand Down
13 changes: 10 additions & 3 deletions board/CZ.NIC/turris_omnia/turris_omnia.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,17 @@ static int set_regdomain(void)

static void handle_reset_button(void)
{
const char * const vars[1] = { "bootcmd_rescue", };
int ret;
u8 reset_status;

/*
* Ensure that bootcmd_rescue has always stock value, so that running
* run bootcmd_rescue
* always works correctly.
*/
env_set_default_vars(1, (char * const *)vars, 0);

ret = omnia_mcu_read(CMD_GET_RESET, &reset_status, 1);
if (ret) {
printf("omnia_mcu_read failed: %i, reset status unknown!\n",
Expand All @@ -352,17 +360,16 @@ static void handle_reset_button(void)
env_set_ulong("omnia_reset", reset_status);

if (reset_status) {
const char * const vars[3] = {
const char * const vars[2] = {
"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);
env_set_default_vars(2, (char * const *)vars, 0);

/* Ensure bootcmd_rescue is used by distroboot */
env_set("boot_targets", "rescue");
Expand Down

0 comments on commit 029bb91

Please sign in to comment.