mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] startup: remove unused editcmd variable
@ 2019-07-04  6:44 Sascha Hauer
  2019-07-04  6:44 ` [PATCH 2/4] startup: Create global.linux.bootargs.dyn.* variables where they are needed Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2019-07-04  6:44 UTC (permalink / raw)
  To: Barebox List

Nobody uses global.editcmd, so remove it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/startup.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/common/startup.c b/common/startup.c
index 5686c0fb32..749db18e5a 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -153,7 +153,6 @@ static const char * const global_autoboot_abort_keys[] = {
 };
 static int global_autoboot_timeout = 3;
 static char *global_boot_default;
-static char *global_editcmd;
 static char *global_linux_bootargs_base;
 static char *global_linux_bootargs_dyn_ip;
 static char *global_linux_bootargs_dyn_root;
@@ -213,7 +212,6 @@ static int run_init(void)
 		return 0;
 	}
 
-	global_editcmd = xstrdup("sedit");
 	global_user = xstrdup("none");
 	globalvar_add_simple_string("user", &global_user);
 	global_boot_default = xstrdup("net");
@@ -225,7 +223,6 @@ static int run_init(void)
 	globalvar_add_simple_int("autoboot_timeout",
 				 &global_autoboot_timeout, "%u");
 	globalvar_add_simple_string("boot.default", &global_boot_default);
-	globalvar_add_simple_string("editcmd", &global_editcmd);
 	globalvar_add_simple_string("linux.bootargs.base",
 				    &global_linux_bootargs_base);
 	globalvar_add_simple_string("linux.bootargs.dyn.ip",
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/4] startup: Create global.linux.bootargs.dyn.* variables where they are needed
  2019-07-04  6:44 [PATCH 1/4] startup: remove unused editcmd variable Sascha Hauer
@ 2019-07-04  6:44 ` Sascha Hauer
  2019-07-04  6:44 ` [PATCH 3/4] startup: Create boot related variables where they are used Sascha Hauer
  2019-07-04  6:44 ` [PATCH 4/4] startup: Factor out the autoboot counter to separate function Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2019-07-04  6:44 UTC (permalink / raw)
  To: Barebox List

global.linux.bootargs.dyn.* variables are exclusively used in boot
scripts, so create them right before executing a script. This moves
the corresponding code from the unrelated startup code to the place
where the variables are used.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/boot.c    | 2 ++
 common/startup.c | 6 ------
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/common/boot.c b/common/boot.c
index 974eaf5d02..84b2ff9677 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -92,6 +92,8 @@ static int bootscript_boot(struct bootentry *entry, int verbose, int dryrun)
 		return 0;
 	}
 
+	globalvar_add_simple("linux.bootargs.dyn.ip", NULL);
+	globalvar_add_simple("linux.bootargs.dyn.root", NULL);
 	globalvar_set_match("linux.bootargs.dyn.", "");
 
 	ret = run_command(bs->scriptpath);
diff --git a/common/startup.c b/common/startup.c
index 749db18e5a..7e5a167af1 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -154,8 +154,6 @@ static const char * const global_autoboot_abort_keys[] = {
 static int global_autoboot_timeout = 3;
 static char *global_boot_default;
 static char *global_linux_bootargs_base;
-static char *global_linux_bootargs_dyn_ip;
-static char *global_linux_bootargs_dyn_root;
 static char *global_user;
 
 static bool test_abort(void)
@@ -225,10 +223,6 @@ static int run_init(void)
 	globalvar_add_simple_string("boot.default", &global_boot_default);
 	globalvar_add_simple_string("linux.bootargs.base",
 				    &global_linux_bootargs_base);
-	globalvar_add_simple_string("linux.bootargs.dyn.ip",
-				    &global_linux_bootargs_dyn_ip);
-	globalvar_add_simple_string("linux.bootargs.dyn.root",
-				    &global_linux_bootargs_dyn_root);
 
 	/* Unblank console cursor */
 	printf("\e[?25h");
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 3/4] startup: Create boot related variables where they are used
  2019-07-04  6:44 [PATCH 1/4] startup: remove unused editcmd variable Sascha Hauer
  2019-07-04  6:44 ` [PATCH 2/4] startup: Create global.linux.bootargs.dyn.* variables where they are needed Sascha Hauer
@ 2019-07-04  6:44 ` Sascha Hauer
  2019-07-04  6:44 ` [PATCH 4/4] startup: Factor out the autoboot counter to separate function Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2019-07-04  6:44 UTC (permalink / raw)
  To: Barebox List

global.boot.default, global.linux.bootargs.base and global.user are
used in the boot code, so create them there.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/boot.c    | 18 ++++++++++++++----
 common/startup.c | 10 ----------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/common/boot.c b/common/boot.c
index 84b2ff9677..14d4fe9d64 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -119,12 +119,22 @@ void boot_set_watchdog_timeout(unsigned int timeout)
 	boot_watchdog_timeout = timeout;
 }
 
-static int init_boot_watchdog_timeout(void)
+static char *global_boot_default;
+static char *global_user;
+
+static int init_boot(void)
 {
-	return globalvar_add_simple_int("boot.watchdog_timeout",
-			&boot_watchdog_timeout, "%u");
+	global_boot_default = xstrdup("net");
+	globalvar_add_simple_string("boot.default", &global_boot_default);
+	globalvar_add_simple_int("boot.watchdog_timeout",
+				 &boot_watchdog_timeout, "%u");
+	globalvar_add_simple("linux.bootargs.base", NULL);
+	global_user = xstrdup("none");
+	globalvar_add_simple_string("user", &global_user);
+
+	return 0;
 }
-late_initcall(init_boot_watchdog_timeout);
+late_initcall(init_boot);
 
 BAREBOX_MAGICVAR_NAMED(global_watchdog_timeout, global.boot.watchdog_timeout,
 		"Watchdog enable timeout in seconds before booting");
diff --git a/common/startup.c b/common/startup.c
index 7e5a167af1..b88c4a00d3 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -152,9 +152,6 @@ static const char * const global_autoboot_abort_keys[] = {
 	"ctrl-c",
 };
 static int global_autoboot_timeout = 3;
-static char *global_boot_default;
-static char *global_linux_bootargs_base;
-static char *global_user;
 
 static bool test_abort(void)
 {
@@ -210,19 +207,12 @@ static int run_init(void)
 		return 0;
 	}
 
-	global_user = xstrdup("none");
-	globalvar_add_simple_string("user", &global_user);
-	global_boot_default = xstrdup("net");
-
 	globalvar_add_simple_enum("autoboot_abort_key",
 				  &global_autoboot_abort_key,
                                   global_autoboot_abort_keys,
 				  ARRAY_SIZE(global_autoboot_abort_keys));
 	globalvar_add_simple_int("autoboot_timeout",
 				 &global_autoboot_timeout, "%u");
-	globalvar_add_simple_string("boot.default", &global_boot_default);
-	globalvar_add_simple_string("linux.bootargs.base",
-				    &global_linux_bootargs_base);
 
 	/* Unblank console cursor */
 	printf("\e[?25h");
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 4/4] startup: Factor out the autoboot counter to separate function
  2019-07-04  6:44 [PATCH 1/4] startup: remove unused editcmd variable Sascha Hauer
  2019-07-04  6:44 ` [PATCH 2/4] startup: Create global.linux.bootargs.dyn.* variables where they are needed Sascha Hauer
  2019-07-04  6:44 ` [PATCH 3/4] startup: Create boot related variables where they are used Sascha Hauer
@ 2019-07-04  6:44 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2019-07-04  6:44 UTC (permalink / raw)
  To: Barebox List

The autoboot countdown is part of the init function. This patch factors
out this code to a separate function to allow boards to call it at a
different time. Also boards can set the autoboot state manually in case
they have its own idea how to interrupt the autoboot process.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/startup.c | 134 +++++++++++++++++++++++++++++++----------------
 include/common.h |  10 ++++
 2 files changed, 98 insertions(+), 46 deletions(-)

diff --git a/common/startup.c b/common/startup.c
index b88c4a00d3..92bf94f849 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -182,20 +182,95 @@ static bool test_abort(void)
 }
 
 #define INITFILE "/env/bin/init"
+#define MENUFILE "/env/menu/mainmenu"
+
+static enum autoboot_state autoboot_state = AUTOBOOT_UNKNOWN;
+
+/**
+ * set_autoboot_state - set the autoboot state
+ * @autoboot: the state to set
+ *
+ * This functions sets the autoboot state to the given state. This can be called
+ * by boards which have its own idea when and how the autoboot shall be aborted.
+ */
+void set_autoboot_state(enum autoboot_state autoboot)
+{
+	autoboot_state = autoboot;
+}
+
+/**
+ * do_autoboot_countdown - print autoboot countdown to console
+ *
+ * This prints the autoboot countdown to the console and waits for input. This
+ * evaluates the global.autoboot_about_key to determine which keys are allowed
+ * to interrupt booting and also global.autoboot_timeout to determine the timeout
+ * for the counter. This function can be called multiple times, it is executed
+ * only the first time.
+ *
+ * Returns an enum autoboot_state value containing the user input.
+ */
+enum autoboot_state do_autoboot_countdown(void)
+{
+	unsigned flags = CONSOLE_COUNTDOWN_EXTERN;
+	int ret;
+	struct stat s;
+	bool menu_exists;
+	char *abortkeys = NULL;
+	unsigned char outkey;
+
+	if (autoboot_state != AUTOBOOT_UNKNOWN)
+		return autoboot_state;
+
+	globalvar_add_simple_enum("autoboot_abort_key",
+				  &global_autoboot_abort_key,
+                                  global_autoboot_abort_keys,
+				  ARRAY_SIZE(global_autoboot_abort_keys));
+	globalvar_add_simple_int("autoboot_timeout",
+				 &global_autoboot_timeout, "%u");
+
+	menu_exists = stat(MENUFILE, &s) == 0;
+
+	if (menu_exists) {
+		printf("\nHit m for menu or %s to stop autoboot: ",
+		       global_autoboot_abort_keys[global_autoboot_abort_key]);
+		abortkeys = "m";
+	} else {
+		printf("\nHit %s to stop autoboot: ",
+		       global_autoboot_abort_keys[global_autoboot_abort_key]);
+	}
+
+	switch (global_autoboot_abort_key) {
+	case 0:
+		flags |= CONSOLE_COUNTDOWN_ANYKEY;
+		break;
+	case 1:
+		flags |= CONSOLE_COUNTDOWN_CTRLC;
+		break;
+	default:
+		break;
+	}
+
+	ret = console_countdown(global_autoboot_timeout, flags, abortkeys,
+				&outkey);
+
+	if (ret == 0)
+		autoboot_state = AUTOBOOT_BOOT;
+	else if (menu_exists && outkey == 'm')
+		autoboot_state = AUTOBOOT_MENU;
+	else
+		autoboot_state = AUTOBOOT_ABORT;
+
+	return autoboot_state;
+}
 
 static int run_init(void)
 {
 	DIR *dir;
 	struct dirent *d;
 	const char *initdir = "/env/init";
-	const char *menufile = "/env/menu/mainmenu";
-	struct stat s;
-	unsigned flags = CONSOLE_COUNTDOWN_EXTERN;
-	unsigned char outkey;
-	int ret;
-	bool menu_exists;
 	bool env_bin_init_exists;
-	char *abortkeys = NULL;
+	enum autoboot_state autoboot;
+	struct stat s;
 
 	setenv("PATH", "/env/bin");
 
@@ -207,13 +282,6 @@ static int run_init(void)
 		return 0;
 	}
 
-	globalvar_add_simple_enum("autoboot_abort_key",
-				  &global_autoboot_abort_key,
-                                  global_autoboot_abort_keys,
-				  ARRAY_SIZE(global_autoboot_abort_keys));
-	globalvar_add_simple_int("autoboot_timeout",
-				 &global_autoboot_timeout, "%u");
-
 	/* Unblank console cursor */
 	printf("\e[?25h");
 
@@ -240,44 +308,18 @@ static int run_init(void)
 		closedir(dir);
 	}
 
-	menu_exists = stat(menufile, &s) == 0;
-
-	if (menu_exists) {
-		printf("\nHit m for menu or %s to stop autoboot: ",
-		       global_autoboot_abort_keys[global_autoboot_abort_key]);
-		abortkeys = "m";
-	} else {
-		printf("\nHit %s to stop autoboot: ",
-		       global_autoboot_abort_keys[global_autoboot_abort_key]);
-	}
-
-	switch (global_autoboot_abort_key) {
-	case 0:
-		flags |= CONSOLE_COUNTDOWN_ANYKEY;
-		break;
-	case 1:
-		flags |= CONSOLE_COUNTDOWN_CTRLC;
-		break;
-	default:
-		break;
-	}
-
-	ret = console_countdown(global_autoboot_timeout, flags, abortkeys,
-				&outkey);
+	autoboot = do_autoboot_countdown();
 
-	if (ret == 0)
+	if (autoboot == AUTOBOOT_BOOT)
 		run_command("boot");
 
 	console_ctrlc_allow();
 
-	if (menu_exists) {
-		if (outkey == 'm')
-			run_command(menufile);
+	if (autoboot == AUTOBOOT_MENU)
+		run_command(MENUFILE);
 
-		printf("Enter 'exit' to get back to the menu\n");
-		run_shell();
-		run_command(menufile);
-	}
+	run_shell();
+	run_command(MENUFILE);
 
 	return 0;
 }
diff --git a/include/common.h b/include/common.h
index b1294978d7..08f79a54af 100644
--- a/include/common.h
+++ b/include/common.h
@@ -93,6 +93,16 @@ unsigned long long strtoull_suffix(const char *str, char **endp, int base);
  */
 extern int (*barebox_main)(void);
 
+enum autoboot_state {
+	AUTOBOOT_UNKNOWN,
+	AUTOBOOT_ABORT,
+	AUTOBOOT_MENU,
+	AUTOBOOT_BOOT,
+};
+
+void set_autoboot_state(enum autoboot_state autoboot);
+enum autoboot_state do_autoboot_countdown(void);
+
 void __noreturn start_barebox(void);
 void shutdown_barebox(void);
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2019-07-04  6:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-04  6:44 [PATCH 1/4] startup: remove unused editcmd variable Sascha Hauer
2019-07-04  6:44 ` [PATCH 2/4] startup: Create global.linux.bootargs.dyn.* variables where they are needed Sascha Hauer
2019-07-04  6:44 ` [PATCH 3/4] startup: Create boot related variables where they are used Sascha Hauer
2019-07-04  6:44 ` [PATCH 4/4] startup: Factor out the autoboot counter to separate function Sascha Hauer

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