From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: chalianis1@gmail.com, s.hauer@pengutronix.de
Cc: barebox@lists.infradead.org, Ahmad Fatoum <a.fatoum@barebox.org>
Subject: Re: [PATCH 09/11] efi: payload: bootm: add support for fit image
Date: Mon, 6 Oct 2025 13:41:14 +0200 [thread overview]
Message-ID: <d59489be-c41c-4ed5-9276-0a5f79d35239@pengutronix.de> (raw)
In-Reply-To: <20251006041512.1360284-9-chalianis1@gmail.com>
On 10/6/25 6:15 AM, chalianis1@gmail.com wrote:
> From: Ahmad Fatoum <a.fatoum@barebox.org>
>
> Extend the EFI payload boot flow to support loading kernel, initrd,
> and devicetree directly from a FIT image. When a FIT is present,
> the loader extracts the relevant subimages ("kernel", "ramdisk",
> and "fdt") also support falling back to external files when possible.
>
> Signed-off-by: Chali Anis <chalianis1@gmail.com>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> efi/payload/Kconfig | 1 +
> efi/payload/bootm.c | 125 ++++++++++++++++++++++++++++++++++++--------
> 2 files changed, 104 insertions(+), 22 deletions(-)
>
> diff --git a/efi/payload/Kconfig b/efi/payload/Kconfig
> index e3a6a72d6a1c..4fb866210a69 100644
> --- a/efi/payload/Kconfig
> +++ b/efi/payload/Kconfig
> @@ -32,6 +32,7 @@ config EFI_HANDOVER_PROTOCOL
>
> config EFI_PAYLOAD_BOOTM
> bool "EFI bootm protocol"
> + select BOOTM_FITIMAGE
> default !X86
>
> endif
> diff --git a/efi/payload/bootm.c b/efi/payload/bootm.c
> index d0e995be5d7c..3e9ccd42bf7f 100644
> --- a/efi/payload/bootm.c
> +++ b/efi/payload/bootm.c
> @@ -34,11 +34,74 @@
> #include "image.h"
> #include "setup_header.h"
>
> +static bool ramdisk_is_fit(struct image_data *data)
> +{
> + struct stat st;
> +
> + if (bootm_signed_images_are_forced())
> + return true;
> +
> + if (data->initrd_file) {
> + if (!stat(data->initrd_file, &st) && st.st_size > 0)
> + return false;
> + }
> +
> + return data->os_fit ? fit_has_image(data->os_fit,
> + data->fit_config, "ramdisk") > 0 : false;
> +}
> +
> +static bool fdt_is_fit(struct image_data *data)
> +{
> + struct stat st;
> +
> + if (bootm_signed_images_are_forced())
> + return true;
> +
> + if (data->oftree_file) {
> + if (!stat(data->oftree_file, &st) && st.st_size > 0)
> + return false;
> + }
> +
> + return data->os_fit ? fit_has_image(data->os_fit,
> + data->fit_config, "fdt") > 0 : false;
> +}
> +
> static int efi_load_os(struct image_data *data,
> struct efi_loaded_image **loaded_image,
> efi_handle_t *handle)
> {
> - return efi_load_image(data->os_file, loaded_image, handle);
> + efi_status_t efiret;
> + efi_handle_t h;
> +
> + if (!data->os_fit)
> + return efi_load_image(data->os_file, loaded_image, handle);
> +
> + if (!data->fit_kernel)
> + return -ENOENT;
> +
> + efiret = BS->load_image(false, efi_parent_image, efi_device_path,
> + (void *)data->fit_kernel, data->fit_kernel_size, &h);
> + if (EFI_ERROR(efiret)) {
> + pr_err("failed to LoadImage: %s\n", efi_strerror(efiret));
> + goto out_mem;
> + };
> +
> + efiret = BS->open_protocol(h, &efi_loaded_image_protocol_guid,
> + (void **)loaded_image, efi_parent_image,
> + NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> + if (EFI_ERROR(efiret)) {
> + pr_err("failed to OpenProtocol: %s\n", efi_strerror(efiret));
> + goto out_unload;
> + }
> +
> + *handle = h;
> +
> + return 0;
> +
> +out_unload:
> + BS->unload_image(h);
> +out_mem:
> + return -efi_errno(efiret);
> }
>
> static int efi_load_ramdisk(struct image_data *data, void **initrd)
> @@ -47,17 +110,26 @@ static int efi_load_ramdisk(struct image_data *data, void **initrd)
> void *initrd_mem;
> int ret;
>
> - if (!data->initrd_file)
> - return 0;
> -
> - pr_info("Loading ramdisk from '%s'\n", data->initrd_file);
> -
> - initrd_mem = read_file(data->initrd_file, &initrd_size);
> - if (!initrd_mem) {
> - ret = -errno;
> - pr_err("Failed to read initrd from file '%s': %m\n",
> - data->initrd_file);
> - return ret;
> + if (ramdisk_is_fit(data)) {
> + ret = fit_open_image(data->os_fit, data->fit_config, "ramdisk",
> + (const void **)&initrd_mem, &initrd_size);
> + if (ret) {
> + pr_err("Cannot open ramdisk image in FIT image: %m\n");
> + return ret;
> + }
> + } else {
> + if (!data->initrd_file)
> + return 0;
> +
> + pr_info("Loading ramdisk from '%s'\n", data->initrd_file);
> +
> + initrd_mem = read_file(data->initrd_file, &initrd_size);
> + if (!initrd_mem) {
> + ret = -errno;
> + pr_err("Failed to read initrd from file '%s': %m\n",
> + data->initrd_file);
> + return ret;
> + }
> }
>
> ret = efi_initrd_register(initrd_mem, initrd_size);
> @@ -84,16 +156,25 @@ static int efi_load_fdt(struct image_data *data, void **fdt)
> unsigned long of_size;
> int ret;
>
> - if (!data->oftree_file)
> - return 0;
> -
> - pr_info("Loading devicetree from '%s'\n", data->oftree_file);
> -
> - of_tree = read_file(data->oftree_file, &of_size);
> - if (!of_tree) {
> - ret = -errno;
> - pr_err("Failed to read oftree: %m\n");
> - return ret;
> + if (fdt_is_fit(data)) {
> + ret = fit_open_image(data->os_fit, data->fit_config, "fdt",
> + (const void **)&of_tree, &of_size);
> + if (ret) {
> + pr_err("Cannot open FDT image in FIT image: %m\n");
> + return ret;
> + }
> + } else {
> + if (!data->oftree_file)
> + return 0;
> +
> + pr_info("Loading devicetree from '%s'\n", data->oftree_file);
> +
> + of_tree = read_file(data->oftree_file, &of_size);
> + if (!of_tree) {
> + ret = -errno;
> + pr_err("Failed to read oftree: %m\n");
> + return ret;
> + }
> }
>
> efiret = BS->allocate_pages(EFI_ALLOCATE_ANY_PAGES,
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2025-10-06 11:41 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-06 4:15 [PATCH 01/11] common: filetype: add detection for x86 Linux kernel images chalianis1
2025-10-06 4:15 ` [PATCH 02/11] efi: payload: split out payload Kconfig symbols chalianis1
2025-10-06 4:15 ` [PATCH 03/11] efi: payload: add support for EFI initrd media protocol chalianis1
2025-10-06 11:31 ` Ahmad Fatoum
2025-10-06 4:15 ` [PATCH 04/11] tlsf: move kasan_poison_shadow into tlsf_add_pool chalianis1
2025-10-06 4:15 ` [PATCH 05/11] tlsf: support on-demand requesting memory from external store chalianis1
2025-10-06 4:15 ` [PATCH 06/11] efi: payload: earlymem: allocate only the barebox needs in term of memory chalianis1
2025-10-06 11:32 ` Ahmad Fatoum
2025-10-06 4:15 ` [PATCH 07/11] efi: payload: split image handling from legacy handover boot chalianis1
2025-10-06 11:37 ` Ahmad Fatoum
2025-10-06 4:15 ` [PATCH 08/11] efi: payload: bootm: add support for efi stub boot chalianis1
2025-10-06 11:40 ` Ahmad Fatoum
2025-10-06 4:15 ` [PATCH 09/11] efi: payload: bootm: add support for fit image chalianis1
2025-10-06 11:41 ` Ahmad Fatoum [this message]
2025-10-06 4:15 ` [PATCH 10/11] efi: payload: make selectable without COMPILE_TEST chalianis1
2025-10-06 4:15 ` [PATCH 11/11] ARM: efi: add a generic defconfig for v8 efi payload chalianis1
2025-10-06 11:41 ` Ahmad Fatoum
2025-10-06 11:39 ` [PATCH 01/11] common: filetype: add detection for x86 Linux kernel images Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d59489be-c41c-4ed5-9276-0a5f79d35239@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
--cc=chalianis1@gmail.com \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox