From patchwork Tue Oct 7 17:05:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 549 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856783; bh=Jyup7fKnUi6lnBdkiIY+IigHLngggxPJjE15EScI6fg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=HxMBXnQkyy8v5ieOw15Co19mgySMuaByG+schx9InGOLKqRgfub7izd8JBObm324x Z+GjJtKGgGhiCkZvXJqEGxr0IUVKxmcc0YKugYZZXKdm8VUIeA2/ucZu1pDMG07VpU ciO3IDgOqrSH3WExYuim27g/zJ6vOik2fELGJ4/CfEv82jb0fIyR0HOSXiAy8y1aTD SHNHHyqRlr5UwuoIbzp87eyG+hm6cDsNS33kOKy1vDBA+GEGTQE/1moiccqK+ryC7a 75z1hrXr2kMLURXjCCZfrGQvmuvYccNml+eoz3o+lSqyhUsu0x7cbGtBzAtv+sixGO 77bs9U2KEm+pw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 18B9F68000 for ; Tue, 7 Oct 2025 11:06:23 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id cqnKWTLYeIqh for ; Tue, 7 Oct 2025 11:06:23 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856781; bh=Jyup7fKnUi6lnBdkiIY+IigHLngggxPJjE15EScI6fg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=KOz2f4A/iuqrr2TlXo1Ot3gfvQAGgaSNpqe9bjg61L0RDmFJvFO38GVYJ/GARoTou Nj5slNlJXACQysJ/Z5IEuFRvagvqi1jA2pGy6mK3CiWrjpxZVMhfxOo19XQk0sgzw5 RCoNlnKa9NM/wprTtUPZd8NPnFURHoPxvWlLBe1f+sG2+dcjkQRVqIGyzojl8gPYBv Xz9JRqL7Qq6xH9I7WSB1yIzczq0MFZ+g5SXQ9f3syivWuK4/pjIeq4IbSbz9m5NtHg zj5/khRIdBwre783L+JawyDHfvUi2c9BDYNdpuR5BGs1D2T9ulqBp5dxSzzoflf/sJ eBVPbceMV00Cw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 78B5967FF8 for ; Tue, 7 Oct 2025 11:06:21 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856778; bh=UR0zhdgbF0J4e7XfgR/tGFsUuqk/zthUY7oBKjv8zkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AyHt9V8ICLR5oMmZfNoNIOWt6hT63I1r2LmhOmunllIR5lASAUt2U4Vh3GCDx5G1A VSoZDEl5jkZt/DOgx784WeWhm6AqUMMfhrdOkzGdwgKBG7S6b7borD01nUtybGe2F0 ouhwxcS2svbCH9sik+xZ9i29nhOsrUyew2wBB8ezDCCszazUcNOSJhMqNSrHVdyEvL qhD0OD5SDV06z6UR/6XPncev8CvbsljCY6xVd5I+YGFfsn9MiA6lvLOUUttDieA7Tz 55dYdwuGAustt6H+g/siZXgV9d5XNT//EBvvyAX62qkjg6ZKQIycQUunoAVV3oQa69 /m3Q/yQ8K+OuA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B51CC67F1E; Tue, 7 Oct 2025 11:06:18 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id SMAxOLHm6vYd; Tue, 7 Oct 2025 11:06:18 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856777; bh=8+7tYhZC9W5m5jS3LjmHqa19UpyKWqAUt734pxSpqX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KJf31NmUrNnK8mdgltQdFK52cM0lU2a4U6mzwx2gRnsYyzCwnggJPGtJpXH+mSYVh y5fVXJuiwx0OdqnWIWXnMuLKcf8VpoCyihpXhRz25MQ199MSPoa9UKSpZKBtPHdB5Q lPh754WTVd4ZToYNhwWfQO5fuZVGA8N0r3Pt8++k9UF+PkadshIHjRW+eI6gZ1vPjn u4qv9o1cWeyhY7vIexBQ+rPU3gOl8VZs4wXGkTNbmNe2lT0eiK0StkGYiikhuZfs4v 5vhMEVZ3GsYkyFZWG+2j28FVXd553V5q/MFcAUNa++Myx2Oz7jbbHqn58lC1I5IrlV 0a9nLvHDCLejg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id BDA8667FF7; Tue, 7 Oct 2025 11:06:16 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 7 Oct 2025 11:05:16 -0600 Message-ID: <20251007170549.541981-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251007170549.541981-1-sjg@u-boot.org> References: <20251007170549.541981-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: POTXHJFVWZY4R7TTZKCSNHL6ODEN7NQT X-Message-ID-Hash: POTXHJFVWZY4R7TTZKCSNHL6ODEN7NQT X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 02/20] event: Add EVT_BOOTCMD event for custom boot commands List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass 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 Signed-off-by: Simon Glass --- (no changes since v1) common/event.c | 1 + common/main.c | 32 +++++++++++++++++++++++++++++++- include/event.h | 22 ++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/common/event.c b/common/event.c index a48ca6c549d..44f32035775 100644 --- a/common/event.c +++ b/common/event.c @@ -49,6 +49,7 @@ const char *const type_name[] = { /* main loop events */ "main_loop", + "bootcmd", /* booting */ "boot_os_addr", diff --git a/common/main.c b/common/main.c index b0b6e74f5d3..06e5193ecb9 100644 --- a/common/main.c +++ b/common/main.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/include/event.h b/include/event.h index 5fecaa66e80..2f0eac61633 100644 --- a/include/event.h +++ b/include/event.h @@ -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; }; /**