[PATCH 3/6 v2] efi_loader: Introduce helper functions for EFI
Ilias Apalodimas
ilias.apalodimas at linaro.org
Sun Mar 14 08:34:48 CET 2021
Hi Heinrich,
On Sun, Mar 14, 2021 at 08:31:20AM +0100, Heinrich Schuchardt wrote:
> On 3/13/21 10:47 PM, Ilias Apalodimas wrote:
> > A following patch introduces a different logic for loading initrd's
> > based on the EFI_LOAD_FILE2_PROTOCOL.
> > +/**
> > + * efi_get_file_size() - Get the size of a file using an EFI file handle
> > + *
> > + * @handle: EFI file handle
> > + * @size: buffer to fill in the discovered size
> > + *
> > + * Return: device path or NULL. Caller must free the returned value
> > + */
> > +efi_status_t efi_get_file_size(struct efi_file_handle *fh, efi_uintn_t *size)
>
> Should this function be in lib/efi_loader/efi_file?
there's already a statically defined efi_get_file_size() in that file. I can
rename that, just let me know what you prefer.
>
> Best regards
>
> Heinrich
>
> > +{
> > + struct efi_file_info *info = NULL;
> > + efi_uintn_t bs = 0;
> > + efi_status_t ret;
> > +
> > + *size = 0;
> > + ret = EFI_CALL(fh->getinfo(fh, (efi_guid_t *)&efi_file_info_guid, &bs,
> > + info));
> > + if (ret != EFI_BUFFER_TOO_SMALL) {
> > + ret = EFI_DEVICE_ERROR;
> > + goto out;
> > + }
> > +
> > + info = malloc(bs);
> > + if (!info) {
> > + ret = EFI_OUT_OF_RESOURCES;
> > + goto out;
> > + }
> > + ret = EFI_CALL(fh->getinfo(fh, (efi_guid_t *)&efi_file_info_guid, &bs,
> > + info));
> > + if (ret != EFI_SUCCESS)
> > + goto out;
> > +
> > + *size = info->file_size;
> > +
> > +out:
> > + free(info);
> > + return ret;
> > +}
> > diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c
> > index 1c7459266a38..b11ed91a74a4 100644
> > --- a/lib/efi_loader/efi_var_common.c
> > +++ b/lib/efi_loader/efi_var_common.c
> > @@ -9,6 +9,7 @@
> > #include <common.h>
> > #include <efi_loader.h>
> > #include <efi_variable.h>
> > +#include <stdlib.h>
> >
> > enum efi_secure_mode {
> > EFI_MODE_SETUP,
> > @@ -343,3 +344,35 @@ enum efi_auth_var_type efi_auth_var_get_type(u16 *name, const efi_guid_t *guid)
> > }
> > return EFI_AUTH_VAR_NONE;
> > }
> > +
> > +/**
> > + * efi_get_var() - read value of an EFI variable
> > + *
> > + * @name: variable name
> > + * @start: vendor GUID
> > + * @size: size of allocated buffer
> > + *
> > + * Return: buffer with variable data or NULL
> > + */
> > +void *efi_get_var(u16 *name, const efi_guid_t *vendor, efi_uintn_t *size)
> > +{
> > + efi_status_t ret;
> > + void *buf = NULL;
> > +
> > + *size = 0;
> > + ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL);
> > + if (ret == EFI_BUFFER_TOO_SMALL) {
> > + buf = malloc(*size);
> > + if (!buf)
> > + return NULL;
> > + ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL);
> > + }
> > +
> > + if (ret != EFI_SUCCESS) {
> > + free(buf);
> > + *size = 0;
> > + return NULL;
> > + }
> > +
> > + return buf;
> > +}
> >
>
More information about the U-Boot
mailing list