[PATCH v5] disk: efi_loader: Improve disk image detection in efi_bootmgr

Ilias Apalodimas ilias.apalodimas at linaro.org
Mon Sep 8 08:15:13 CEST 2025


Hi Javier, Heinrich

On Fri, 5 Sept 2025 at 20:24, Javier Tia <javier.tia at linaro.org> wrote:
>
> Enhances the process for identifying disk images within the EFI boot
> manager. Utilize part_driver_lookup_type() to verify the validity of a
> downloaded file as a disk image, rather than depending on file
> extensions.
>
> part_driver_lookup_type() is now used in the prepare_loaded_image()
> function in the EFI boot manager to detect partitions on a block device
> created from a downloaded image. This allows the boot manager to boot
> from any disk image that can be recognized by a partition driver, not
> just ISO and IMG images.
>
> Update prepare_loaded_image() to create the ramdisk block device
> internally, obtain the blk_desc and use part_driver_lookup_type() to
> detect a valid partition table.
>
> In try_load_from_uri_path(), try prepare_loaded_image() first to detect
> disk images, and fall back to PE-COFF detection only if that fails.
>
> Include part.h in the EFI loader and export part_driver_lookup_type and
> add its prototype and documentation in include/part.h. This makes the
> partition-driver lookup available to other code paths that need to
> detect partition tables on a block descriptor.
>
> Signed-off-by: Javier Tia <javier.tia at linaro.org>

The patch looks ok now. Two more nits, but those can be taken care of
during mering
Reviewed-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>

44

[...]


> +       /* Create the ramdisk block device internally */
>         ramdisk_blk = mount_image(label, addr, size);
> -       if (!ramdisk_blk)
> -               return EFI_LOAD_ERROR;
> +       if (!ramdisk_blk) {
> +               log_err("Failed to create ramdisk block device\n");
> +               return EFI_DEVICE_ERROR;

This message will show up as an error even if we load an EFI app.
Perhaps switch to log_warn()?

> +       }
> +
> +       /* Get the block descriptor and detect partitions */
> +       desc = dev_get_uclass_plat(ramdisk_blk);
> +       if (!desc) {
> +               log_err("Failed to get block descriptor\n");
> +               ret = EFI_DEVICE_ERROR;
> +               goto err;
> +       }
> +
> +       /* Use part_driver_lookup_type for comprehensive partition detection */
> +       part_drv = part_driver_lookup_type(desc);
> +       if (!part_drv) {
> +               log_err("Image is not a valid disk image\n");
> +               ret = EFI_INVALID_PARAMETER;
> +               goto err;
> +       }
>
>         ret = fill_default_file_path(ramdisk_blk, dp);
>         if (ret != EFI_SUCCESS) {
> @@ -389,7 +414,6 @@ static efi_status_t prepare_loaded_image(u16 *label, ulong addr, ulong size,
>  err:
>         if (blkmap_destroy(ramdisk_blk->parent))
>                 log_err("Destroying blkmap failed\n");
> -
>         return ret;
>  }
>
> @@ -407,7 +431,7 @@ static efi_status_t efi_bootmgr_release_uridp(struct uridp_context *ctx)
>         if (!ctx)
>                 return ret;
>
> -       /* cleanup for iso or img image */
> +       /* cleanup for disk image */
>         if (ctx->ramdisk_blk_dev) {
>                 ret = efi_add_memory_map(ctx->image_addr, ctx->image_size,
>                                          EFI_CONVENTIONAL_MEMORY);
> @@ -452,6 +476,7 @@ static void EFIAPI efi_bootmgr_http_return(struct efi_event *event,
>         EFI_EXIT(ret);
>  }
>
> +

You don't need a new line here.

[...]


Cheers
/Ilias


More information about the U-Boot mailing list