[PATCH master 3/4] startup: track system state with regards to initcall/exitcalls
Ahmad Fatoum
a.fatoum at barebox.org
Sun Jun 22 23:20:31 PDT 2025
The operating system reclaims the barebox malloc area fully after it's
booted, so there is no point freeing memory while executing exitcalls.
To allow skipping memory freeing in that situation, maintain this
information in a new barebox_system_state variable.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
common/startup.c | 5 +++++
include/barebox.h | 12 ++++++++++++
2 files changed, 17 insertions(+)
diff --git a/common/startup.c b/common/startup.c
index 560a00c5699b..8d36ffceb47e 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -51,6 +51,7 @@ extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
extern exitcall_t __barebox_exitcalls_start[], __barebox_exitcalls_end[];
+enum system_states barebox_system_state;
#if defined CONFIG_FS_RAMFS && defined CONFIG_FS_DEVFS
static int mount_root(void)
@@ -404,8 +405,10 @@ void __noreturn start_barebox(void)
ERR_PTR(result));
}
+ barebox_system_state = BAREBOX_RUNNING;
pr_debug("initcalls done\n");
+
if (IS_ENABLED(CONFIG_SELFTEST_AUTORUN))
selftests_run();
@@ -435,6 +438,8 @@ void shutdown_barebox(void)
{
exitcall_t *exitcall;
+ barebox_system_state = BAREBOX_EXITING;
+
for (exitcall = __barebox_exitcalls_start;
exitcall < __barebox_exitcalls_end; exitcall++) {
pr_debug("exitcall-> %pS\n", *exitcall);
diff --git a/include/barebox.h b/include/barebox.h
index 02228451c26e..1b291129e982 100644
--- a/include/barebox.h
+++ b/include/barebox.h
@@ -48,4 +48,16 @@ void shutdown_barebox(void);
long get_ram_size(volatile long *base, long size);
+enum system_states {
+ BAREBOX_STARTING,
+ BAREBOX_RUNNING,
+ BAREBOX_EXITING,
+};
+
+#if IN_PROPER
+extern enum system_states barebox_system_state;
+#else
+#define barebox_system_state BAREBOX_STARTING
+#endif
+
#endif
--
2.39.5
More information about the barebox
mailing list