From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH 3/6 v2] efi_loader: Introduce helper functions for EFI
Date: Sun, 14 Mar 2021 10:07:24 +0200 [thread overview]
Message-ID: <YE3EPHnelGo7Yt4b@enceladus> (raw)
In-Reply-To: <26574cf6-78e1-d05a-86d2-3d6443dd567c@gmx.de>
On Sun, Mar 14, 2021 at 09:01:48AM +0100, Heinrich Schuchardt wrote:
> On 3/14/21 8:34 AM, Ilias Apalodimas wrote:
> > 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.
>
> Unfortunately we cannot call the efi_get_file_size() function in
> lib/efi_loader/efi_file.c directly because a driver might have installed
> a different implementation of a simple file protocol.
>
> We should have different names for the functions, e.g. efi_file_size()
> and efi_get_file_size().
>
> But still I think lib/efi_loader/efi_file.c would be a better place for
> the new function. We will be able to reuse it in:
>
> * efi_capsule_read_file()
> * efi_load_image_from_file()
Sure, I'll rename this to efi_file_size() and move it in lib/efi_loader/efi_file.c
>
> Best regards
>
> Heinrich
>
> >
> > >
> > > 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;
> > > > +}
> > > >
> > >
>
next prev parent reply other threads:[~2021-03-14 8:07 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-13 21:47 [PATCH 0/6 v2] Loadfile2 for initrd loading Ilias Apalodimas
2021-03-13 21:47 ` [PATCH 1/6 v2] efi_selftest: Remove loadfile2 for initrd selftests Ilias Apalodimas
2021-03-13 21:47 ` [PATCH 2/6] efi_loader: Add device path related functions for initrd via Boot#### Ilias Apalodimas
2021-03-14 7:19 ` Heinrich Schuchardt
2021-03-14 7:32 ` Ilias Apalodimas
2021-03-13 21:47 ` [PATCH 3/6 v2] efi_loader: Introduce helper functions for EFI Ilias Apalodimas
2021-03-14 7:31 ` Heinrich Schuchardt
2021-03-14 7:34 ` Ilias Apalodimas
2021-03-14 8:01 ` Heinrich Schuchardt
2021-03-14 8:07 ` Ilias Apalodimas [this message]
2021-03-14 8:49 ` Heinrich Schuchardt
2021-03-14 9:24 ` Heinrich Schuchardt
2021-03-13 21:47 ` [PATCH 4/6 v2] efi_loader: Replace config option for initrd loading Ilias Apalodimas
2021-03-14 9:54 ` Heinrich Schuchardt
2021-03-14 10:08 ` Heinrich Schuchardt
2021-03-14 10:19 ` Heinrich Schuchardt
2021-03-13 21:47 ` [PATCH 5/6 v2] efidebug: add multiple device path instances on Boot#### Ilias Apalodimas
2021-03-14 9:27 ` Heinrich Schuchardt
2021-03-14 9:42 ` Heinrich Schuchardt
2021-03-14 9:44 ` Ilias Apalodimas
2021-03-14 10:14 ` Heinrich Schuchardt
2021-03-13 21:47 ` [PATCH 6/6 v2] doc: Update uefi documentation for initrd loading options Ilias Apalodimas
2021-03-14 7:53 ` Heinrich Schuchardt
2021-03-14 9:02 ` Ilias Apalodimas
2021-03-14 8:41 ` [PATCH 0/6 v2] Loadfile2 for initrd loading Heinrich Schuchardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YE3EPHnelGo7Yt4b@enceladus \
--to=ilias.apalodimas@linaro.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox