From 76759e0086cc3804412fd5f6b330196698753488 Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Tue, 2 May 2023 07:47:28 +0300 Subject: doc: signature: update algorithms support description U-Boot supports more hash and verification algorithms these days. Signed-off-by: Baruch Siach Reviewed-by: Simon Glass --- doc/uImage.FIT/signature.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/uImage.FIT/signature.txt b/doc/uImage.FIT/signature.txt index c71280b63b..bc123f512f 100644 --- a/doc/uImage.FIT/signature.txt +++ b/doc/uImage.FIT/signature.txt @@ -42,8 +42,8 @@ device. Algorithms ---------- In principle any suitable algorithm can be used to sign and verify a hash. -At present only one class of algorithms is supported: SHA1 hashing with RSA. -This works by hashing the image to produce a 20-byte hash. +U-Boot supports a few hashing and verification algorithms. See below for +details. While it is acceptable to bring in large cryptographic libraries such as openssl on the host side (e.g. mkimage), it is not desirable for U-Boot. -- cgit v1.2.1 From e7a1dfa23fdc64cd3e61f0b2dff2917d8b84ee33 Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Tue, 2 May 2023 07:47:29 +0300 Subject: doc: signature: update algorithm addition description U-Boot now uses the U_BOOT_CRYPTO_ALGO() macro. Signed-off-by: Baruch Siach Reviewed-by: Simon Glass --- doc/uImage.FIT/signature.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/uImage.FIT/signature.txt b/doc/uImage.FIT/signature.txt index bc123f512f..b6707417ff 100644 --- a/doc/uImage.FIT/signature.txt +++ b/doc/uImage.FIT/signature.txt @@ -56,10 +56,10 @@ of data from the FDT and exponentiation mod n. Code size impact is a little under 5KB on Tegra Seaboard, for example. It is relatively straightforward to add new algorithms if required. If -another RSA variant is needed, then it can be added to the table in -image-sig.c. If another algorithm is needed (such as DSA) then it can be -placed alongside rsa.c, and its functions added to the table in image-sig.c -also. +another RSA variant is needed, then it can be added with the +U_BOOT_CRYPTO_ALGO() macro. If another algorithm is needed (such as DSA) then +it can be placed in a directory alongside lib/rsa/, and its functions added +using U_BOOT_CRYPTO_ALGO(). Creating an RSA key pair and certificate -- cgit v1.2.1 From cc492b93bed14a2a393c0076fac8419d9e1856c2 Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Tue, 2 May 2023 07:47:30 +0300 Subject: doc: signature: describe how to enable ECDSA Signed-off-by: Baruch Siach Reviewed-by: Simon Glass --- doc/uImage.FIT/signature.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/uImage.FIT/signature.txt b/doc/uImage.FIT/signature.txt index b6707417ff..240244b30e 100644 --- a/doc/uImage.FIT/signature.txt +++ b/doc/uImage.FIT/signature.txt @@ -439,6 +439,7 @@ be enabled: CONFIG_FIT_SIGNATURE - enable signing and verification in FITs CONFIG_RSA - enable RSA algorithm for signing +CONFIG_ECDSA - enable ECDSA algorithm for signing WARNING: When relying on signed FIT images with required signature check the legacy image format is default disabled by not defining -- cgit v1.2.1 From 179666c56134169faca697bf72ec46956f6c829c Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Tue, 2 May 2023 07:47:31 +0300 Subject: doc: signature: trim the future work list Since U-Boot supports more RSA/SHA variants, as well as ECDSA, remove these items from the TODO list. Signed-off-by: Baruch Siach Reviewed-by: Simon Glass --- doc/uImage.FIT/signature.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/uImage.FIT/signature.txt b/doc/uImage.FIT/signature.txt index 240244b30e..21eb3894aa 100644 --- a/doc/uImage.FIT/signature.txt +++ b/doc/uImage.FIT/signature.txt @@ -695,8 +695,6 @@ bootm. Possible Future Work -------------------- -- Add support for other RSA/SHA variants, such as rsa4096,sha512. -- Other algorithms besides RSA - More sandbox tests for failure modes - Passwords for keys/certificates - Perhaps implement OAEP -- cgit v1.2.1 From 0c97e771d02c15914562df7df775ab7d6cf94682 Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Tue, 2 May 2023 13:21:46 +0300 Subject: doc: devicetree: fix u-boot.bin filename typo Signed-off-by: Baruch Siach Reviewed-by: Simon Glass Signed-off-by: Heinrich Schuchardt --- doc/develop/devicetree/control.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst index 0b3b32be1b..cbb65c9b17 100644 --- a/doc/develop/devicetree/control.rst +++ b/doc/develop/devicetree/control.rst @@ -100,7 +100,7 @@ and development only and is not recommended for production devices. If CONFIG_OF_SEPARATE is defined, then it will be built and placed in a u-boot.dtb file alongside u-boot-nodtb.bin with the combined result placed -in u-boot.bin so you can still just flash u-boot,bin onto your board. If you are +in u-boot.bin so you can still just flash u-boot.bin onto your board. If you are using CONFIG_SPL_FRAMEWORK, then u-boot.img will be built to include the device tree binary. -- cgit v1.2.1 From 227d3b3e0af02918592dda19aefa379e9ea20887 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 7 May 2023 08:39:34 +0200 Subject: fwu: fix config FWU_MULTI_BANK_UPDATE Symbol CONFIG_EFI_SETUP_EARLY does not exist anymore. CONFIG_FWU_MULTI_BANK_UPDATE without CONFIG_FWU_MDATA results in lib/fwu_updates/fwu.c:49: undefined reference to `fwu_get_mdata' Fixes: 86794052418b ("FWU: Add support for the FWU Multi Bank Update feature") Fixes: 023d9c93932c ("efi_loader: remove CONFIG_EFI_SETUP_EARLY") Signed-off-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas Acked-by: Sughosh Ganu --- lib/fwu_updates/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fwu_updates/Kconfig b/lib/fwu_updates/Kconfig index 78759e6618..71f34793d9 100644 --- a/lib/fwu_updates/Kconfig +++ b/lib/fwu_updates/Kconfig @@ -2,7 +2,7 @@ config FWU_MULTI_BANK_UPDATE bool "Enable FWU Multi Bank Update Feature" depends on EFI_CAPSULE_ON_DISK select PARTITION_TYPE_GUID - select EFI_SETUP_EARLY + select FWU_MDATA imply EFI_CAPSULE_ON_DISK_EARLY select EVENT help -- cgit v1.2.1 From 7dfab39855897418c05ccb6f4213c840f91d1c30 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Thu, 11 May 2023 19:40:35 +0300 Subject: efi_loader: Fix warnings for unaligned accesses Tom reports that when building with clang we see this warning: field guid within 'struct efi_hii_keyboard_layout' is less aligned than 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being packed, which can lead to unaligned accesses [-Wunaligned-access] This happens because 'struct efi_hii_keyboard_layout' is defined as packed and thus has 1-byte alignment but efi_guid_t is a type that requires greater alignment than that. However the EFI spec describes the EFI_GUID as "128-bit buffer containing a unique identifier value. Unless otherwise specified" So convert the efi_guid_t -> u8 b[16] here and skip the alignment requirements. Since the struct is packed to begin with, it makes no difference on the final memory layout. Suggested-by: Heinrich Schuchardt Reported-by: Tom Rini Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- include/efi_api.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/include/efi_api.h b/include/efi_api.h index 2fd0221c1c..55a4c989fc 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -1170,7 +1170,33 @@ struct efi_key_descriptor { struct efi_hii_keyboard_layout { u16 layout_length; - efi_guid_t guid; + /* + * The EFI spec defines this as efi_guid_t. + * clang and gcc both report alignment problems here. + * clang with -Wunaligned-access + * warning: field guid within 'struct efi_hii_keyboard_layout' is less + * aligned than 'efi_guid_t' and is usually due to + * 'struct efi_hii_keyboard_layout' being packed, which can lead to + * unaligned accesses + * + * GCC with -Wpacked-not-aligned -Waddress-of-packed-member + * 'efi_guid_t' offset 2 in 'struct efi_hii_keyboard_layout' + * isn't aligned to 4 + * + * Removing the alignment from efi_guid_t is not an option, since + * it is also used in non-packed structs and that would break + * calculations with offsetof + * + * This is the only place we get a report for. That happens because + * all other declarations of efi_guid_t within a packed struct happens + * to be 4-byte aligned. i.e a u32, a u64 a 2 * u16 or any combination + * that ends up landing efi_guid_t on a 4byte boundary precedes. + * + * Replace this with a 1-byte aligned counterpart of b[16]. This is a + * packed struct so the memory placement of efi_guid_t should not change + * + */ + u8 guid[16]; u32 layout_descriptor_string_offset; u8 descriptor_count; /* struct efi_key_descriptor descriptors[]; follows here */ -- cgit v1.2.1 From 31eda3f55ce788e1c885f38c3afad6f4db60f13e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 12 May 2023 21:23:15 +0200 Subject: efi_loader: print file path w/o boot device Helloworld.efi should print the file path even if the boot device is not set. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/helloworld.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/efi_loader/helloworld.c b/lib/efi_loader/helloworld.c index 6405f58ec3..bd72822c0b 100644 --- a/lib/efi_loader/helloworld.c +++ b/lib/efi_loader/helloworld.c @@ -216,6 +216,10 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle, (con_out, u"Cannot open device path to text protocol\r\n"); goto out; } + con_out->output_string(con_out, u"File path: "); + ret = print_device_path(loaded_image->file_path, device_path_to_text); + if (ret != EFI_SUCCESS) + goto out; if (!loaded_image->device_handle) { con_out->output_string (con_out, u"Missing device handle\r\n"); @@ -234,10 +238,6 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle, ret = print_device_path(device_path, device_path_to_text); if (ret != EFI_SUCCESS) goto out; - con_out->output_string(con_out, u"File path: "); - ret = print_device_path(loaded_image->file_path, device_path_to_text); - if (ret != EFI_SUCCESS) - goto out; out: boottime->exit(handle, ret, 0, NULL); -- cgit v1.2.1 From 01c528118d1fd9bdfaad57ca803094d1b697401d Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 12 May 2023 20:18:10 +0200 Subject: efi_loader: support booting semihosting file Executing an EFI binary fails for files loaded via semihosting. Construct a dummy device path for EFI binaries loaded via semihosting. A future complete solution may include the creation of a handle with a simple file system protocol. Reported-by: Andre Przywara Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_device_path.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index e2e98a39be..20ad948498 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -1203,7 +1203,8 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, } else if (!strcmp(dev, "Uart")) { if (device) *device = efi_dp_from_uart(); - } else if (!strcmp(dev, "Mem")) { + } else if (!strcmp(dev, "Mem") || !strcmp(dev, "hostfs")) { + /* loadm command and semihosting */ efi_get_image_parameters(&image_addr, &image_size); if (device) -- cgit v1.2.1 From d76184edc31292bd68ef1b63e7dfc3f11cd8bada Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 13 May 2023 09:55:26 +0200 Subject: efi_loader: avoid #ifdef in efi_dp_from_name() According to our coding style guide #ifdef should be avoided. Use IS_ENABLED() instead. Sort string comparisons alphabetically. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_device_path.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 20ad948498..a6a6ef0d6c 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -1079,8 +1079,7 @@ struct efi_device_path *efi_dp_from_uart(void) return buf; } -#ifdef CONFIG_NETDEVICES -struct efi_device_path *efi_dp_from_eth(void) +struct efi_device_path __maybe_unused *efi_dp_from_eth(void) { void *buf, *start; unsigned dpsize = 0; @@ -1099,7 +1098,6 @@ struct efi_device_path *efi_dp_from_eth(void) return start; } -#endif /* Construct a device-path for memory-mapped image */ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, @@ -1195,15 +1193,7 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, if (path && !file) return EFI_INVALID_PARAMETER; - if (!strcmp(dev, "Net")) { -#ifdef CONFIG_NETDEVICES - if (device) - *device = efi_dp_from_eth(); -#endif - } else if (!strcmp(dev, "Uart")) { - if (device) - *device = efi_dp_from_uart(); - } else if (!strcmp(dev, "Mem") || !strcmp(dev, "hostfs")) { + if (!strcmp(dev, "Mem") || !strcmp(dev, "hostfs")) { /* loadm command and semihosting */ efi_get_image_parameters(&image_addr, &image_size); @@ -1211,6 +1201,12 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, *device = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, (uintptr_t)image_addr, image_size); + } else if (IS_ENABLED(CONFIG_NETDEVICES) && !strcmp(dev, "Net")) { + if (device) + *device = efi_dp_from_eth(); + } else if (!strcmp(dev, "Uart")) { + if (device) + *device = efi_dp_from_uart(); } else { part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition, 1); -- cgit v1.2.1 From bd646fc3deeb0c274a7fa61e3727916aadd23dc7 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 13 May 2023 10:00:55 +0200 Subject: efi_loader: duplicate code in efi_dp_from_name efi_dp_from_name() has duplicate code to replace slash by backslash. path_to_uefi() called by efi_dp_from_file() already does this. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_device_path.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index a6a6ef0d6c..c4f0cc23a0 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -1187,8 +1187,6 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, size_t image_size; void *image_addr; int part = 0; - char *filename; - char *s; if (path && !file) return EFI_INVALID_PARAMETER; @@ -1220,17 +1218,7 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, if (!path) return EFI_SUCCESS; - filename = calloc(1, strlen(path) + 1); - if (!filename) - return EFI_OUT_OF_RESOURCES; - - sprintf(filename, "%s", path); - /* DOS style file path: */ - s = filename; - while ((s = strchr(s, '/'))) - *s++ = '\\'; - *file = efi_dp_from_file(desc, part, filename); - free(filename); + *file = efi_dp_from_file(desc, part, path); if (!*file) return EFI_INVALID_PARAMETER; -- cgit v1.2.1 From 57806128916e0fcb19d512d12f1f5e65442a1919 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 13 May 2023 10:18:24 +0200 Subject: efi_loader: clean up efi_dp_from_file * Improve variable name usage: Use pos instead of buf to indicate the current position in a buffer. * Avoid double assignment in a single code line. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_device_path.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index c4f0cc23a0..0f58082141 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -1022,7 +1022,7 @@ struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part, const char *path) { struct efi_device_path_file_path *fp; - void *buf, *start; + void *buf, *pos; size_t dpsize = 0, fpsize; if (desc) @@ -1035,26 +1035,28 @@ struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part, dpsize += fpsize; - start = buf = efi_alloc(dpsize + sizeof(END)); + buf = efi_alloc(dpsize + sizeof(END)); if (!buf) return NULL; if (desc) - buf = dp_part_fill(buf, desc, part); + pos = dp_part_fill(buf, desc, part); + else + pos = buf; /* add file-path: */ if (*path) { - fp = buf; + fp = pos; fp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE; fp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH; fp->dp.length = (u16)fpsize; path_to_uefi(fp->str, path); - buf += fpsize; + pos += fpsize; } - *((struct efi_device_path *)buf) = END; + memcpy(pos, &END, sizeof(END)); - return start; + return buf; } struct efi_device_path *efi_dp_from_uart(void) -- cgit v1.2.1 From 9f7ed4b469b5f9b77ea9c0745697b2269f375917 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 13 May 2023 10:22:21 +0200 Subject: efi_loader: error code efi_dp_from_name() Use EFI_OUT_OF_RESOURCES if the device path cannot be constructed. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_device_path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 0f58082141..1436244f99 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -1223,7 +1223,7 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, *file = efi_dp_from_file(desc, part, path); if (!*file) - return EFI_INVALID_PARAMETER; + return EFI_OUT_OF_RESOURCES; return EFI_SUCCESS; } -- cgit v1.2.1 From e1273ea2ec0edfa5502b66b0b142efddd2ef8283 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 13 May 2023 10:30:43 +0200 Subject: efi_loader: simplify efi_dp_from_name() Don't do the same check and assignment in multiple places. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_device_path.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 1436244f99..a9b0ea4015 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -1185,6 +1185,7 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, struct efi_device_path **file) { struct blk_desc *desc = NULL; + struct efi_device_path *dp; struct disk_partition fs_partition; size_t image_size; void *image_addr; @@ -1197,25 +1198,22 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, /* loadm command and semihosting */ efi_get_image_parameters(&image_addr, &image_size); - if (device) - *device = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, - (uintptr_t)image_addr, - image_size); + dp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + (uintptr_t)image_addr, image_size); } else if (IS_ENABLED(CONFIG_NETDEVICES) && !strcmp(dev, "Net")) { - if (device) - *device = efi_dp_from_eth(); + dp = efi_dp_from_eth(); } else if (!strcmp(dev, "Uart")) { - if (device) - *device = efi_dp_from_uart(); + dp = efi_dp_from_uart(); } else { part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition, 1); if (part < 0 || !desc) return EFI_INVALID_PARAMETER; - if (device) - *device = efi_dp_from_part(desc, part); + dp = efi_dp_from_part(desc, part); } + if (device) + *device = dp; if (!path) return EFI_SUCCESS; -- cgit v1.2.1 From c7c0ca37673d8f1ae1c54dad1869101f566923f7 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 13 May 2023 10:36:21 +0200 Subject: efi_loader: fix efi_dp_from_file() * 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 --- cmd/bootefi.c | 2 +- include/efi_loader.h | 2 +- lib/efi_loader/efi_bootmgr.c | 13 +++++-------- lib/efi_loader/efi_device_path.c | 39 +++++++++++---------------------------- 4 files changed, 18 insertions(+), 38 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 8aa15a64c8..5c0afec154 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -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; diff --git a/include/efi_loader.h b/include/efi_loader.h index b395eef9e7..38d7f66bab 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -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, diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 4b24b41047..7ac5f89f76 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -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); } diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index a9b0ea4015..71923b1127 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -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; -- cgit v1.2.1