From 178667b34bf0aa5312727eba6612b3500adad4a3 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 11 Jun 2022 05:22:07 +0000 Subject: efi_loader: allow booting from short dev only DP Allow booting from a short form device-path without file path, e.g. /HD(1,GPT,5ef79931-a1aa-4c70-9d67-611e8f69eafd,0x800,0x1000) Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_bootmgr.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/efi_loader/efi_bootmgr.c') diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 93f6590530..9b65f34035 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -44,7 +44,7 @@ static const struct efi_runtime_services *rs; static struct efi_device_path *expand_media_path(struct efi_device_path *device_path) { - struct efi_device_path *dp, *full_path; + struct efi_device_path *dp, *rem, *full_path; efi_handle_t handle; efi_status_t ret; @@ -57,11 +57,10 @@ struct efi_device_path *expand_media_path(struct efi_device_path *device_path) * booting from removable media. */ dp = device_path; - ret = EFI_CALL(efi_locate_device_path( - &efi_simple_file_system_protocol_guid, - &dp, &handle)); + handle = efi_dp_find_obj(dp, &efi_simple_file_system_protocol_guid, + &rem); if (ret == EFI_SUCCESS) { - if (dp->type == DEVICE_PATH_TYPE_END) { + 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); -- cgit v1.2.3 From 72fa9cd59edcf99cb32c05604d2a904018acd30a Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 11 Jun 2022 05:22:08 +0000 Subject: efi_loader: create boot options without file path Allow the efidebug command to create boot options without file path, e.g. efidebug boot add -b 0001 'short dev only' host 0:1 '' efidebug boot add -B 0002 'long dev only' host 0:1 '' Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_bootmgr.c | 3 +-- lib/efi_loader/efi_device_path.c | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'lib/efi_loader/efi_bootmgr.c') diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 9b65f34035..234073ecb7 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -46,7 +46,6 @@ struct efi_device_path *expand_media_path(struct efi_device_path *device_path) { struct efi_device_path *dp, *rem, *full_path; efi_handle_t handle; - efi_status_t ret; if (!device_path) return NULL; @@ -59,7 +58,7 @@ struct efi_device_path *expand_media_path(struct efi_device_path *device_path) dp = device_path; handle = efi_dp_find_obj(dp, &efi_simple_file_system_protocol_guid, &rem); - if (ret == EFI_SUCCESS) { + if (handle) { if (rem->type == DEVICE_PATH_TYPE_END) { dp = efi_dp_from_file(NULL, 0, "/EFI/BOOT/" BOOTEFI_NAME); diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 50a988c561..171661b897 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -973,9 +973,22 @@ static void path_to_uefi(void *uefi, const char *src) *pos = 0; } -/* - * If desc is NULL, this creates a path with only the file component, - * otherwise it creates a full path with both device and file components +/** + * efi_dp_from_file() - create device path for file + * + * 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 "" + * 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) @@ -1002,12 +1015,14 @@ struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part, buf = dp_part_fill(buf, desc, part); /* add file-path: */ - fp = buf; - 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; + if (*path) { + fp = buf; + 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; + } *((struct efi_device_path *)buf) = END; -- cgit v1.2.3