From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heinrich Schuchardt Date: Sun, 14 Mar 2021 10:27:12 +0100 Subject: [PATCH 5/6 v2] efidebug: add multiple device path instances on Boot#### In-Reply-To: <20210313214738.3257922-6-ilias.apalodimas@linaro.org> References: <20210313214738.3257922-1-ilias.apalodimas@linaro.org> <20210313214738.3257922-6-ilias.apalodimas@linaro.org> Message-ID: <379384cb-810b-e16f-6c74-30dba5a6d32f@gmx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 3/13/21 10:47 PM, Ilias Apalodimas wrote: > The UEFI spec allow a packed array of UEFI device paths in the %s/allow/allows/ > FilePathList[] of an EFI_LOAD_OPTION. The first file path must > describe the loaded image but the rest are OS specific. > > Previous patches parse the device path and try to use the second > member of the array as an initrd. So let's modify efidebug slightly > and install the second file described in the command line as the > initrd device path. > > Signed-off-by: Ilias Apalodimas > --- > cmd/efidebug.c | 194 ++++++++++++++---- > doc/board/emulation/qemu_capsule_update.rst | 4 +- > doc/uefi/uefi.rst | 2 +- > .../test_efi_capsule/test_capsule_firmware.py | 6 +- > test/py/tests/test_efi_secboot/test_signed.py | 16 +- > .../test_efi_secboot/test_signed_intca.py | 8 +- > .../tests/test_efi_secboot/test_unsigned.py | 8 +- > 7 files changed, 180 insertions(+), 58 deletions(-) > > diff --git a/cmd/efidebug.c b/cmd/efidebug.c > index bbbcb0a54643..223cffa389fb 100644 > --- a/cmd/efidebug.c > +++ b/cmd/efidebug.c > @@ -9,6 +9,8 @@ > #include > #include > #include > +#include > +#include > #include > #include > #include > @@ -19,6 +21,7 @@ > #include > #include > #include > +#include > > #define BS systab.boottime > #define RT systab.runtime > @@ -794,6 +797,66 @@ static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag, > return CMD_RET_SUCCESS; > } > > +/** > + * add_initrd_instance() - Append a device path to load_options pointing to an > + * inirtd > + * > + * @dev: Device > + * @part: Partition of thge disk > + * @file: Filename > + * @fp: Device Path containing the existing load_options > + * @fp_size: New size of the device path after the addition > + * Return: Pointer to the device path or ERR_PTR NULL is good enough to signal a problem and saves a few bytes of code. > + * > + */ > +static > +struct efi_device_path *add_initrd_instance(const char *dev, const char *part, > + const char *file, > + const struct efi_device_path *fp, > + efi_uintn_t *fp_size) > +{ > + struct efi_device_path *tmp_dp = NULL, *tmp_fp = NULL; > + struct efi_device_path *final_fp = NULL, *initrd_dp = NULL; > + efi_status_t ret; > + const struct efi_initrd_dp id_dp = { > + .vendor = { > + { > + DEVICE_PATH_TYPE_MEDIA_DEVICE, > + DEVICE_PATH_SUB_TYPE_VENDOR_PATH, > + sizeof(id_dp.vendor), > + }, > + EFI_INITRD_MEDIA_GUID, > + }, > + .end = { > + DEVICE_PATH_TYPE_END, > + DEVICE_PATH_SUB_TYPE_END, > + sizeof(id_dp.end), > + } > + }; > + > + ret = efi_dp_from_name(dev, part, file, &tmp_dp, &tmp_fp); > + if (ret != EFI_SUCCESS) { > + printf("Cannot create device path for \"%s %s\"\n", part, file); > + goto out; > + } > + > + initrd_dp = efi_dp_append((const struct efi_device_path *)&id_dp, > + tmp_fp); > + if (!initrd_dp) { > + printf("Cannot append media vendor device path path\n"); "Cannot add initrd\n" is less confusing for an end user. But I guess that message should be moved to caller because efi_dp_concat() might fail too (due to out of memory). > + goto out; > + } > + final_fp = efi_dp_concat(fp, initrd_dp); > + *fp_size = efi_dp_size(fp) + efi_dp_size(initrd_dp) + > + (2 * sizeof(struct efi_device_path)); > + > +out: > + efi_free_pool(initrd_dp); > + efi_free_pool(tmp_dp); > + efi_free_pool(tmp_fp); > + return final_fp ? final_fp : ERR_PTR(-EINVAL); Just return final_fp. NULL signals an error. > +} > + > /** > * do_efi_boot_add() - set UEFI load option > * > @@ -806,7 +869,9 @@ static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag, > * > * Implement efidebug "boot add" sub-command. Create or change UEFI load option. > * > - * efidebug boot add