summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2025-10-14 08:27:01 -0600
committerTom Rini <[email protected]>2025-10-14 08:27:01 -0600
commit14d36cd8da298f895053764632fd58c8afe4badb (patch)
tree1cdc43d2d9046481b06895ac6ed0b29bcd414565 /lib
parent78406dda9908394bc231a766e0b2259b3d95743c (diff)
parent377bc19fd92074bd32e6b29b9133037238ca54dd (diff)
Merge tag 'mix-next-14102025' of https://source.denx.de/u-boot/custodians/u-boot-tpm
TPM changes: Make all drive names defined with U_BOOT_DRIVER unique TEE changes: Rework things such that sandbox will also traverse the optee directory when SANDBOX_TEE is enabled, but only build one of the optee-specific files when OPTEE is enabled. EFI changes: Up to now we were relying on the file extension to accept and load an image over HTTP. We expected images to be either .iso or .img. By wiring up internal existing functions we can try to mount any file extension and reject it only if mounting fails. part_driver_lookup_type
Diffstat (limited to 'lib')
-rw-r--r--lib/efi_loader/efi_bootmgr.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 662993fb809..a687f4d8e85 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -17,6 +17,7 @@
#include <log.h>
#include <malloc.h>
#include <net.h>
+#include <part.h>
#include <efi_loader.h>
#include <efi_variable.h>
#include <asm/unaligned.h>
@@ -347,6 +348,9 @@ static efi_status_t fill_default_file_path(struct udevice *blk,
* @dp: pointer to default file device path
* @blk: pointer to created blk udevice
* Return: status code
+ *
+ * This function handles device creation internally and performs cleanup
+ * on error paths.
*/
static efi_status_t prepare_loaded_image(u16 *label, ulong addr, ulong size,
struct efi_device_path **dp,
@@ -355,10 +359,31 @@ static efi_status_t prepare_loaded_image(u16 *label, ulong addr, ulong size,
u64 pages;
efi_status_t ret;
struct udevice *ramdisk_blk;
+ struct blk_desc *desc;
+ struct part_driver *part_drv;
+ /* Create the ramdisk block device internally */
ramdisk_blk = mount_image(label, addr, size);
- if (!ramdisk_blk)
- return EFI_LOAD_ERROR;
+ if (!ramdisk_blk) {
+ log_warning("Failed to create ramdisk block device\n");
+ return EFI_DEVICE_ERROR;
+ }
+
+ /* 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) {
@@ -407,7 +432,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);
@@ -466,7 +491,6 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp,
{
char *s;
int err;
- int uri_len;
efi_status_t ret;
void *source_buffer;
efi_uintn_t source_size;
@@ -516,18 +540,15 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp,
image_size = ALIGN(image_size, SZ_2M);
/*
- * If the file extension is ".iso" or ".img", mount it and try to load
- * the default file.
- * If the file is PE-COFF image, load the downloaded file.
+ * Check if the downloaded file is a disk image or PE-COFF image.
+ * Try disk image detection first using prepare_loaded_image().
*/
- uri_len = strlen(uridp->uri);
- if (!strncmp(&uridp->uri[uri_len - 4], ".iso", 4) ||
- !strncmp(&uridp->uri[uri_len - 4], ".img", 4)) {
- ret = prepare_loaded_image(lo_label, image_addr, image_size,
- &loaded_dp, &blk);
- if (ret != EFI_SUCCESS)
- goto err;
+ /* First, try to treat the image as a disk image */
+ ret = prepare_loaded_image(lo_label, image_addr, image_size,
+ &loaded_dp, &blk);
+ if (ret == EFI_SUCCESS) {
+ /* Image is a disk image, set up for disk boot */
source_buffer = NULL;
source_size = 0;
} else if (efi_check_pe((void *)image_addr, image_size, NULL) == EFI_SUCCESS) {