mbox series

[v3,0/9] efi_loader: improve device-tree loading

Message ID 20240610091057.64463-1-heinrich.schuchardt@canonical.com
Headers show
Series efi_loader: improve device-tree loading | expand

Message

Heinrich Schuchardt June 10, 2024, 9:10 a.m. UTC
In U-Boot EFI boot options can already specify both an EFI binary and
an initrd. With this series we can additionally define the matching
device-tree to be loaded in the boot option.

With the last patch the boot manager will fall back the device-tree
specified by $fdtfile in directories '/dtb/', '/', or '/dtb/current/'
on the boot device if no device-tree is specified in the boot
option or via a bootefi command parameter.

v3:
	Add missing '@' in EFI_LP_DP_PART_FDT description.
	Use calloc() instead of malloc() in load_fdt_from_load_option().
	Add missing '@' in load_fdt_from_load_option function description
	Rename struct efi_initrd_dp to efi_lo_dp_prefix.

v2:
	Update efi_dp_concat() instead of new function efi_dp_merge().
	Carve out a function efi_load_option_dp_join() which we can
	use both for the eficonfig and the efidebug command.
	Rename variables id_dp, final_dp_size.
	Rename create_initrd_dp() to create_lo_dp_part().
	Use enum as parameter for create_lo_dp_part().
	Put all related changes into one patch.

Heinrich Schuchardt (8):
  efi_loader: allow concatenation with contained end node
  cmd: eficonfig: add support for setting fdt
  cmd: efidebug: add support for setting fdt
  efi_loader: load device-tree specified in boot option
  efi_loader: move distro_efi_get_fdt_name()
  efi_loader: return binary from efi_dp_from_lo()
  efi_loader: export efi_load_image_from_path
  efi_loader: load distro dtb in bootmgr

 boot/bootmeth_efi.c                        |  60 +---------
 cmd/eficonfig.c                            |  83 +++++++++----
 cmd/efidebug.c                             | 130 +++++++++++++++------
 include/efi_loader.h                       |  24 +++-
 lib/efi_loader/Makefile                    |   1 +
 lib/efi_loader/efi_bootbin.c               |   2 +-
 lib/efi_loader/efi_bootmgr.c               |  75 +++++++++++-
 lib/efi_loader/efi_boottime.c              |   3 +-
 lib/efi_loader/efi_device_path.c           |  40 ++++---
 lib/efi_loader/efi_device_path_utilities.c |   2 +-
 lib/efi_loader/efi_fdt.c                   | 117 +++++++++++++++++++
 lib/efi_loader/efi_helper.c                |  44 +++++++
 12 files changed, 445 insertions(+), 136 deletions(-)
 create mode 100644 lib/efi_loader/efi_fdt.c

Comments

Simon Glass June 10, 2024, 1:53 p.m. UTC | #1
Hi Heinrich,

On Mon, 10 Jun 2024 at 03:11, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> In U-Boot EFI boot options can already specify both an EFI binary and
> an initrd. With this series we can additionally define the matching
> device-tree to be loaded in the boot option.
>
> With the last patch the boot manager will fall back the device-tree
> specified by $fdtfile in directories '/dtb/', '/', or '/dtb/current/'
> on the boot device if no device-tree is specified in the boot
> option or via a bootefi command parameter.
>
> v3:
>         Add missing '@' in EFI_LP_DP_PART_FDT description.
>         Use calloc() instead of malloc() in load_fdt_from_load_option().
>         Add missing '@' in load_fdt_from_load_option function description
>         Rename struct efi_initrd_dp to efi_lo_dp_prefix.
>
> v2:
>         Update efi_dp_concat() instead of new function efi_dp_merge().
>         Carve out a function efi_load_option_dp_join() which we can
>         use both for the eficonfig and the efidebug command.
>         Rename variables id_dp, final_dp_size.
>         Rename create_initrd_dp() to create_lo_dp_part().
>         Use enum as parameter for create_lo_dp_part().
>         Put all related changes into one patch.
>
> Heinrich Schuchardt (8):
>   efi_loader: allow concatenation with contained end node
>   cmd: eficonfig: add support for setting fdt
>   cmd: efidebug: add support for setting fdt
>   efi_loader: load device-tree specified in boot option
>   efi_loader: move distro_efi_get_fdt_name()
>   efi_loader: return binary from efi_dp_from_lo()
>   efi_loader: export efi_load_image_from_path
>   efi_loader: load distro dtb in bootmgr
>
>  boot/bootmeth_efi.c                        |  60 +---------
>  cmd/eficonfig.c                            |  83 +++++++++----
>  cmd/efidebug.c                             | 130 +++++++++++++++------
>  include/efi_loader.h                       |  24 +++-
>  lib/efi_loader/Makefile                    |   1 +
>  lib/efi_loader/efi_bootbin.c               |   2 +-
>  lib/efi_loader/efi_bootmgr.c               |  75 +++++++++++-
>  lib/efi_loader/efi_boottime.c              |   3 +-
>  lib/efi_loader/efi_device_path.c           |  40 ++++---
>  lib/efi_loader/efi_device_path_utilities.c |   2 +-
>  lib/efi_loader/efi_fdt.c                   | 117 +++++++++++++++++++
>  lib/efi_loader/efi_helper.c                |  44 +++++++
>  12 files changed, 445 insertions(+), 136 deletions(-)
>  create mode 100644 lib/efi_loader/efi_fdt.c
>

Somewhat related, what work has been done to support FIT, or to locate
a DT using the compatible string?

Regards,
Simon
Heinrich Schuchardt June 10, 2024, 2 p.m. UTC | #2
On 10.06.24 15:53, Simon Glass wrote:
> Hi Heinrich,
> 
> On Mon, 10 Jun 2024 at 03:11, Heinrich Schuchardt
> <heinrich.schuchardt@canonical.com> wrote:
>>
>> In U-Boot EFI boot options can already specify both an EFI binary and
>> an initrd. With this series we can additionally define the matching
>> device-tree to be loaded in the boot option.
>>
>> With the last patch the boot manager will fall back the device-tree
>> specified by $fdtfile in directories '/dtb/', '/', or '/dtb/current/'
>> on the boot device if no device-tree is specified in the boot
>> option or via a bootefi command parameter.
>>
>> v3:
>>          Add missing '@' in EFI_LP_DP_PART_FDT description.
>>          Use calloc() instead of malloc() in load_fdt_from_load_option().
>>          Add missing '@' in load_fdt_from_load_option function description
>>          Rename struct efi_initrd_dp to efi_lo_dp_prefix.
>>
>> v2:
>>          Update efi_dp_concat() instead of new function efi_dp_merge().
>>          Carve out a function efi_load_option_dp_join() which we can
>>          use both for the eficonfig and the efidebug command.
>>          Rename variables id_dp, final_dp_size.
>>          Rename create_initrd_dp() to create_lo_dp_part().
>>          Use enum as parameter for create_lo_dp_part().
>>          Put all related changes into one patch.
>>
>> Heinrich Schuchardt (8):
>>    efi_loader: allow concatenation with contained end node
>>    cmd: eficonfig: add support for setting fdt
>>    cmd: efidebug: add support for setting fdt
>>    efi_loader: load device-tree specified in boot option
>>    efi_loader: move distro_efi_get_fdt_name()
>>    efi_loader: return binary from efi_dp_from_lo()
>>    efi_loader: export efi_load_image_from_path
>>    efi_loader: load distro dtb in bootmgr
>>
>>   boot/bootmeth_efi.c                        |  60 +---------
>>   cmd/eficonfig.c                            |  83 +++++++++----
>>   cmd/efidebug.c                             | 130 +++++++++++++++------
>>   include/efi_loader.h                       |  24 +++-
>>   lib/efi_loader/Makefile                    |   1 +
>>   lib/efi_loader/efi_bootbin.c               |   2 +-
>>   lib/efi_loader/efi_bootmgr.c               |  75 +++++++++++-
>>   lib/efi_loader/efi_boottime.c              |   3 +-
>>   lib/efi_loader/efi_device_path.c           |  40 ++++---
>>   lib/efi_loader/efi_device_path_utilities.c |   2 +-
>>   lib/efi_loader/efi_fdt.c                   | 117 +++++++++++++++++++
>>   lib/efi_loader/efi_helper.c                |  44 +++++++
>>   12 files changed, 445 insertions(+), 136 deletions(-)
>>   create mode 100644 lib/efi_loader/efi_fdt.c
>>
> 
> Somewhat related, what work has been done to support FIT, or to locate
> a DT using the compatible string?

CONFIG_BOOTM_EFI allows booting a FIT image containing an EFI binary and 
optionally a device-tree. You can manually select a configuration when 
invoking the bootm command. I am not aware of any automation for this 
selection.

Best regards

Heinrich
Simon Glass June 10, 2024, 3:54 p.m. UTC | #3
Hi Heinrich,

On Mon, 10 Jun 2024 at 08:00, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> On 10.06.24 15:53, Simon Glass wrote:
> > Hi Heinrich,
> >
> > On Mon, 10 Jun 2024 at 03:11, Heinrich Schuchardt
> > <heinrich.schuchardt@canonical.com> wrote:
> >>
> >> In U-Boot EFI boot options can already specify both an EFI binary and
> >> an initrd. With this series we can additionally define the matching
> >> device-tree to be loaded in the boot option.
> >>
> >> With the last patch the boot manager will fall back the device-tree
> >> specified by $fdtfile in directories '/dtb/', '/', or '/dtb/current/'
> >> on the boot device if no device-tree is specified in the boot
> >> option or via a bootefi command parameter.
> >>
> >> v3:
> >>          Add missing '@' in EFI_LP_DP_PART_FDT description.
> >>          Use calloc() instead of malloc() in load_fdt_from_load_option().
> >>          Add missing '@' in load_fdt_from_load_option function description
> >>          Rename struct efi_initrd_dp to efi_lo_dp_prefix.
> >>
> >> v2:
> >>          Update efi_dp_concat() instead of new function efi_dp_merge().
> >>          Carve out a function efi_load_option_dp_join() which we can
> >>          use both for the eficonfig and the efidebug command.
> >>          Rename variables id_dp, final_dp_size.
> >>          Rename create_initrd_dp() to create_lo_dp_part().
> >>          Use enum as parameter for create_lo_dp_part().
> >>          Put all related changes into one patch.
> >>
> >> Heinrich Schuchardt (8):
> >>    efi_loader: allow concatenation with contained end node
> >>    cmd: eficonfig: add support for setting fdt
> >>    cmd: efidebug: add support for setting fdt
> >>    efi_loader: load device-tree specified in boot option
> >>    efi_loader: move distro_efi_get_fdt_name()
> >>    efi_loader: return binary from efi_dp_from_lo()
> >>    efi_loader: export efi_load_image_from_path
> >>    efi_loader: load distro dtb in bootmgr
> >>
> >>   boot/bootmeth_efi.c                        |  60 +---------
> >>   cmd/eficonfig.c                            |  83 +++++++++----
> >>   cmd/efidebug.c                             | 130 +++++++++++++++------
> >>   include/efi_loader.h                       |  24 +++-
> >>   lib/efi_loader/Makefile                    |   1 +
> >>   lib/efi_loader/efi_bootbin.c               |   2 +-
> >>   lib/efi_loader/efi_bootmgr.c               |  75 +++++++++++-
> >>   lib/efi_loader/efi_boottime.c              |   3 +-
> >>   lib/efi_loader/efi_device_path.c           |  40 ++++---
> >>   lib/efi_loader/efi_device_path_utilities.c |   2 +-
> >>   lib/efi_loader/efi_fdt.c                   | 117 +++++++++++++++++++
> >>   lib/efi_loader/efi_helper.c                |  44 +++++++
> >>   12 files changed, 445 insertions(+), 136 deletions(-)
> >>   create mode 100644 lib/efi_loader/efi_fdt.c
> >>
> >
> > Somewhat related, what work has been done to support FIT, or to locate
> > a DT using the compatible string?
>
> CONFIG_BOOTM_EFI allows booting a FIT image containing an EFI binary and
> optionally a device-tree. You can manually select a configuration when
> invoking the bootm command. I am not aware of any automation for this
> selection.

Thanks for the info.

Can we perhaps require FIT_BEST_MATCH and then provide a way? All this
filename stuff is missing the point, really. It isn't going to get any
easier, either.

Regards,
Simon
Heinrich Schuchardt June 10, 2024, 4:10 p.m. UTC | #4
On 10.06.24 17:54, Simon Glass wrote:
> Hi Heinrich,
> 
> On Mon, 10 Jun 2024 at 08:00, Heinrich Schuchardt
> <heinrich.schuchardt@canonical.com> wrote:
>>
>> On 10.06.24 15:53, Simon Glass wrote:
>>> Hi Heinrich,
>>>
>>> On Mon, 10 Jun 2024 at 03:11, Heinrich Schuchardt
>>> <heinrich.schuchardt@canonical.com> wrote:
>>>>
>>>> In U-Boot EFI boot options can already specify both an EFI binary and
>>>> an initrd. With this series we can additionally define the matching
>>>> device-tree to be loaded in the boot option.
>>>>
>>>> With the last patch the boot manager will fall back the device-tree
>>>> specified by $fdtfile in directories '/dtb/', '/', or '/dtb/current/'
>>>> on the boot device if no device-tree is specified in the boot
>>>> option or via a bootefi command parameter.
>>>>
>>>> v3:
>>>>           Add missing '@' in EFI_LP_DP_PART_FDT description.
>>>>           Use calloc() instead of malloc() in load_fdt_from_load_option().
>>>>           Add missing '@' in load_fdt_from_load_option function description
>>>>           Rename struct efi_initrd_dp to efi_lo_dp_prefix.
>>>>
>>>> v2:
>>>>           Update efi_dp_concat() instead of new function efi_dp_merge().
>>>>           Carve out a function efi_load_option_dp_join() which we can
>>>>           use both for the eficonfig and the efidebug command.
>>>>           Rename variables id_dp, final_dp_size.
>>>>           Rename create_initrd_dp() to create_lo_dp_part().
>>>>           Use enum as parameter for create_lo_dp_part().
>>>>           Put all related changes into one patch.
>>>>
>>>> Heinrich Schuchardt (8):
>>>>     efi_loader: allow concatenation with contained end node
>>>>     cmd: eficonfig: add support for setting fdt
>>>>     cmd: efidebug: add support for setting fdt
>>>>     efi_loader: load device-tree specified in boot option
>>>>     efi_loader: move distro_efi_get_fdt_name()
>>>>     efi_loader: return binary from efi_dp_from_lo()
>>>>     efi_loader: export efi_load_image_from_path
>>>>     efi_loader: load distro dtb in bootmgr
>>>>
>>>>    boot/bootmeth_efi.c                        |  60 +---------
>>>>    cmd/eficonfig.c                            |  83 +++++++++----
>>>>    cmd/efidebug.c                             | 130 +++++++++++++++------
>>>>    include/efi_loader.h                       |  24 +++-
>>>>    lib/efi_loader/Makefile                    |   1 +
>>>>    lib/efi_loader/efi_bootbin.c               |   2 +-
>>>>    lib/efi_loader/efi_bootmgr.c               |  75 +++++++++++-
>>>>    lib/efi_loader/efi_boottime.c              |   3 +-
>>>>    lib/efi_loader/efi_device_path.c           |  40 ++++---
>>>>    lib/efi_loader/efi_device_path_utilities.c |   2 +-
>>>>    lib/efi_loader/efi_fdt.c                   | 117 +++++++++++++++++++
>>>>    lib/efi_loader/efi_helper.c                |  44 +++++++
>>>>    12 files changed, 445 insertions(+), 136 deletions(-)
>>>>    create mode 100644 lib/efi_loader/efi_fdt.c
>>>>
>>>
>>> Somewhat related, what work has been done to support FIT, or to locate
>>> a DT using the compatible string?
>>
>> CONFIG_BOOTM_EFI allows booting a FIT image containing an EFI binary and
>> optionally a device-tree. You can manually select a configuration when
>> invoking the bootm command. I am not aware of any automation for this
>> selection.
> 
> Thanks for the info.
> 
> Can we perhaps require FIT_BEST_MATCH and then provide a way? All this
> filename stuff is missing the point, really. It isn't going to get any
> easier, either.
> 

Thanks for the pointer. FIT_BEST_MATCH would allow to select a matching 
device-tree from a FIT image. But any solution using FIT images will not 
not be compatible to other firmware.

As a distro I would prefer a solution that runs on any EFI firmware, 
e.g. EDK II. Being able to use the same image on all boards of the same 
architecture was the motivator for Suse to start U-Boot's EFI 
implementation.

Best regards

Heinrich
Tom Rini June 10, 2024, 4:41 p.m. UTC | #5
On Mon, Jun 10, 2024 at 06:10:08PM +0200, Heinrich Schuchardt wrote:
> On 10.06.24 17:54, Simon Glass wrote:
> > Hi Heinrich,
> > 
> > On Mon, 10 Jun 2024 at 08:00, Heinrich Schuchardt
> > <heinrich.schuchardt@canonical.com> wrote:
> > > 
> > > On 10.06.24 15:53, Simon Glass wrote:
> > > > Hi Heinrich,
> > > > 
> > > > On Mon, 10 Jun 2024 at 03:11, Heinrich Schuchardt
> > > > <heinrich.schuchardt@canonical.com> wrote:
> > > > > 
> > > > > In U-Boot EFI boot options can already specify both an EFI binary and
> > > > > an initrd. With this series we can additionally define the matching
> > > > > device-tree to be loaded in the boot option.
> > > > > 
> > > > > With the last patch the boot manager will fall back the device-tree
> > > > > specified by $fdtfile in directories '/dtb/', '/', or '/dtb/current/'
> > > > > on the boot device if no device-tree is specified in the boot
> > > > > option or via a bootefi command parameter.
> > > > > 
> > > > > v3:
> > > > >           Add missing '@' in EFI_LP_DP_PART_FDT description.
> > > > >           Use calloc() instead of malloc() in load_fdt_from_load_option().
> > > > >           Add missing '@' in load_fdt_from_load_option function description
> > > > >           Rename struct efi_initrd_dp to efi_lo_dp_prefix.
> > > > > 
> > > > > v2:
> > > > >           Update efi_dp_concat() instead of new function efi_dp_merge().
> > > > >           Carve out a function efi_load_option_dp_join() which we can
> > > > >           use both for the eficonfig and the efidebug command.
> > > > >           Rename variables id_dp, final_dp_size.
> > > > >           Rename create_initrd_dp() to create_lo_dp_part().
> > > > >           Use enum as parameter for create_lo_dp_part().
> > > > >           Put all related changes into one patch.
> > > > > 
> > > > > Heinrich Schuchardt (8):
> > > > >     efi_loader: allow concatenation with contained end node
> > > > >     cmd: eficonfig: add support for setting fdt
> > > > >     cmd: efidebug: add support for setting fdt
> > > > >     efi_loader: load device-tree specified in boot option
> > > > >     efi_loader: move distro_efi_get_fdt_name()
> > > > >     efi_loader: return binary from efi_dp_from_lo()
> > > > >     efi_loader: export efi_load_image_from_path
> > > > >     efi_loader: load distro dtb in bootmgr
> > > > > 
> > > > >    boot/bootmeth_efi.c                        |  60 +---------
> > > > >    cmd/eficonfig.c                            |  83 +++++++++----
> > > > >    cmd/efidebug.c                             | 130 +++++++++++++++------
> > > > >    include/efi_loader.h                       |  24 +++-
> > > > >    lib/efi_loader/Makefile                    |   1 +
> > > > >    lib/efi_loader/efi_bootbin.c               |   2 +-
> > > > >    lib/efi_loader/efi_bootmgr.c               |  75 +++++++++++-
> > > > >    lib/efi_loader/efi_boottime.c              |   3 +-
> > > > >    lib/efi_loader/efi_device_path.c           |  40 ++++---
> > > > >    lib/efi_loader/efi_device_path_utilities.c |   2 +-
> > > > >    lib/efi_loader/efi_fdt.c                   | 117 +++++++++++++++++++
> > > > >    lib/efi_loader/efi_helper.c                |  44 +++++++
> > > > >    12 files changed, 445 insertions(+), 136 deletions(-)
> > > > >    create mode 100644 lib/efi_loader/efi_fdt.c
> > > > > 
> > > > 
> > > > Somewhat related, what work has been done to support FIT, or to locate
> > > > a DT using the compatible string?
> > > 
> > > CONFIG_BOOTM_EFI allows booting a FIT image containing an EFI binary and
> > > optionally a device-tree. You can manually select a configuration when
> > > invoking the bootm command. I am not aware of any automation for this
> > > selection.
> > 
> > Thanks for the info.
> > 
> > Can we perhaps require FIT_BEST_MATCH and then provide a way? All this
> > filename stuff is missing the point, really. It isn't going to get any
> > easier, either.
> > 
> 
> Thanks for the pointer. FIT_BEST_MATCH would allow to select a matching
> device-tree from a FIT image. But any solution using FIT images will not not
> be compatible to other firmware.
> 
> As a distro I would prefer a solution that runs on any EFI firmware, e.g.
> EDK II. Being able to use the same image on all boards of the same
> architecture was the motivator for Suse to start U-Boot's EFI
> implementation.

I'm pretty sure tianocore, grub and systemd takes patches too? And
everyone is going to need to do _something_ because all of the measured
boot stuff that distributions want starts from "we can't check the
measurement of 10000 files, we need to check one file". So it's pretty
handy then that there's an open and well known specification that
handles that problem. I'm still frankly a little baffled as to what
would prevent UKI from being "EFI application stub around a FIT image".