This helper returns the last autoboot state used and can thus be used to
detect if boot was aborted manually.

Signed-off-by: Ahmad Fatoum <[email protected]>
---
 common/startup.c  | 24 ++++++++++++++++++------
 include/barebox.h |  1 +
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/common/startup.c b/common/startup.c
index 73cf4a495b9c..81a3ae1513c2 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -274,11 +274,22 @@ static int register_autoboot_vars(void)
 }
 postcore_initcall(register_autoboot_vars);
 
+static enum autoboot_state current_autoboot = AUTOBOOT_UNKNOWN;
+
+/**
+ * get_autoboot_state - get the autoboot state
+ *
+ * This functions returns the autoboot state last used.
+ */
+enum autoboot_state get_autoboot_state(void)
+{
+       return current_autoboot;
+}
+
 static int run_init(void)
 {
        const char *bmode, *cmdline;
        bool env_bin_init_exists;
-       enum autoboot_state autoboot;
        struct stat s;
        glob_t g;
        int i, ret;
@@ -355,19 +366,20 @@ static int run_init(void)
                free(scr);
        }
 
-       autoboot = do_autoboot_countdown();
+       current_autoboot = do_autoboot_countdown();
 
        console_ctrlc_allow();
 
-       if (autoboot == AUTOBOOT_BOOT)
+       if (current_autoboot == AUTOBOOT_BOOT)
                run_command("boot");
 
        if (IS_ENABLED(CONFIG_NET) && !IS_ENABLED(CONFIG_CONSOLE_DISABLE_INPUT) 
&&
-           autoboot != AUTOBOOT_HALT)
+           current_autoboot != AUTOBOOT_HALT)
                eth_open_all();
 
-       if (autoboot != AUTOBOOT_MENU) {
-               if (autoboot == AUTOBOOT_ABORT && autoboot == 
global_autoboot_state)
+       if (current_autoboot != AUTOBOOT_MENU) {
+               if (current_autoboot == AUTOBOOT_ABORT &&
+                   current_autoboot == global_autoboot_state)
                        watchdog_inhibit_all();
 
                run_shell();
diff --git a/include/barebox.h b/include/barebox.h
index 6f3179d4bd62..4e694e0db9a6 100644
--- a/include/barebox.h
+++ b/include/barebox.h
@@ -40,6 +40,7 @@ enum autoboot_state {
        AUTOBOOT_UNKNOWN,
 };
 
+enum autoboot_state get_autoboot_state(void);
 void set_autoboot_state(enum autoboot_state autoboot);
 enum autoboot_state do_autoboot_countdown(void);
 
-- 
2.47.3


Reply via email to