mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] startup: implement get_autoboot_state() helper
@ 2025-12-15  8:24 Ahmad Fatoum
  2025-12-15  8:24 ` [PATCH 2/3] of: implement of_get_machine_vendor() Ahmad Fatoum
  2025-12-15  8:24 ` [PATCH 3/3] lib: smbios: add support for populating SMBIOS table Ahmad Fatoum
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-12-15  8:24 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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 <a.fatoum@pengutronix.de>
---
 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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-15  8:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-15  8:24 [PATCH 1/3] startup: implement get_autoboot_state() helper Ahmad Fatoum
2025-12-15  8:24 ` [PATCH 2/3] of: implement of_get_machine_vendor() Ahmad Fatoum
2025-12-15  8:24 ` [PATCH 3/3] lib: smbios: add support for populating SMBIOS table Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox