All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: "Marek Behún" <marek.behun@nic.cz>, u-boot@lists.denx.de
Cc: "Pali Rohár" <pali@kernel.org>
Subject: Re: [PATCH u-boot-marvell v2 2/6] arm: mvebu: turris_mox: add support for board rescue mode
Date: Thu, 10 Jun 2021 07:09:29 +0200	[thread overview]
Message-ID: <056c7e7c-4725-65ad-afe8-88386258481f@denx.de> (raw)
In-Reply-To: <20210607143451.5343-3-marek.behun@nic.cz>

On 07.06.21 16:34, Marek Behún wrote:
> Add necessary config options and board code to support board factory
> reset / rescue mode on Turris MOX.
> 
> In order to also support invoking rescue mode from U-Boot console,
> without having to press the factory reset button, put the rescue command
> into `bootcmd_rescue` default environment variable. When factory reset
> button is pressed, invoke rescue mode via distroboot by setting
> `boot_targets` to `rescue`.
> 
> Rescue boot from console can be invoked by running
>    run bootcmd_rescue
> 
> Signed-off-by: Marek Behún <marek.behun@nic.cz>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

> ---
>   board/CZ.NIC/turris_mox/turris_mox.c | 71 ++++++++++++++++++++++++++++
>   configs/turris_mox_defconfig         |  6 +++
>   include/configs/turris_mox.h         |  9 ++++
>   3 files changed, 86 insertions(+)
> 
> diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c
> index 15cbf92550..a78f33661e 100644
> --- a/board/CZ.NIC/turris_mox/turris_mox.c
> +++ b/board/CZ.NIC/turris_mox/turris_mox.c
> @@ -10,11 +10,13 @@
>   #include <asm/global_data.h>
>   #include <asm/io.h>
>   #include <asm/gpio.h>
> +#include <button.h>
>   #include <clk.h>
>   #include <dm.h>
>   #include <env.h>
>   #include <fdt_support.h>
>   #include <init.h>
> +#include <led.h>
>   #include <linux/delay.h>
>   #include <linux/libfdt.h>
>   #include <linux/string.h>
> @@ -44,6 +46,8 @@
>   #define SFP_GPIO_PATH	"/soc/internal-regs@d0000000/spi@10600/moxtet@1/gpio@0"
>   #define PCIE_PATH	"/soc/pcie@d0070000"
>   #define SFP_PATH	"/sfp"
> +#define LED_PATH	"/leds/led"
> +#define BUTTON_PATH	"/gpio-keys/reset"
>   
>   DECLARE_GLOBAL_DATA_PTR;
>   
> @@ -373,6 +377,71 @@ int misc_init_r(void)
>   	return 0;
>   }
>   
> +static bool read_reset_button(void)
> +{
> +	struct udevice *button, *led;
> +	int i;
> +
> +	if (device_get_global_by_ofnode(ofnode_path(BUTTON_PATH), &button)) {
> +		printf("Cannot find reset button!\n");
> +		return false;
> +	}
> +
> +	if (device_get_global_by_ofnode(ofnode_path(LED_PATH), &led)) {
> +		printf("Cannot find status LED!\n");
> +		return false;
> +	}
> +
> +	led_set_state(led, LEDST_ON);
> +
> +	for (i = 0; i < 21; ++i) {
> +		if (button_get_state(button) != BUTTON_ON)
> +			return false;
> +		if (i < 20)
> +			mdelay(50);
> +	}
> +
> +	led_set_state(led, LEDST_OFF);
> +
> +	return true;
> +}
> +
> +static void handle_reset_button(void)
> +{
> +	if (read_reset_button()) {
> +		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 boot_targets!\n");
> +	} 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);
> +		}
> +	}
> +}
> +
>   static void mox_print_info(void)
>   {
>   	int ret, board_version, ram_size;
> @@ -543,6 +612,8 @@ int last_stage_init(void)
>   
>   	printf("\n");
>   
> +	handle_reset_button();
> +
>   	return 0;
>   }
>   
> diff --git a/configs/turris_mox_defconfig b/configs/turris_mox_defconfig
> index 75524babbc..d6d37a3d7d 100644
> --- a/configs/turris_mox_defconfig
> +++ b/configs/turris_mox_defconfig
> @@ -23,10 +23,14 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y
>   # CONFIG_DISPLAY_BOARDINFO is not set
>   CONFIG_ARCH_EARLY_INIT_R=y
>   CONFIG_MISC_INIT_R=y
> +CONFIG_BUTTON=y
> +CONFIG_BUTTON_GPIO=y
> +CONFIG_CMD_BUTTON=y
>   CONFIG_CMD_CLK=y
>   # CONFIG_CMD_FLASH is not set
>   CONFIG_CMD_GPIO=y
>   CONFIG_CMD_I2C=y
> +CONFIG_CMD_LED=y
>   CONFIG_CMD_MMC=y
>   CONFIG_CMD_PCI=y
>   CONFIG_CMD_SPI=y
> @@ -46,6 +50,8 @@ CONFIG_CLK=y
>   CONFIG_CLK_MVEBU=y
>   # CONFIG_MVEBU_GPIO is not set
>   CONFIG_DM_I2C=y
> +CONFIG_LED=y
> +CONFIG_LED_GPIO=y
>   CONFIG_MISC=y
>   CONFIG_MMC_SDHCI=y
>   CONFIG_MMC_SDHCI_SDMA=y
> diff --git a/include/configs/turris_mox.h b/include/configs/turris_mox.h
> index 51445ec60a..b148b1621a 100644
> --- a/include/configs/turris_mox.h
> +++ b/include/configs/turris_mox.h
> @@ -75,12 +75,21 @@
>   
>   #include <config_distro_bootcmd.h>
>   
> +#define TURRIS_MOX_BOOTCMD_RESCUE \
> +	"setenv bootargs \"console=ttyMV0,115200 " \
> +			  "earlycon=ar3700_uart,0xd0012000\" && " \
> +	"sf probe && " \
> +	"sf read 0x5000000 0x190000 && " \
> +	"lzmadec 0x5000000 0x5800000 && " \
> +	"bootm 0x5800000"
> +
>   #define CONFIG_EXTRA_ENV_SETTINGS	\
>   	"scriptaddr=0x4d00000\0"	\
>   	"pxefile_addr_r=0x4e00000\0"	\
>   	"fdt_addr_r=0x4f00000\0"	\
>   	"kernel_addr_r=0x5000000\0"	\
>   	"ramdisk_addr_r=0x8000000\0"	\
> +	"bootcmd_rescue=" TURRIS_MOX_BOOTCMD_RESCUE "\0" \
>   	BOOTENV
>   
>   #endif /* _CONFIG_TURRIS_MOX_H */
> 


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@denx.de

  parent reply	other threads:[~2021-06-10  5:09 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-02 17:09 [PATCH u-boot-marvell 0/7] Changes for Turris MOX Marek Behún
2021-06-02 17:09 ` [PATCH u-boot-marvell 1/7] arm: mvebu: dts: turris_mox: add button and LED nodes Marek Behún
2021-06-02 17:09 ` [PATCH u-boot-marvell 2/7] arm: mvebu: turris_mox: add support for board rescue mode Marek Behún
2021-06-03 15:18   ` Marek Behún
2021-06-02 17:09 ` [PATCH u-boot-marvell 3/7] arm: mvebu: turris_mox: start blinking PHY LEDs when entering rescue Marek Behún
2021-06-02 17:09 ` [PATCH u-boot-marvell 4/7] arm: mvebu: configs: turris_mox: add fdtfile default env variable Marek Behún
2021-06-02 17:09 ` [PATCH u-boot-marvell 5/7] arm: mvebu: dts: turris_mox: add nodes for SPI NOR partitions Marek Behún
2021-06-02 17:10 ` [PATCH u-boot-marvell 6/7] arm: mvebu: turris_mox: enable options for Turris network boot Marek Behún
2021-06-02 17:10 ` [PATCH u-boot-marvell 7/7] arm64: a37xx: dts: rename internal-regs node Marek Behún
2021-06-03 15:20   ` Marek Behún
2021-06-07 14:34 ` [PATCH u-boot-marvell v2 0/6] Changes for Turris MOX Marek Behún
2021-06-07 14:34   ` [PATCH u-boot-marvell v2 1/6] arm: mvebu: dts: turris_mox: add button and LED nodes Marek Behún
2021-06-08  9:47     ` Pali Rohár
2021-06-10  5:06     ` Stefan Roese
2021-06-07 14:34   ` [PATCH u-boot-marvell v2 2/6] arm: mvebu: turris_mox: add support for board rescue mode Marek Behún
2021-06-08  9:48     ` Pali Rohár
2021-06-10  5:09     ` Stefan Roese [this message]
2021-06-07 14:34   ` [PATCH u-boot-marvell v2 3/6] arm: mvebu: turris_mox: start blinking PHY LEDs when entering rescue Marek Behún
2021-06-08  9:49     ` Pali Rohár
2021-06-10  5:09     ` Stefan Roese
2021-06-07 14:34   ` [PATCH u-boot-marvell v2 4/6] arm: mvebu: configs: turris_mox: add fdtfile default env variable Marek Behún
2021-06-08  9:50     ` Pali Rohár
2021-06-10  5:10     ` Stefan Roese
2021-06-07 14:34   ` [PATCH u-boot-marvell v2 5/6] arm: mvebu: dts: turris_mox: add nodes for SPI NOR partitions Marek Behún
2021-06-08  9:51     ` Pali Rohár
2021-06-10  5:12       ` Stefan Roese
2021-06-10 14:07         ` Pali Rohár
2021-06-10 14:28           ` Marek Behun
2021-06-11  4:14             ` Stefan Roese
2021-06-10  5:11     ` Stefan Roese
2021-06-07 14:34   ` [PATCH u-boot-marvell v2 6/6] arm: mvebu: turris_mox: enable options for Turris network boot Marek Behún
2021-06-08  9:52     ` Pali Rohár
2021-06-10  5:11     ` Stefan Roese
2021-06-10  7:54   ` [PATCH u-boot-marvell v2 0/6] Changes for Turris MOX Stefan Roese

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=056c7e7c-4725-65ad-afe8-88386258481f@denx.de \
    --to=sr@denx.de \
    --cc=marek.behun@nic.cz \
    --cc=pali@kernel.org \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.