From patchwork Tue Apr 30 01:48:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1092924 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nic.cz Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.b="rCEC6+/r"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44tPf039G3z9s70 for ; Tue, 30 Apr 2019 11:51:52 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id F2E13C21C93; Tue, 30 Apr 2019 01:50:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9CE79C21E0B; Tue, 30 Apr 2019 01:48:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4DA8EC21C8B; Tue, 30 Apr 2019 01:48:28 +0000 (UTC) Received: from mail.nic.cz (mail.nic.cz [217.31.204.67]) by lists.denx.de (Postfix) with ESMTPS id BF6D6C21BE5 for ; Tue, 30 Apr 2019 01:48:27 +0000 (UTC) Received: from dellmb.labs.office.nic.cz (unknown [172.20.6.125]) by mail.nic.cz (Postfix) with ESMTP id 7842D63650; Tue, 30 Apr 2019 03:48:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1556588907; bh=pyZLATKbA4UR87GTUuZL04FcfrwACXUGT7un8A8GmUM=; h=From:To:Date; b=rCEC6+/rF6A41pTD0wUsABi68P45U1WTBRKmXV4tOI5+7ilugioKtfHblvxm8h1TH 9nfJWVvL6pmn6cZrgN2GBQqCbzk42f+D2/DSDcr7QyxO6CEMRU0di6sn+a82VTrOb3 9ZNS1SoigK3x8Z8IcFvnKQ9hnJOHHL6VCiXa/pTg= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: u-boot@lists.denx.de Date: Tue, 30 Apr 2019 03:48:24 +0200 Message-Id: <20190430014825.30553-15-marek.behun@nic.cz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430014825.30553-1-marek.behun@nic.cz> References: <20190430014825.30553-1-marek.behun@nic.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at mail X-Virus-Status: Clean Cc: Stefan Roese Subject: [U-Boot] [PATCH u-boot-marvell v2 14/15] arm: mvebu: turris_omnia: add RESET button handling X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" There is a Factory RESET button on the back side of the Turris Omnia router. When user presses this button before powering the device up and keeps it pressed, the microcontroller prevents the main CPU from booting and counts how long the RESET button is being pressed (and indicates this by lighting up front LEDs). The idea behind this is that the user can boot the device into several Factory RESET modes. This patch adds support for U-Boot to read into which Factory RESET mode the user booted the device. The value is an integer stored into the omnia_reset environment variable. It is 0 if the button was not pressed at all during power up, otherwise it is the number identifying the Factory RESET mode. This patch also adds support for configuring (via Kconfig) if the bootcmd environment variable should be overwritten if this Factory RESET button was pressed during device powerup, and if this configuration option is enabled, the value by which bootcmd should be overwritten with is also a configurable option. The default value sets the colors of all the LEDs on the front panel to green, then loads the rescue system image from the SPI flash memory and then boots it. Signed-off-by: Marek BehĂșn --- arch/arm/mach-mvebu/Kconfig | 43 ++++++++++++++++++++++++ board/CZ.NIC/turris_omnia/turris_omnia.c | 23 +++++++++++++ 2 files changed, 66 insertions(+) diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig index fc29c3b084..4229a505d1 100644 --- a/arch/arm/mach-mvebu/Kconfig +++ b/arch/arm/mach-mvebu/Kconfig @@ -116,6 +116,7 @@ config TARGET_DB_88F6820_AMC config TARGET_TURRIS_OMNIA bool "Support Turris Omnia" select 88F6820 + select BOARD_LATE_INIT select DM_I2C select I2C_MUX select I2C_MUX_PCA954x @@ -165,6 +166,48 @@ config TARGET_DB_XC3_24G4XG endchoice +if TARGET_TURRIS_OMNIA + +config TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD + bool "Turris Omnia RESET button overwrites bootcmd" + default y + help + There is a RESET button on the back side of the Turris Omnia router, + which is read by the microcontroller before the main CPU is booted. + If this button is pressed during device poweron, the CPU is only + booted after the button is released. + + The CPU can then read how long the RESET button was pressed (in time + intervals of cca 2 seconds, at most 12 different values), and U-Boot + stores this value into omnia_reset environment variable. + The microcontroller also lights up one front LED every time interval, + so that users can see the value they are forcing. + + If this option is enabled, the board code will also overwrite the + bootcmd variable with a constant configurable in this configuration + (config TURRIS_OMNIA_RSTBTN_BOOTCMD_VALUE) if the RESET button was + pressed for at least one time interval. + + Otherwise only the omnia_reset environment variable is set. + +config TURRIS_OMNIA_RSTBTN_BOOTCMD_VALUE + string "Turris Omnia RESET button bootcmd value" + default "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 \\\"$bootargs omniarescue=$omnia_reset\\\"; sf probe; sf read 0x1000000 0x100000 0x700000; bootm 0x1000000; bootz 0x1000000" + depends on TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD + help + If the RESET button is pressed during device poweron and released at + least after cca 2 seconds, the bootcmd will be overwritten with this + value. + + You can use the omnia_reset environment variable in this command to + detect how long the reset button was pressed (or pass this value to + Linux as a boot parameter). + + The default value of this command set the front LEDs to green color + and then tries to boot rescue system from SPI memory. + +endif + config SYS_BOARD default "clearfog" if TARGET_CLEARFOG default "helios4" if TARGET_HELIOS4 diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index af43ee23d9..91fce6370c 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -328,6 +328,28 @@ static int set_regdomain(void) printf("Regdomain set to %s\n", rd); return env_set("regdomain", rd); } + +static void handle_reset_button(void) +{ + int ret; + u8 reset_status; + + ret = omnia_mcu_read(CMD_GET_RESET, &reset_status, 1); + if (ret) { + printf("omnia_mcu_read failed: %i, reset status unknown!\n", + ret); + return; + } + + env_set_ulong("omnia_reset", reset_status); + +#ifdef CONFIG_TURRIS_OMNIA_RSTBTN_OVERWRITE_BOOTCMD + if (reset_status) { + printf("RESET button was pressed, overwriting bootcmd!\n"); + env_set("bootcmd", CONFIG_TURRIS_OMNIA_RSTBTN_BOOTCMD_VALUE); + } +#endif +} #endif int board_early_init_f(void) @@ -373,6 +395,7 @@ int board_late_init(void) { #ifndef CONFIG_SPL_BUILD set_regdomain(); + handle_reset_button(); #endif return 0;