karo: introduce variables 'safeboot' and 'wdreset'
authorLothar Waßmann <LW@KARO-electronics.de>
Fri, 9 Jan 2015 11:33:40 +0000 (12:33 +0100)
committerLothar Waßmann <LW@KARO-electronics.de>
Fri, 9 Jan 2015 12:08:28 +0000 (13:08 +0100)
The environment variable 'safeboot' will be set when <CTRL-C> is
detected early in the boot process.
'wdreset' is set when the last boot cause was a watchdog reset.
This makes it possible to handle these events from the boot scripts.

board/karo/common/env.c
board/karo/tx28/tx28.c
board/karo/tx48/tx48.c
board/karo/tx51/tx51.c
board/karo/tx53/tx53.c
board/karo/tx6/tx6qdl.c

index c6def4f..7dbb7c8 100644 (file)
@@ -28,6 +28,8 @@ static const char const *cleanup_vars[] = {
        "bootargs",
        "fileaddr",
        "filesize",
+       "safeboot",
+       "wdreset",
 };
 
 void env_cleanup(void)
index ca0b3bc..e140e22 100644 (file)
@@ -147,7 +147,7 @@ int board_early_init_f(void)
        while ((rtc_stat = readl(&rtc_regs->hw_rtc_stat)) &
                RTC_STAT_STALE_REGS_PERSISTENT0) {
                if (timeout-- < 0)
-                       return 0;
+                       return 1;
                udelay(1);
        }
        boot_cause = readl(&rtc_regs->hw_rtc_persistent0);
@@ -162,11 +162,16 @@ int board_early_init_f(void)
 
 rtc_err:
        serial_puts("Inconsistent value in RTC_PERSISTENT0 register; power-on-reset required\n");
-       return 0;
+       return 1;
 }
 
 int board_init(void)
 {
+       if (ctrlc()) {
+               printf("CTRL-C detected; safeboot enabled\n");
+               return 1;
+       }
+
        /* Address of boot parameters */
 #ifdef CONFIG_OF_LIBFDT
        gd->bd->bi_arch_number = -1;
@@ -837,7 +842,10 @@ int board_late_init(void)
 
        env_cleanup();
 
-       karo_fdt_move_fdt();
+       if (had_ctrlc())
+               setenv_ulong("safeboot", 1);
+       else
+               karo_fdt_move_fdt();
 
        baseboard = getenv("baseboard");
        if (!baseboard)
index 539472a..8bc8bc5 100644 (file)
@@ -846,8 +846,12 @@ int board_init(void)
        /* address of boot parameters */
        gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
 
-       if (ctrlc())
-               printf("CTRL-C detected\n");
+       if (ctrlc() || (prm_rstst & PRM_RSTST_WDT1_RST)) {
+               if (prm_rstst & PRM_RSTST_WDT1_RST)
+                       printf("WDOG RESET detected\n");
+               else
+                       printf("<CTRL-C> detected; safeboot enabled\n");
+       }
 
        gpio_request_array(tx48_gpios, ARRAY_SIZE(tx48_gpios));
        tx48_set_pin_mux(tx48_pads, ARRAY_SIZE(tx48_pads));
@@ -915,11 +919,9 @@ static void tx48_set_cpu_clock(void)
                return;
 
        if (had_ctrlc() || (prm_rstst & PRM_RSTST_WDT1_RST)) {
-               if (prm_rstst & PRM_RSTST_WDT1_RST) {
-                       printf("Watchdog reset detected; skipping cpu clock change\n");
-               } else {
-                       printf("<CTRL-C> detected; skipping cpu clock change\n");
-               }
+               printf("%s detected; skipping cpu clock change\n",
+                       (prm_rstst & PRM_RSTST_WDT1_RST) ?
+                       "WDOG RESET" : "<CTRL-C>");
                return;
        }
 
@@ -969,7 +971,13 @@ int board_late_init(void)
        env_cleanup();
 
        tx48_set_cpu_clock();
-       karo_fdt_move_fdt();
+
+       if (had_ctrlc())
+               setenv_ulong("safeboot", 1);
+       else if (prm_rstst & PRM_RSTST_WDT1_RST)
+               setenv_ulong("wdreset", 1);
+       else
+               karo_fdt_move_fdt();
 
        baseboard = getenv("baseboard");
        if (!baseboard)
index 72c6584..b94e537 100644 (file)
@@ -271,7 +271,10 @@ int board_init(void)
        gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x1000;
 
        if (ctrlc() || (wrsr & WRSR_TOUT)) {
-               printf("CTRL-C detected; Skipping boot critical setup\n");
+               if (wrsr & WRSR_TOUT)
+                       printf("WDOG RESET detected\n");
+               else
+                       printf("<CTRL-C> detected; safeboot enabled\n");
                return 1;
        }
        return 0;
@@ -1046,7 +1049,13 @@ int board_late_init(void)
        env_cleanup();
 
        tx51_set_cpu_clock();
-       karo_fdt_move_fdt();
+
+       if (had_ctrlc())
+               setenv_ulong("safeboot", 1);
+       else if (wrsr & WRSR_TOUT)
+               setenv_ulong("wdreset", 1);
+       else
+               karo_fdt_move_fdt();
 
        baseboard = getenv("baseboard");
        if (!baseboard)
index 3074ae9..9df8126 100644 (file)
@@ -486,7 +486,10 @@ int board_init(void)
        gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x1000;
 
        if (ctrlc() || (wrsr & WRSR_TOUT)) {
-               printf("CTRL-C detected; Skipping PMIC setup\n");
+               if (wrsr & WRSR_TOUT)
+                       printf("WDOG RESET detected; Skipping PMIC setup\n");
+               else
+                       printf("<CTRL-C> detected; safeboot enabled\n");
                return 1;
        }
 
@@ -1289,11 +1292,14 @@ static void tx53_set_cpu_clock(void)
 {
        unsigned long cpu_clk = getenv_ulong("cpu_clk", 10, 0);
 
-       if (had_ctrlc() || (wrsr & WRSR_TOUT))
+       if (cpu_clk == 0 || cpu_clk == mxc_get_clock(MXC_ARM_CLK) / 1000000)
                return;
 
-       if (cpu_clk == 0 || cpu_clk == mxc_get_clock(MXC_ARM_CLK) / 1000000)
+       if (had_ctrlc() || (wrsr & WRSR_TOUT)) {
+               printf("%s detected; skipping cpu clock change\n",
+                       (wrsr & WRSR_TOUT) ? "WDOG RESET" : "<CTRL-C>");
                return;
+       }
 
        if (mxc_set_clock(CONFIG_SYS_MX5_HCLK, cpu_clk, MXC_ARM_CLK) == 0) {
                cpu_clk = mxc_get_clock(MXC_ARM_CLK);
@@ -1326,7 +1332,13 @@ int board_late_init(void)
        env_cleanup();
 
        tx53_set_cpu_clock();
-       karo_fdt_move_fdt();
+
+       if (had_ctrlc())
+               setenv_ulong("safeboot", 1);
+       else if (wrsr & WRSR_TOUT)
+               setenv_ulong("wdreset", 1);
+       else
+               karo_fdt_move_fdt();
 
        baseboard = getenv("baseboard");
        if (!baseboard)
index 7214136..1fa2d1f 100644 (file)
@@ -261,11 +261,14 @@ int board_init(void)
        gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x1000;
        gd->bd->bi_arch_number = -1;
 
-       if (ctrlc()) {
+       if (ctrlc() || (wrsr & WRSR_TOUT)) {
+               if (wrsr & WRSR_TOUT)
+                       printf("WDOG RESET detected; Skipping PMIC setup\n");
+               else
+                       printf("<CTRL-C> detected; safeboot enabled\n");
 #ifndef CONFIG_MX6_TEMPERATURE_HOT
                tx6_temp_check_enabled = false;
 #endif
-               printf("CTRL-C detected; Skipping PMIC setup\n");
                return 1;
        }
 
@@ -1078,12 +1081,14 @@ static void tx6qdl_set_cpu_clock(void)
 {
        unsigned long cpu_clk = getenv_ulong("cpu_clk", 10, 0);
 
-       if (had_ctrlc() || (wrsr & WRSR_TOUT))
-               return;
-
        if (cpu_clk == 0 || cpu_clk == mxc_get_clock(MXC_ARM_CLK) / 1000000)
                return;
 
+       if (had_ctrlc() || (wrsr & WRSR_TOUT)) {
+               printf("%s detected; skipping cpu clock change\n",
+                       (wrsr & WRSR_TOUT) ? "WDOG RESET" : "<CTRL-C>");
+               return;
+       }
        if (mxc_set_clock(CONFIG_SYS_MX6_HCLK, cpu_clk, MXC_ARM_CLK) == 0) {
                cpu_clk = mxc_get_clock(MXC_ARM_CLK);
                printf("CPU clock set to %lu.%03lu MHz\n",
@@ -1118,7 +1123,12 @@ int board_late_init(void)
                check_cpu_temperature(1);
 
        tx6qdl_set_cpu_clock();
-       if (!had_ctrlc())
+
+       if (had_ctrlc())
+               setenv_ulong("safeboot", 1);
+       else if (wrsr & WRSR_TOUT)
+               setenv_ulong("wdreset", 1);
+       else
                karo_fdt_move_fdt();
 
        baseboard = getenv("baseboard");