From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Cc: Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
Shantur Rathore <i@shantur.com>, Bin Meng <bmeng@tinylab.org>,
AKASHI Takahiro <akashi.tkhro@gmail.com>,
Masahisa Kojima <kojima.masahisa@socionext.com>,
Raymond Mao <raymond.mao@linaro.org>,
Mark Kettenis <kettenis@openbsd.org>,
Joao Marcos Costa <jmcosta944@gmail.com>,
u-boot@lists.denx.de
Subject: Re: [RFC 02/14] efi_loader: library function efi_dp_merge
Date: Wed, 22 May 2024 08:57:03 +0300 [thread overview]
Message-ID: <Zk2JL2bqBLbe6tSk@hera> (raw)
In-Reply-To: <a17e0a7e-8269-4d1d-aaaa-a944655b90f4@canonical.com>
On Tue, May 14, 2024 at 02:49:47PM +0200, Heinrich Schuchardt wrote:
> On 4/26/24 17:47, Ilias Apalodimas wrote:
> > Hi Heinrich
> >
> > On Fri, 26 Apr 2024 at 17:53, Heinrich Schuchardt
> > <heinrich.schuchardt@canonical.com> wrote:
> > >
> > > On 26.04.24 16:30, Ilias Apalodimas wrote:
> > > > Hi Heinrich,
> > > >
> > > > On Fri, 26 Apr 2024 at 17:13, Heinrich Schuchardt
> > > > <heinrich.schuchardt@canonical.com> wrote:
> > > > >
> > > > > Provide a function to append a device_path to a list of device paths
> > > > > that is separated by final end nodes.
> > > > >
> > > > > Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> > > > > ---
> > > > > include/efi_loader.h | 3 +++
> > > > > lib/efi_loader/efi_device_path.c | 31 +++++++++++++++++++++++++++++++
> > > > > 2 files changed, 34 insertions(+)
> > > > >
> > > > > diff --git a/include/efi_loader.h b/include/efi_loader.h
> > > > > index 9600941aa32..a7d7b8324f1 100644
> > > > > --- a/include/efi_loader.h
> > > > > +++ b/include/efi_loader.h
> > > > > @@ -944,6 +944,9 @@ struct efi_load_option {
> > > > >
> > > > > struct efi_device_path *efi_dp_from_lo(struct efi_load_option *lo,
> > > > > const efi_guid_t *guid);
> > > > > +struct efi_device_path *efi_dp_merge(const struct efi_device_path *dp1,
> > > > > + efi_uintn_t *size,
> > > > > + const struct efi_device_path *dp2);
> > > > > struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
> > > > > const struct efi_device_path *dp2,
> > > > > bool split_end_node);
> > > > > diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
> > > > > index 46aa59b9e40..16cbe41d32f 100644
> > > > > --- a/lib/efi_loader/efi_device_path.c
> > > > > +++ b/lib/efi_loader/efi_device_path.c
> > > > > @@ -270,6 +270,37 @@ struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp)
> > > > > return ndp;
> > > > > }
> > > > >
> > > > > +/**
> > > > > + * efi_dp_merge() - Concatenate two device paths separated by final end node
> > > > > + *
> > > > > + * @dp1: first device path
> > > > > + * @size: pointer to length of @dp1, total size on return
> > > > > + * @dp2: second device path
> > > > > + *
> > > > > + * Return: concatenated device path or NULL
> > > > > + */
> > > > > +struct efi_device_path *efi_dp_merge(const struct efi_device_path *dp1,
> > > > > + efi_uintn_t *size,
> > > > > + const struct efi_device_path *dp2)
> > > > > +{
> > > > > + efi_uintn_t len, len1, len2;
> > > > > + struct efi_device_path *dp;
> > > > > + u8 *p;
> > > > > +
> > > > > + len1 = *size;
> > > > > + len2 = efi_dp_size(dp2) + sizeof(END);
> > > > > + len = len1 + len2;
> > > > > + dp = efi_alloc(len);
> > > > > + if (!dp)
> > > > > + return NULL;
> > > > > + memcpy(dp, dp1, len1);
> > > > > + p = (u8 *)dp + len1;
> > > > > + memcpy(p, dp2, len2);
> > > > > + *size = len;
> > > >
> > > > Can't we just use efi_dp_concat()?
> > >
> > > efi_dp_concat cannot be used to put a device-path end-node in between
> > > two device-paths that are concatenated. We need that separator in the
> > > load options.
> >
> > I am not sure I am following you. It's been a few years so please bear
> > with me until I manage to re-read that code and page it back to
> > memory.
> >
> > What I remember though is that the format of the DP looks like this:
> >
> > Loaded image DP - end node - initrd GUID DP (without and end node) -
> > initrd - end of device path.
> > So to jump from the special initrd GUID to the actual DP that contains
> > the initrd you need to do an efi_dp_next(). Also, efi_dp_concat() will
> > inject an end node with a DEVICE_PATH_SUB_TYPE_END type if the third
> > argument is 'true'.
> >
> > What am I missing?
>
> Let us assume
>
> dp1 = /vmlinux/endnode/initrd/endnode
> dp2 = /dtb/endnode
>
> and we invoke dp_concat(dp1, dp2, true):
>
> sz1 is calculated via the efi_dp_size() function which looks for the *first*
> device-path end node.
>
> sz1 = efi_dp_size(dp1) = sizeof(/vmlinux)
>
> sz1 will not include initrd and its endnode.
>
> So dp_concat(/vmlinux/endnode/initrd/endnode, /dtb/endnode, true)
> will return:
>
> /vmlinux/endnode/dtb/endnode
>
> but in our boot option we want
>
> /vmlinux/endnode/initrd/endnode/dtb/endnode
Correct,
> I introduced an new function efi_dp_merge().
> Instead we could change the arguments to:
>
>
> * @sz1:
> * * 0 to concatenate
> * * 1 to concatenate with end node added as separator
> * * size of dp1 excluding last end node to concatenate with end node as
> * separator in case dp1 contains an end node
> struct
> efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
> const struct efi_device_path *dp2,
> size_t sz1)
>
> and replace
>
> sz1 = efi_dp_size(dp1);
>
> by
>
> if (sz1 < sizeof(struct efi_device_path)
> sz1 = efi_dp_size(dp1);
>
> Best regards
Yes please, I like this more. we already have enough efi_dp_xxx
Thanks
/Ilias
>
> Heinrich
>
> >
> > Thanks
> > /Ilias
> >
> > >
> > > Best regards
> > >
> > > Heinrich
> > >
> > > >
> > > > Thanks
> > > > /Ilias
> > > > > +
> > > > > + return dp;
> > > > > +}
> > > > > +
> > > > > /**
> > > > > * efi_dp_concat() - Concatenate two device paths and add and terminate them
> > > > > * with an end node.
> > > > > --
> > > > > 2.43.0
> > > > >
> > >
>
next prev parent reply other threads:[~2024-05-22 5:57 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-26 14:13 [RFC 00/14] efi_loader: improve device-tree loading Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 01/14] efi_loader: pass GUID by address to efi_dp_from_lo Heinrich Schuchardt
2024-04-26 23:50 ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 02/14] efi_loader: library function efi_dp_merge Heinrich Schuchardt
2024-04-26 14:30 ` Ilias Apalodimas
2024-04-26 14:52 ` Heinrich Schuchardt
2024-04-26 15:47 ` Ilias Apalodimas
2024-05-14 12:49 ` Heinrich Schuchardt
2024-05-14 12:58 ` Mark Kettenis
2024-05-14 13:08 ` Heinrich Schuchardt
2024-05-22 5:57 ` Ilias Apalodimas [this message]
2024-04-26 14:13 ` [RFC 03/14] efi_loader: simplify efi_dp_concat() Heinrich Schuchardt
2024-04-28 13:29 ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 04/14] cmd: eficonfig: add support for setting fdt Heinrich Schuchardt
2024-04-27 17:21 ` E Shattow
2024-04-27 21:25 ` Heinrich Schuchardt
2024-04-28 4:13 ` E Shattow
2024-04-26 14:13 ` [RFC 05/14] cmd: efidebug: " Heinrich Schuchardt
2024-05-22 6:16 ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 06/14] efi_loader: superfluous efi_restore_gd after EFI_CALL Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 07/14] cmd: terminate efidebug test bootmgr early on error Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 08/14] efi_loader: improve error handling in try_load_entry() Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 09/14] efi_loader: do not install dtb if bootmgr fails Heinrich Schuchardt
2024-05-22 6:17 ` Ilias Apalodimas
2024-05-22 6:27 ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 10/14] efi_loader: load device-tree specified in boot option Heinrich Schuchardt
2024-05-22 6:28 ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 11/14] efi_loader: move distro_efi_get_fdt_name() Heinrich Schuchardt
2024-04-26 14:52 ` Caleb Connolly
2024-04-26 15:18 ` Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 12/14] efi_loader: return binary from efi_dp_from_lo() Heinrich Schuchardt
2024-04-28 13:28 ` Ilias Apalodimas
2024-05-14 12:57 ` Heinrich Schuchardt
2024-04-26 14:13 ` [RFC 13/14] efi_loader: export efi_load_image_from_path Heinrich Schuchardt
2024-04-28 13:32 ` Ilias Apalodimas
2024-04-26 14:13 ` [RFC 14/14] efi_loader: load distro dtb in bootmgr 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=Zk2JL2bqBLbe6tSk@hera \
--to=ilias.apalodimas@linaro.org \
--cc=akashi.tkhro@gmail.com \
--cc=bmeng@tinylab.org \
--cc=heinrich.schuchardt@canonical.com \
--cc=i@shantur.com \
--cc=jmcosta944@gmail.com \
--cc=kettenis@openbsd.org \
--cc=kojima.masahisa@socionext.com \
--cc=raymond.mao@linaro.org \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--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