From patchwork Sat Nov 15 18:51:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 700 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=1763232784; bh=7zyfsUQB/O0YecMiN5wxjOUCWSvma+zTaZ3TJNnpw74=; 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=IeT/8gkjUjE0rKv3o38d76RMy5ODHHWffutGw2Eel57AlHRSBw4gZZ46/W957PEwY aVf47cv/URo44fgzX6IXX24miWpGpNsATHs5qMfbJW6m9vu/AOQ8Ytd8MrWnhbrD60 A91f3s79DxTcaZp/PzmA9Fjiz3O1ysDqifaiMi5NTauMI6hINDkxGGCXD9+2/CLMBq qsZIl9xyR1QzLZpA0/B05WsRuxOdugZ4+U/nycD3hSF1bVcxy9GKfPnFMZmFVEVLCN J3BVfLgpjYXlFd21XYy5gV9TV5xLs9KV8hzRixXTTQfgiOTlx4il1zLaXf7wSIRL0P 5r4rFHJYJ745w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E7ADC68621 for ; Sat, 15 Nov 2025 11:53:04 -0700 (MST) 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 ZwR-LAtI8Quf for ; Sat, 15 Nov 2025 11:53:04 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232783; bh=7zyfsUQB/O0YecMiN5wxjOUCWSvma+zTaZ3TJNnpw74=; 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=Tw7Jr5EvCCtdNubRW5nQEqPoaR3tj/ZDGhMKo1ASJhEsnfR4Sp7LK6pLf+Ej5bwh6 HfJ/R2+tVwr/Pz62dQEtx0tT/qsAon8vADiAWeb3QpwFf5N07hyQ4MQ7RCpoyxzu6o ggpjWegawCBehSo/BoCnn5Nj43Dy7lcIXstl2ScBjwIXxqo/LD0AgbzNZ66XUfy5tR DKujYDIHnZ1rwmJRXbnrVXqqAZokfIXmQnuRdV3wkRp8CIDVLjTcQN1fbl3Nr8kBnv dEKBWHldt3DCjIF5pal9aLeecinUwczi1EcFj9jeP8LUokzte2r5dFSmxYMRyPpGAC A99yPy7LQumCA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7814C68570 for ; Sat, 15 Nov 2025 11:53:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232780; bh=jlk+6aOd7DwM5Sv4xpL2hlsXZ9SQhKSWsZYDWsV6nyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NX0rsu1xR8QklRfYZtytEgvXey8ht5RbR+8kZ5t1Frer1bHEWz+sQ8G6dr9zsBbvV wL7t+JrYY1U1sr60Lx/U5H3B5VYGgt0SATdo446jqQLP1gLLUcAFezUBDxzE8L7u/M Q4YniJK9ec+fC1GrRqlM7YWFlkp3hI0o4vIkkaQA7fHfsjQQcK496unetsURQmt2ov 4pwvwDwA0BtRuE3Nr0AB2ADecuwZgDyq7ckxWJkSqQf6kWezxW/o8Z0qNv3oE+c4aY KyL55n9Qh9Ov6kCWh6H9pRYQdMR+azFhhXSQUVeWOQx+H0HM04mnZwqxpu3PKAncIT Zw/OaC9L49kBw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F0A9A685D9; Sat, 15 Nov 2025 11:53:00 -0700 (MST) 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 0u17xADNG5fw; Sat, 15 Nov 2025 11:53:00 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232780; bh=sHkrjSDKXNsqh3GZHzNPHERZYrXMBy0vx0P7Rwx6YL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aiuYO8zUvmwQuC6m78aR95VDVRDCuCsiBqm7mVv+crod+eH4xBSRt2ykymxcrc7Rh SweWGLQ5SzbHceEemKBHyER4MqcZkQnNuLSgni9oZjbTfic737b/P8YgqDcuCRmg72 e0/8VDxFU3F/XKFLXsd79h1DownBhNevmEVp6I+JzVxS+Za8zd/LMWnjweQExrwHW9 HtWw1Et5p+K7idehWa48dXX8+TdR9Z/KMEOgSl6LUeTv/M2WAdcdO/XCDdGbzFt792 fbyJ1dVKFE/oFG2P1NBEVns1X4xpyDXZkcbOcBSaitcTMSppbx+rcTixsMY2a0T2Kk JzijR9F2Np1dQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5BAE766654; Sat, 15 Nov 2025 11:53:00 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 15 Nov 2025 11:51:51 -0700 Message-ID: <20251115185212.539268-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251115185212.539268-1-sjg@u-boot.org> References: <20251115185212.539268-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: RALI5JB5UHIRE627CNQUTCUSOAP523KS X-Message-ID-Hash: RALI5JB5UHIRE627CNQUTCUSOAP523KS 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: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 02/16] emulation: Support the bootcmd more generally 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 The code for obtaining a bootcmd from the host when running until QEMU is currently x86-specific. In fact it can be supported on other architecture. Move it into a common place and update the documentation. Signed-off-by: Simon Glass --- arch/x86/cpu/qemu/qemu.c | 28 ------------------------ board/emulation/common/Makefile | 3 +++ board/emulation/common/bootcmd.c | 37 ++++++++++++++++++++++++++++++++ doc/board/emulation/common.rst | 28 ++++++++++++++++++++++++ doc/board/emulation/index.rst | 1 + doc/board/emulation/qemu-x86.rst | 18 ++-------------- 6 files changed, 71 insertions(+), 44 deletions(-) create mode 100644 board/emulation/common/bootcmd.c create mode 100644 doc/board/emulation/common.rst diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c index 24916d867ee..b393205acb3 100644 --- a/arch/x86/cpu/qemu/qemu.c +++ b/arch/x86/cpu/qemu/qemu.c @@ -153,31 +153,3 @@ int mp_determine_pci_dstirq(int bus, int dev, int func, int pirq) return irq; } #endif - -#if CONFIG_IS_ENABLED(EVENT) -static int qemu_get_bootcmd(void *ctx, struct event *event) -{ - struct event_bootcmd *bc = &event->data.bootcmd; - enum fw_cfg_selector select; - struct udevice *qfw_dev; - ulong size; - - if (qfw_get_dev(&qfw_dev)) - return 0; - - if (qfw_locate_file(qfw_dev, "opt/u-boot/bootcmd", &select, &size)) - return 0; - if (!size) - return 0; - - /* Check if the command fits in the provided buffer with terminator */ - if (size >= bc->size) - return -ENOSPC; - - qfw_read_entry(qfw_dev, select, size, bc->bootcmd); - bc->bootcmd[size] = '\0'; - - return 0; -} -EVENT_SPY_FULL(EVT_BOOTCMD, qemu_get_bootcmd); -#endif diff --git a/board/emulation/common/Makefile b/board/emulation/common/Makefile index c5b452e7e34..a91e4f16fef 100644 --- a/board/emulation/common/Makefile +++ b/board/emulation/common/Makefile @@ -2,3 +2,6 @@ obj-$(CONFIG_SYS_MTDPARTS_RUNTIME) += qemu_mtdparts.o obj-$(CONFIG_SET_DFU_ALT_INFO) += qemu_dfu.o +ifdef CONFIG_QFW +obj-$(CONFIG_$(PHASE_)EVENT) += bootcmd.o +endif diff --git a/board/emulation/common/bootcmd.c b/board/emulation/common/bootcmd.c new file mode 100644 index 00000000000..6fc7c618c8f --- /dev/null +++ b/board/emulation/common/bootcmd.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + */ + +#include +#include +#include + +#if CONFIG_IS_ENABLED(EVENT) +static int qemu_get_bootcmd(void *ctx, struct event *event) +{ + struct event_bootcmd *bc = &event->data.bootcmd; + enum fw_cfg_selector select; + struct udevice *qfw_dev; + ulong size; + + if (qfw_get_dev(&qfw_dev)) + return 0; + + if (qfw_locate_file(qfw_dev, "opt/u-boot/bootcmd", &select, &size)) + return 0; + if (!size) + return 0; + + /* Check if the command fits in the provided buffer with terminator */ + if (size >= bc->size) + return -ENOSPC; + + qfw_read_entry(qfw_dev, select, size, bc->bootcmd); + bc->bootcmd[size] = '\0'; + + return 0; +} +EVENT_SPY_FULL(EVT_BOOTCMD, qemu_get_bootcmd); +#endif diff --git a/doc/board/emulation/common.rst b/doc/board/emulation/common.rst new file mode 100644 index 00000000000..90dde5f442a --- /dev/null +++ b/doc/board/emulation/common.rst @@ -0,0 +1,28 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Common features +=============== + +It is possible to specify the boot command directly using the fw_cfg interface. +This allows QEMU to control the boot command, which can be useful for automated +testing or scripting. To use this feature, create a file containing the boot +command and pass it to QEMU using the fw_cfg option. + +Here is an x86 example:: + + $ echo "qfw load; zboot 01000000 - 04000000 1b1ab50" > bootcmd.txt + $ qemu-system-x86_64 -nographic -bios path/to/u-boot.rom \ + -fw_cfg name=opt/u-boot/bootcmd,file=bootcmd.txt + +U-Boot will read the boot command from the firmware configuration and execute it +automatically during the boot process. This bypasses the normal distro boot +sequence. + +Note that the boot command is limited in length and should not exceed the boot +command buffer size. If the command is too long, U-Boot will fail to read it and +fall back to the default boot behavior. + +The :doc:`script` and build-efi scripts provide a `-c` option for this feature, +although it uses a string rather than a file. + +Note that ``CONFIG_QFW`` must be enabled for this feature to work. diff --git a/doc/board/emulation/index.rst b/doc/board/emulation/index.rst index 5a2a00ae225..6eccf7bad8a 100644 --- a/doc/board/emulation/index.rst +++ b/doc/board/emulation/index.rst @@ -8,6 +8,7 @@ Emulation acpi blkdev + common script qemu-arm qemu-mips diff --git a/doc/board/emulation/qemu-x86.rst b/doc/board/emulation/qemu-x86.rst index c2862e631ee..27f0d273f38 100644 --- a/doc/board/emulation/qemu-x86.rst +++ b/doc/board/emulation/qemu-x86.rst @@ -116,22 +116,8 @@ supports 32-bit. Specifying a boot command -------------------------- -It is possible to specify the boot command directly using the fw_cfg interface. -This allows QEMU to control the boot command, which can be useful for automated -testing or scripting. To use this feature, create a file containing the boot -command and pass it to QEMU using the fw_cfg option:: - - $ echo "qfw load; zboot 01000000 - 04000000 1b1ab50" > bootcmd.txt - $ qemu-system-x86_64 -nographic -bios path/to/u-boot.rom \ - -fw_cfg name=opt/u-boot/bootcmd,file=bootcmd.txt - -U-Boot will read the boot command from the firmware configuration and execute it -automatically during the boot process. This bypasses the normal distro boot -sequence. - -Note that the boot command is limited in length and should not exceed the boot -command buffer size. If the command is too long, U-Boot will fail to read it and -fall back to the default boot behavior. +See :doc:`common` for details on how to provide a boot command to U-Boot on +startup. Booting distros ---------------