]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: fix efi_dp_from_file()
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sat, 13 May 2023 08:36:21 +0000 (10:36 +0200)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sat, 13 May 2023 09:09:51 +0000 (11:09 +0200)
* When called from efi_dp_from_name() we miss to append the filename
  for non-block devices.
* expand_media_path() could be simplified by using efi_dp_from_file to
  prepend the device path of the boot device.

This can be avoided by passing a device path to efi_dp_from_file() instead
of a block device descriptor and a partition number.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
cmd/bootefi.c
include/efi_loader.h
lib/efi_loader/efi_bootmgr.c
lib/efi_loader/efi_device_path.c

index 8aa15a64c83617eb25de641e2ebddd82803e9338..5c0afec1544d96fff08d9664d00d391ae45f9010 100644 (file)
@@ -589,7 +589,7 @@ static efi_status_t bootefi_test_prepare
        if (!bootefi_device_path)
                return EFI_OUT_OF_RESOURCES;
 
-       bootefi_image_path = efi_dp_from_file(NULL, 0, path);
+       bootefi_image_path = efi_dp_from_file(NULL, path);
        if (!bootefi_image_path) {
                ret = EFI_OUT_OF_RESOURCES;
                goto failure;
index b395eef9e790a984ef1d51c437d5064560269713..38d7f66bab516f6fcc063c33dff661c2e1ba8925 100644 (file)
@@ -810,7 +810,7 @@ bool efi_dp_is_multi_instance(const struct efi_device_path *dp);
 struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part);
 /* Create a device node for a block device partition. */
 struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part);
-struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
+struct efi_device_path *efi_dp_from_file(const struct efi_device_path *dp,
                                         const char *path);
 struct efi_device_path *efi_dp_from_eth(void);
 struct efi_device_path *efi_dp_from_mem(uint32_t mem_type,
index 4b24b41047238a10af2e7525e6e4c6ef6cf338f1..7ac5f89f76d64b524e30a55831ae340088126d0c 100644 (file)
@@ -47,7 +47,7 @@ const efi_guid_t efi_guid_bootmenu_auto_generated =
 static
 struct efi_device_path *expand_media_path(struct efi_device_path *device_path)
 {
-       struct efi_device_path *dp, *rem, *full_path;
+       struct efi_device_path *rem, *full_path;
        efi_handle_t handle;
 
        if (!device_path)
@@ -58,15 +58,12 @@ struct efi_device_path *expand_media_path(struct efi_device_path *device_path)
         * simple file system protocol, append a default file name to support
         * booting from removable media.
         */
-       dp = device_path;
-       handle = efi_dp_find_obj(dp, &efi_simple_file_system_protocol_guid,
-                                &rem);
+       handle = efi_dp_find_obj(device_path,
+                                &efi_simple_file_system_protocol_guid, &rem);
        if (handle) {
                if (rem->type == DEVICE_PATH_TYPE_END) {
-                       dp = efi_dp_from_file(NULL, 0,
-                                             "/EFI/BOOT/" BOOTEFI_NAME);
-                       full_path = efi_dp_append(device_path, dp);
-                       efi_free_pool(dp);
+                       full_path = efi_dp_from_file(device_path,
+                                                    "/EFI/BOOT/" BOOTEFI_NAME);
                } else {
                        full_path = efi_dp_dup(device_path);
                }
index a9b0ea401585d426d97d91c31c2970ccd161e5b8..71923b1127350991b0840aea7b3c901a516ab597 100644 (file)
@@ -1002,47 +1002,31 @@ static void path_to_uefi(void *uefi, const char *src)
 }
 
 /**
- * efi_dp_from_file() - create device path for file
+ * efi_dp_from_file() - append file path node to device path.
  *
- * The function creates a device path from the block descriptor @desc and the
- * partition number @part and appends a device path node created describing the
- * file path @path.
- *
- * If @desc is NULL, the device path will not contain nodes describing the
- * partition.
- * If @path is an empty string "", the device path will not contain a node
- * for the file path.
- *
- * @desc:      block device descriptor or NULL
- * @part:      partition number
- * @path:      file path on partition or ""
+ * @dp:                device path or NULL
+ * @path:      file path or NULL
  * Return:     device path or NULL in case of an error
  */
-struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
-               const char *path)
+struct efi_device_path *efi_dp_from_file(const struct efi_device_path *dp,
+                                        const char *path)
 {
        struct efi_device_path_file_path *fp;
        void *buf, *pos;
-       size_t dpsize = 0, fpsize;
-
-       if (desc)
-               dpsize = dp_part_size(desc, part);
+       size_t dpsize, fpsize;
 
+       dpsize = efi_dp_size(dp);
        fpsize = sizeof(struct efi_device_path) +
                 2 * (utf8_utf16_strlen(path) + 1);
        if (fpsize > U16_MAX)
                return NULL;
 
-       dpsize += fpsize;
-
-       buf = efi_alloc(dpsize + sizeof(END));
+       buf = efi_alloc(dpsize + fpsize + sizeof(END));
        if (!buf)
                return NULL;
 
-       if (desc)
-               pos = dp_part_fill(buf, desc, part);
-       else
-               pos = buf;
+       memcpy(buf, dp, dpsize);
+       pos = buf + dpsize;
 
        /* add file-path: */
        if (*path) {
@@ -1218,8 +1202,7 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr,
        if (!path)
                return EFI_SUCCESS;
 
-       *file = efi_dp_from_file(desc, part, path);
-
+       *file = efi_dp_from_file(dp, path);
        if (!*file)
                return EFI_OUT_OF_RESOURCES;