event: Add EVT_BOOTCMD event for custom boot commands

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>
This commit is contained in:
Simon Glass
2025-10-05 06:18:01 -06:00
parent 1997712001
commit 69891885b7
3 changed files with 54 additions and 1 deletions

View File

@@ -49,6 +49,7 @@ const char *const type_name[] = {
/* main loop events */
"main_loop",
"bootcmd",
/* booting */
"boot_os_addr",

View File

@@ -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);

View File

@@ -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;
};
/**