From patchwork Mon Oct 6 23:21:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 533 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=1759792983; bh=kh48lDFhq6G7xNwSofH+K0OKkSiwuofrYA2wFvhPrf0=; 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=SJQNEf20tx5tYcz1A6/ti8XB7ZiVUbxyXEHrxNwK5ocue/eZRr4SjQaRnGy587mH6 zK8zbtRMDLToTOAhThBP9Fz6wzK/AzHAwOLdgYJoiaO+zgMRJVl/fF5BI/ztZhH6Yp SzJiyoeRnHYSpm5J2KGumxQLT4QUU3BsfTnPSr4I7ISmBqDc9RFNbCTpQFoV/XvgmF +8YEk79zK5PNt+rneCBzSCBu9nNxqUXtE+smq6d6jweWeSrYJxLdjmc/dXAKCn8Lpp 9rMu2AlAg0qj8Nq0BtEokB/weRSee7XcL3M9YMdrFqRjTpJ95JDN4Eam7vdJTaLcOK uPTeqj+JDoAmw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1C45D67DB4 for ; Mon, 6 Oct 2025 17:23:03 -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 1hfqnijPtoJe for ; Mon, 6 Oct 2025 17:23:03 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759792983; bh=kh48lDFhq6G7xNwSofH+K0OKkSiwuofrYA2wFvhPrf0=; 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=SJQNEf20tx5tYcz1A6/ti8XB7ZiVUbxyXEHrxNwK5ocue/eZRr4SjQaRnGy587mH6 zK8zbtRMDLToTOAhThBP9Fz6wzK/AzHAwOLdgYJoiaO+zgMRJVl/fF5BI/ztZhH6Yp SzJiyoeRnHYSpm5J2KGumxQLT4QUU3BsfTnPSr4I7ISmBqDc9RFNbCTpQFoV/XvgmF +8YEk79zK5PNt+rneCBzSCBu9nNxqUXtE+smq6d6jweWeSrYJxLdjmc/dXAKCn8Lpp 9rMu2AlAg0qj8Nq0BtEokB/weRSee7XcL3M9YMdrFqRjTpJ95JDN4Eam7vdJTaLcOK uPTeqj+JDoAmw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 092E467F03 for ; Mon, 6 Oct 2025 17:23:03 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759792980; bh=qXhglvSEQgMlKx3y1OpFL75mw53j/Le/6sx8uw1PaA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WcwEsOcbBq/T6c7fxYiuS7yajV5SSVyWNmLK0x6iP1sNqrA34sLX41jZ/kx2jjrWE 7XWAw7Yim6CnsDXNAvHdHZzQ3iuEn6ujOTTbbMr3oTMVlDXZDV81/cpSjZWAhaP9qd jcMcDr/UkIsh6SnAbRHEv5fyjaJhIJ2fhC2Txcz69VQRpsGW9uZpq+f8RuweY44awO PG9fKLxnFB+O7V2lCjZm/RmzIXZlnOGpCAQg4iEkSr5HWLhJDSV1bFDts34+9QLEy4 eyNXLxa2zTo4E37DW0tY3tnrmBetaH/Vod69Nd8/Qf6JTsKx2rmk7rMQVoC65WF9tq QYc8nQZZyVUpw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 130E167DB4; Mon, 6 Oct 2025 17:23:00 -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 WAWka-_VH12H; Mon, 6 Oct 2025 17:23:00 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759792978; bh=arwzHrkvudjTR8eLaBbrvP/sck5HKn2WrHPNDTXxW2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xa3++9Z2ZUIq+KxvUY+kHcD/GAEiLi0xOqVpC+H3MWmbjrziTAtnkFSS9OV0j4tSF klGun61n+lS3is20kG0zh0syDl5pNTKNHOkXefrOvXoXXOJnm6IJiePpFRd4LFVGUl LM9OKaR6BIWVJtqyuTTtGX1nn4IlNj8tyV8CvQHD6JOMYZTaFgWPyMXRSoyUY7JZol rbwbov6DRDV6F56nSMAc0T1clUIaRhQs2v+yZIWg6uOMn3VjhK4lzXNNy9wF/0QGsR lN/6ckSOQpDJPL4tK7cjDapeLkxTCBQ9d3wksvUQQwS8AHfFkyTuWRctgN/E1NpZcq Bq/2S3xvYq8TA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 52A2E67F03; Mon, 6 Oct 2025 17:22:58 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 6 Oct 2025 17:21:44 -0600 Message-ID: <20251006232236.2091941-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251006232236.2091941-1-sjg@u-boot.org> References: <20251006232236.2091941-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: VYQ2RA26OKAF55UFLFA5YCFAZ5ID6VTY X-Message-ID-Hash: VYQ2RA26OKAF55UFLFA5YCFAZ5ID6VTY 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 02/17] 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 --- 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; }; /**