]> git.sur5r.net Git - u-boot/blobdiff - board/liebherr/display5/spl.c
display5: Support for the emergency PAD pressing
[u-boot] / board / liebherr / display5 / spl.c
index 437963e225ee46c59647976b19a943e60bf348a3..551a14347da6c47b2b33c6fccbe94d33f70ed190 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2017 DENX Software Engineering
  * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/arch/imx-regs.h>
 #include "asm/arch/iomux.h"
 #include <asm/mach-imx/iomux-v3.h>
+#include <asm/gpio.h>
 #include <environment.h>
 #include <fsl_esdhc.h>
 #include <netdev.h>
+#include <bootcount.h>
 #include "common.h"
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -194,10 +195,24 @@ void board_init_f(ulong dummy)
        /* Clear the BSS. */
        memset(__bss_start, 0, __bss_end - __bss_start);
 
+       displ5_set_iomux_misc_spl();
+
        /* load/boot image from boot device */
        board_init_r(NULL, 0);
 }
 
+#define EM_PAD IMX_GPIO_NR(3, 29)
+int board_check_emergency_pad(void)
+{
+       int ret;
+
+       ret = gpio_direction_input(EM_PAD);
+       if (ret)
+               return ret;
+
+       return !gpio_get_value(EM_PAD);
+}
+
 void board_boot_order(u32 *spl_boot_list)
 {
        /* Default boot sequence SPI -> MMC */
@@ -206,15 +221,22 @@ void board_boot_order(u32 *spl_boot_list)
        spl_boot_list[2] = BOOT_DEVICE_UART;
        spl_boot_list[3] = BOOT_DEVICE_NONE;
 
+       /*
+        * In case of emergency PAD pressed, we always boot
+        * to proper u-boot and perform recovery tasks there.
+        */
+       if (board_check_emergency_pad())
+               return;
+
 #ifdef CONFIG_SPL_ENV_SUPPORT
        /* 'fastboot' */
        const char *s;
 
-       env_init();
-       env_load();
+       if (env_init() || env_load())
+               return;
 
        s = env_get("BOOT_FROM");
-       if (s && strcmp(s, "ACTIVE") == 0) {
+       if (s && !bootcount_error() && strcmp(s, "ACTIVE") == 0) {
                spl_boot_list[0] = BOOT_DEVICE_MMC1;
                spl_boot_list[1] = spl_boot_device();
        }