[Concept,02/17] event: Add EVT_BOOTCMD event for custom boot commands
Commit Message
From: Simon Glass <sjg@chromium.org>
Add a new event that is triggered in main_loop() before
autoboot_command(). This allows platform code to provide a custom
bootcmd string via the event system.
The event uses struct event_bootcmd which provides a buffer for the
bootcmd string and its size. Platform event handlers can write their
custom bootcmd to this buffer.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---
common/event.c | 1 +
common/main.c | 32 +++++++++++++++++++++++++++++++-
include/event.h | 22 ++++++++++++++++++++++
3 files changed, 54 insertions(+), 1 deletion(-)
@@ -49,6 +49,7 @@ const char *const type_name[] = {
/* main loop events */
"main_loop",
+ "bootcmd",
/* booting */
"boot_os_addr",
@@ -14,6 +14,7 @@
#include <command.h>
#include <console.h>
#include <env.h>
+#include <event.h>
#include <fdtdec.h>
#include <init.h>
#include <net.h>
@@ -38,10 +39,35 @@ static void run_preboot_environment_command(void)
}
}
+static const char *get_autoboot_cmd(char *buf, int size)
+{
+ const char *s = NULL;
+
+ if (IS_ENABLED(CONFIG_EVENT)) {
+ struct event_bootcmd event_bootcmd;
+ int ret;
+
+ event_bootcmd.bootcmd = buf;
+ event_bootcmd.size = size;
+ buf[0] = '\0';
+
+ ret = event_notify(EVT_BOOTCMD, &event_bootcmd,
+ sizeof(event_bootcmd));
+ if (ret)
+ return NULL;
+
+ if (buf[0] != '\0')
+ s = buf;
+ }
+
+ return s;
+}
+
/* We come here after U-Boot is initialised and ready to process commands */
void main_loop(void)
{
const char *s;
+ char bootcmd_buf[CONFIG_SYS_CBSIZE];
bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
@@ -64,7 +90,11 @@ void main_loop(void)
process_button_cmds();
- s = bootdelay_process();
+ /* Allow platform code to provide bootcmd via event */
+ s = get_autoboot_cmd(bootcmd_buf, sizeof(bootcmd_buf));
+ if (!s)
+ s = bootdelay_process();
+
if (cli_process_fdt(&s))
cli_secure_boot_cmd(s);
@@ -172,6 +172,16 @@ enum event_t {
*/
EVT_MAIN_LOOP,
+ /**
+ * @EVT_BOOTCMD:
+ * This event is triggered in main_loop() before autoboot_command().
+ * It allows platform code to provide a custom bootcmd string.
+ * Its parameter is of type struct event_bootcmd.
+ * The event handler can write the bootcmd to the provided buffer.
+ * A non-zero return value causes the boot to fail.
+ */
+ EVT_BOOTCMD,
+
/**
* @EVT_BOOT_OS_ADDR:
* Triggered immediately before the OS is loaded into its final address
@@ -270,6 +280,18 @@ union event_data {
struct event_bootm_final {
enum bootm_final_t flags;
} bootm_final;
+
+ /**
+ * struct event_bootcmd - bootcmd override
+ *
+ * @bootcmd: Buffer for bootcmd string (provided by caller, must be an
+ * empty string on entry)
+ * @size: Size of bootcmd buffer
+ */
+ struct event_bootcmd {
+ char *bootcmd;
+ int size;
+ } bootcmd;
};
/**