From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2931CC48BD1 for ; Thu, 10 Jun 2021 05:09:41 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C464613D0 for ; Thu, 10 Jun 2021 05:09:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C464613D0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DEC7C82D6C; Thu, 10 Jun 2021 07:09:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1623301778; bh=TfGuEtS3Nu4mXtJzsIyE1SZzDqdn3PlnvopmAHu0QFA=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=F0vUlg2LFYaHVI5yKcqsAW7Cp9A4eL8omW0AyJJyRzaK7BvhWIJZoUg938efSMtsW 3TIfkNIfIl6Kg+SPkfBcfNG8uw5R95FN55SoNo0htAmolPssd7F6M2JLPJBpOII/je ecKkCQdtm7XNfKWX8jU3ZYIgrSRy/Tuhwi65mU595ZhP/B9Q6SprgQ7tzy2fTK5Apy zysbqX/LvoFBsE0xm33THNnwcasQu80ZehJrrbSBFZOTzDcJ4E2jHn7N4+gKqq6bwu MjxRtrIkOLQJp31OZaHO/UlAEnYwCQXi3TrFK5xhVLE2FW5tpDHzjdX27bZZVXEl3y yM1lKhchngwzw== Received: by phobos.denx.de (Postfix, from userid 109) id 2128182D22; Thu, 10 Jun 2021 07:09:36 +0200 (CEST) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [IPv6:2001:67c:2050:1::465:107]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 405AB82D15 for ; Thu, 10 Jun 2021 07:09:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4G0sTn04LczQjZ5; Thu, 10 Jun 2021 07:09:33 +0200 (CEST) Received: from smtp1.mailbox.org ([80.241.60.240]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id c5js4YXDjd4L; Thu, 10 Jun 2021 07:09:29 +0200 (CEST) Subject: Re: [PATCH u-boot-marvell v2 2/6] arm: mvebu: turris_mox: add support for board rescue mode To: =?UTF-8?Q?Marek_Beh=c3=ban?= , u-boot@lists.denx.de Cc: =?UTF-8?Q?Pali_Roh=c3=a1r?= References: <20210607143451.5343-1-marek.behun@nic.cz> <20210607143451.5343-3-marek.behun@nic.cz> From: Stefan Roese Message-ID: <056c7e7c-4725-65ad-afe8-88386258481f@denx.de> Date: Thu, 10 Jun 2021 07:09:29 +0200 MIME-Version: 1.0 In-Reply-To: <20210607143451.5343-3-marek.behun@nic.cz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 8bit X-MBO-SPAM-Probability: X-Rspamd-Score: -5.25 / 15.00 / 15.00 X-Rspamd-Queue-Id: 10CDF1895 X-Rspamd-UID: b30c66 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean 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 Reviewed-by: Stefan Roese 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 > #include > #include > +#include > #include > #include > #include > #include > #include > +#include > #include > #include > #include > @@ -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 > > +#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