Operating systems need a description of the hardware. This description can
either be supplied via ACPI tables or via device-trees. On the ARM
architecture ACPI tables are not avaialable for most devices.

In an ideal world device-trees would be defined once by the hardware
manufacturer and would not be subject to change.

In reality device-trees or subject to frequent changes. Linux has a long
record of breaking forward and backwards compatibility between device-
trees and the kernel. So for booting it is wise to use the specific device-
tree that comes with the operation system. This requires reading the
device-tree from file.

One approach is to leave loading the device-tree file to the firmware. This
works fine if the firmware is loading the triple of kernel, initrd, and
device-tree. This is what Debian does with the flash-kernel package. It
provides a boot script for U-Boot that loads the most recent kernel,
initrd, and device-tree.

Before passing the device-tree to the operating as an EFI configuration
table the firmware goes through the following steps:

* Fix-ups are applied to the device-tree. Examples of the changes include
  the memory size and the RISC-V boot hart. Without the changes the
  operating system may not boot at all or crash later.

* Memory reservations are added to the memory map according to the
  /reserved-memory node and the memory reservation block of the
  device-tree. Without these reservations the operating system may crash.

When using GRUB it is not known beforehand which operating system the user
will choose. To guarantee compatibility with the operating system GRUB has
to take control of the device-tree loading.

GRUB has a devicetree command to load a device-tree which is then passed as
EFI configuration table to the operating systems. But GRUB lacks the
information needed to apply fix-ups to the device-tree. Further memory
reservations are not executed.

What is needed is to pass the device-tree loaded by GRUB via the
devicetree command to the firmware to execute fix-ups and memory
reservations.

U-Boot v2020.04-rc1 provides an EFI protocol for this purpose which has
been defined in the EFI_DT_FIXUP_PROTOCOL specification [1].

With the first patch in the series the devicetree command is enhanced. It
checks if an instance of the EFI_DT_FIXUP_PROTOCOL is available. If yes,
the Fixup() method of the protocol is called when the boot command is
invoked. The fixed-up device-tree is passed to the operating system as
EFI configuration table.

The second patch adjusts the 10_linux template for grub-mkconfig. If
GRUB_LOAD_DEVICETREE=true in /etc/default/grub, it looks for file
dtb-${version} matching the Linux version. If the file (or file dtb as
fallback) is found, a devicetree command is added to grub.cfg.

[1] EFI_DT_FIXUP_PROTOCOL specification
    https://github.com/U-Boot-EFI/EFI_DT_FIXUP_PROTOCOL

Heinrich Schuchardt (2):
  efi: EFI Device Tree Fixup Protocol
  10_linux: support loading device trees

 docs/grub.texi             |  6 ++++++
 grub-core/loader/efi/fdt.c | 35 ++++++++++++++++++++++++++++++++++-
 include/grub/efi/api.h     | 22 ++++++++++++++++++++++
 util/grub-mkconfig.in      |  1 +
 util/grub.d/10_linux.in    | 23 +++++++++++++++++++++++
 5 files changed, 86 insertions(+), 1 deletion(-)

--
2.30.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to