From patchwork Tue Mar 29 12:16:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 602868 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3qZ8tQ6sDWz9s4n for ; Tue, 29 Mar 2016 23:17:50 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 714E4A76D4; Tue, 29 Mar 2016 14:17:38 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id M7QZlD-88eej; Tue, 29 Mar 2016 14:17:38 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A13B3A76CD; Tue, 29 Mar 2016 14:17:36 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9A6FEA7666 for ; Tue, 29 Mar 2016 14:17:21 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dAUWElkseoFU for ; Tue, 29 Mar 2016 14:17:21 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from gagarine.paulk.fr (gagarine.paulk.fr [109.190.93.129]) by theia.denx.de (Postfix) with ESMTPS id 169C7A769C for ; Tue, 29 Mar 2016 14:17:09 +0200 (CEST) Received: by gagarine.paulk.fr (Postfix, from userid 65534) id 0C30020877; Tue, 29 Mar 2016 14:17:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on gagarine.paulk.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from localhost.localdomain (collins [192.168.1.129]) by gagarine.paulk.fr (Postfix) with ESMTP id 634E12087C; Tue, 29 Mar 2016 14:16:58 +0200 (CEST) From: Paul Kocialkowski To: u-boot@lists.denx.de Date: Tue, 29 Mar 2016 14:16:25 +0200 Message-Id: <1459253787-14577-5-git-send-email-contact@paulk.fr> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1459253787-14577-1-git-send-email-contact@paulk.fr> References: <1459253787-14577-1-git-send-email-contact@paulk.fr> Cc: Tom Rini Subject: [U-Boot] [PATCH v2 5/7] sniper: Proper reboot mode and boot reason validation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" With the previous implementation, rebooting without registering a recognized reboot mode (despite registering the magic) would end up with U-Boot checking for a valid power-on reason, which might result in the device turning off (e.g. with no USB cable attached and no buttons pressed). This was designed to catch reboots that are actually intended to be power-off, something that old Android kernels do, instead of properly turning the device off using the TWL4030. However, since this approach is not viable (breaks reboot in most cases), the validity of the reboot mode magic is checked to detect a reboot and the 'o' char is recognized to indicate that power-off is required. Still, that might be overridden by the detection of usual power-on reasons, on purpose. Signed-off-by: Paul Kocialkowski --- board/lge/sniper/sniper.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/board/lge/sniper/sniper.c b/board/lge/sniper/sniper.c index 29a7045..0662449 100644 --- a/board/lge/sniper/sniper.c +++ b/board/lge/sniper/sniper.c @@ -94,6 +94,7 @@ int misc_init_r(void) char reboot_mode[2] = { 0 }; unsigned char keys[3]; unsigned char data = 0; + int rc; /* Power button reset init */ @@ -109,22 +110,14 @@ int misc_init_r(void) /* Reboot mode */ - omap_reboot_mode(reboot_mode, sizeof(reboot_mode)); + rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode)); if (keys[0]) reboot_mode[0] = 'r'; else if (keys[1]) reboot_mode[0] = 'b'; - if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) { - if (!getenv("reboot-mode")) - setenv("reboot-mode", (char *)reboot_mode); - - omap_reboot_mode_clear(); - } else { - /* Reboot mode garbage may still be valid, so clear it. */ - omap_reboot_mode_clear(); - + if (rc < 0 || reboot_mode[0] == 'o') { /* * When not rebooting, valid power on reasons are either the * power button, charger plug or USB plug. @@ -138,6 +131,13 @@ int misc_init_r(void) twl4030_power_off(); } + if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) { + if (!getenv("reboot-mode")) + setenv("reboot-mode", (char *)reboot_mode); + } + + omap_reboot_mode_clear(); + /* Serial number */ omap_die_id_serial(); @@ -160,6 +160,19 @@ void get_board_serial(struct tag_serialnr *serialnr) omap_die_id_get_board_serial(serialnr); } +void reset_misc(void) +{ + char reboot_mode[2] = { 0 }; + + /* + * Valid resets must contain the reboot mode magic, but we must not + * override it when set previously (e.g. reboot to bootloader). + */ + + omap_reboot_mode(reboot_mode, sizeof(reboot_mode)); + omap_reboot_mode_store(reboot_mode); +} + int fb_set_reboot_flag(void) { return omap_reboot_mode_store("b");