Skip to contentSkip to conversation

x86/Documentation: explain LINUX_EFI_INITRD_MEDIA_GUID

PATCH Hugo Osvaldo Barrera 2 participants 2 messages Apr 28, 2025 – May 6, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Since the Handover Protocol was deprecated, the recommended approach is to provide an initrd using a UEFI boot service with the LINUX_EFI_INITRD_MEDIA_GUID device path. Documentation for the new approach has been no more than an admonition with a link to an existing implementation.

Provide a short explanation of this functionality, to ease future implementations without having to reverse engineer existing ones.

---
 Documentation/admin-guide/efi-stub.rst |  5 ++++
 Documentation/arch/x86/boot.rst        | 36 +++++++++++++++++++-------
 2 files changed, 32 insertions(+), 9 deletions(-)
Documentation/admin-guide/efi-stub.rst +5 -0
index 090f3a185e18..3af702259f1d 100644
@@ -1,3 +1,5 @@
+.. _efi-boot-stub:
+
 =================
 The EFI Boot Stub
 =================
@@ -79,6 +81,9 @@ because the image we're executing is interpreted by the EFI shell,
 which understands relative paths, whereas the rest of the command line
 is passed to bzImage.efi.
 
+.. hint::
+   It is also possible to provide an initrd using UEFI boot services. See
+   :ref:`pe-coff-entry-point` for details.
 
 The "dtb=" option
 -----------------
Documentation/arch/x86/boot.rst +27 -9
index 77e6163288db..2fecf89910ec 100644
@@ -1431,12 +1431,30 @@ The boot loader *must* fill out the following fields in bp::
 All other fields should be zero.
 
 .. note::
-     The EFI Handover Protocol is deprecated in favour of the ordinary PE/COFF
-     entry point, combined with the LINUX_EFI_INITRD_MEDIA_GUID based initrd
-     loading protocol (refer to [0] for an example of the bootloader side of
-     this), which removes the need for any knowledge on the part of the EFI
-     bootloader regarding the internal representation of boot_params or any
-     requirements/limitations regarding the placement of the command line
-     and ramdisk in memory, or the placement of the kernel image itself.
-
-[0] https://github.com/u-boot/u-boot/commit/ec80b4735a593961fe701cc3a5d717d4739b0fd0
+   The EFI Handover Protocol is deprecated in favour of the ordinary PE/COFF
+   entry point described below.
+
+.. _pe-coff-entry-point:
+
+PE/COFF entry point
+===================
+
+When compiled with ``CONFIG_EFI_STUB=y``, the kernel can be executed as a
+regular PE/COFF binary. See :ref:`efi-boot-stub` for implementation details.
+
+The stub loader can request the initrd via a UEFI protocol. For this to work,
+the firmware or bootloader needs to register a handle which implements the
+``EFI_LOAD_FILE2`` protocol with the ``LINUX_EFI_INITRD_MEDIA_GUID`` device
+path. In this case, a kernel booting via the EFI stub will use the ``LoadFile``
+function on the registered handle to obtain a reference to the initrd.
+
+This approach removes the need for any knowledge on the part of the EFI
+bootloader regarding the internal representation of boot_params or any
+requirements/limitations regarding the placement of the command line and
+ramdisk in memory, or the placement of the kernel image itself.
+
+For sample implementations, refer to `the original u-boot implementation`_ or
+`the implementation in candyboot`_.
+
+.. _the original u-boot implementation: https://github.com/u-boot/u-boot/commit/ec80b4735a593961fe701cc3a5d717d4739b0fd0
+.. _the implementation in candyboot: https://git.sr.ht/~whynothugo/candyboot/tree/4097b2538d7f1cf85f03922bf42409490b666202/item/src/main.rs#L225
Signature · 1 line
2.49.0
maintainer
#1 lore raw
Quoted 20 lines · Hugo Osvaldo Barrera

Since the Handover Protocol was deprecated, the recommended approach is to provide an initrd using a UEFI boot service with the LINUX_EFI_INITRD_MEDIA_GUID device path. Documentation for the new approach has been no more than an admonition with a link to an existing implementation.

Provide a short explanation of this functionality, to ease future implementations without having to reverse engineer existing ones.

---
 Documentation/admin-guide/efi-stub.rst |  5 ++++
 Documentation/arch/x86/boot.rst        | 36 +++++++++++++++++++-------
 2 files changed, 32 insertions(+), 9 deletions(-)
Documentation/admin-guide/efi-stub.rst +0 -0
index 090f3a185e18..3af702259f1d 100644

Documentation/admin-guide/efi-stub.rst line 1

Quoted 1 line
Documentation/admin-guide/efi-stub.rst +1 -0
@@ -1,3 +1,5 @@
+.. _efi-boot-stub:

This label is unneeded...

Quoted 30 lines
Documentation/admin-guide/efi-stub.rst +3 -0
 =================
 The EFI Boot Stub
 =================
@@ -79,6 +81,9 @@ because the image we're executing is interpreted by the EFI shell,
 which understands relative paths, whereas the rest of the command line
 is passed to bzImage.efi.
 
+.. hint::
+   It is also possible to provide an initrd using UEFI boot services. See
+   :ref:`pe-coff-entry-point` for details.
 
 The "dtb=" option
 -----------------
Documentation/arch/x86/boot.rst +0 -9
index 77e6163288db..2fecf89910ec 100644
@@ -1431,12 +1431,30 @@ The boot loader *must* fill out the following fields in bp::
 All other fields should be zero.
 
 .. note::
-     The EFI Handover Protocol is deprecated in favour of the ordinary PE/COFF
-     entry point, combined with the LINUX_EFI_INITRD_MEDIA_GUID based initrd
-     loading protocol (refer to [0] for an example of the bootloader side of
-     this), which removes the need for any knowledge on the part of the EFI
-     bootloader regarding the internal representation of boot_params or any
-     requirements/limitations regarding the placement of the command line
-     and ramdisk in memory, or the placement of the kernel image itself.
-
-[0] https://github.com/u-boot/u-boot/commit/ec80b4735a593961fe701cc3a5d717d4739b0fd0

Documentation/arch/x86/boot.rst The boot loader *must* fill out the following fields in bp:: · line 1443

Quoted 10 lines
Documentation/arch/x86/boot.rst +10 -0
+   The EFI Handover Protocol is deprecated in favour of the ordinary PE/COFF
+   entry point described below.
+
+.. _pe-coff-entry-point:
+
+PE/COFF entry point
+===================
+
+When compiled with ``CONFIG_EFI_STUB=y``, the kernel can be executed as a
+regular PE/COFF binary. See :ref:`efi-boot-stub` for implementation details.

...just say "see Documentation/admin-guide/efi-stub.rst here.

Quoted 8 lines
Documentation/arch/x86/boot.rst +7 -0
+
+The stub loader can request the initrd via a UEFI protocol. For this to work,
+the firmware or bootloader needs to register a handle which implements the
+``EFI_LOAD_FILE2`` protocol with the ``LINUX_EFI_INITRD_MEDIA_GUID`` device
+path. In this case, a kernel booting via the EFI stub will use the ``LoadFile``
+function on the registered handle to obtain a reference to the initrd.
+

Documentation/arch/x86/boot.rst The boot loader *must* fill out the following fields in bp:: · line 1460

Quoted 10 lines
Documentation/arch/x86/boot.rst +10 -0
+This approach removes the need for any knowledge on the part of the EFI
+bootloader regarding the internal representation of boot_params or any
+requirements/limitations regarding the placement of the command line and
+ramdisk in memory, or the placement of the kernel image itself.
+
+For sample implementations, refer to `the original u-boot implementation`_ or
+`the implementation in candyboot`_.
+
+.. _the original u-boot implementation: https://github.com/u-boot/u-boot/commit/ec80b4735a593961fe701cc3a5d717d4739b0fd0
+.. _the implementation in candyboot: https://git.sr.ht/~whynothugo/candyboot/tree/4097b2538d7f1cf85f03922bf42409490b666202/item/src/main.rs#L225

Thanks,

jon