[PATCH resend 4/9] linux/arm: unify ARM/arm64 vs Xen PE/COFF header handling

2022-08-18 Thread Ard Biesheuvel
Xen has its own version of the image header, to account for the additional PE/COFF header fields. Since we are adding references to those in the shared EFI loader code, update the common definitions and drop the Xen specific one which no longer has a purpose. Signed-off-by: Ard Biesheuvel --- gr

[PATCH resend 3/9] arm64/linux: Remove magic number header field check

2022-08-18 Thread Ard Biesheuvel
The 'ARM\x64' magic number in the file header identifies an image as one that implements the bare metal boot protocol, allowing the loader to simply move the file to a suitably aligned address in memory, with sufficient headroom for the trailing .bss segment (the required memory size is described i

[PATCH resend 2/9] efi: move MS-DOS stub out of generic PE header definition

2022-08-18 Thread Ard Biesheuvel
The PE/COFF spec permits the COFF signature and file header to appear anywhere in the file, and the actual offset is recorded in 4 byte little endian field at offset 0x3c of the image. When GRUB is emitted as a PE/COFF binary, we reuse the 128 byte MS-DOS stub (even for non-x86 architectures), put

[PATCH resend 8/9] efi: implement LoadFile2 initrd loading protocol for Linux

2022-08-18 Thread Ard Biesheuvel
Recent Linux kernels will invoke the LoadFile2 protocol installed on a well-known vendor media path to load the initrd if it is exposed by the firmware. Using this method is preferred for two reasons: - the Linux kernel is in charge of allocating the memory, and so it can implement any placement

[PATCH resend 1/9] loader: drop argv[] argument in grub_initrd_load()

2022-08-18 Thread Ard Biesheuvel
From: Nikita Ermakov In the case of an error grub_initrd_load() uses argv[] to print the filename that caused the error. It is also possible to obtain the filename from the file handles and there is no need to duplicate that information in argv[], so let's drop it. Signed-off-by: Nikita Ermakov

[PATCH resend 6/9] efi: add definition of LoadFile2 protocol

2022-08-18 Thread Ard Biesheuvel
Incorporate the EFI_LOAD_FILE2_PROTOCOL GUID and C types from the UEFI spec. Reviewed-by: Heinrich Schuchardt Signed-off-by: Ard Biesheuvel --- grub-core/commands/efi/lsefi.c | 1 + include/grub/efi/api.h | 15 +++ 2 files changed, 16 insertions(+) diff --git a/grub-core/c

Re: [PATCH resend 0/9] linux: implement LoadFile2 initrd loading

2022-08-18 Thread Ard Biesheuvel
On Thu, 18 Aug 2022 at 10:55, Ard Biesheuvel wrote: > > This implements the LoadFile2 initrd loading protocol, which is > essentially a callback interface into the bootloader to load the initrd > data into a caller provided buffer. This means the bootloader no longer > has to contain any policy re

[PATCH resend 0/9] linux: implement LoadFile2 initrd loading

2022-08-18 Thread Ard Biesheuvel
This implements the LoadFile2 initrd loading protocol, which is essentially a callback interface into the bootloader to load the initrd data into a caller provided buffer. This means the bootloader no longer has to contain any policy regarding where to load the initrd (which differs between archite

[PATCH resend 5/9] linux/arm: account for COFF headers appearing at unexpected offsets

2022-08-18 Thread Ard Biesheuvel
The way we load the Linux and PE/COFF image headers depends on a fixed placement of the COFF header at offset 0x40 into the file. This is a reasonable default, given that this is where Linux emits it today. However, in order to comply with the PE/COFF spec, which allows this header to appear anywhe

[PATCH resend 9/9] linux: ignore FDT unless we need to modify it

2022-08-18 Thread Ard Biesheuvel
Now that we implemented supported for the LoadFile2 protocol for initrd loading, there is no longer a need to pass the initrd parameters via the device tree. This means there is no longer a reason to update the device tree in the first place, and so we can ignore it entirely. The only remaining re

[PATCH resend 7/9] efi/efinet: Don't close connections at fini_hw() time

2022-08-18 Thread Ard Biesheuvel
When GRUB runs on top of EFI firmware, it only has access to block and network device abstractions exposed by the firmware, and it is up to the firmware to quiesce the underlying hardware when handing over to the OS. This is especially important for network devices, to prevent incoming packets fro

[PATCH v3 0/8] linux: implement LoadFile2 initrd loading

2022-08-18 Thread Ard Biesheuvel
This implements the LoadFile2 initrd loading protocol, which is essentially a callback interface into the bootloader to load the initrd data into a caller provided buffer. This means the bootloader no longer has to contain any policy regarding where to load the initrd (which differs between archite

[PATCH v3 1/8] loader: drop argv[] argument in grub_initrd_load()

2022-08-18 Thread Ard Biesheuvel
From: Nikita Ermakov In the case of an error grub_initrd_load() uses argv[] to print the filename that caused the error. It is also possible to obtain the filename from the file handles and there is no need to duplicate that information in argv[], so let's drop it. Signed-off-by: Nikita Ermakov

[PATCH v3 2/8] efi: move MS-DOS stub out of generic PE header definition

2022-08-18 Thread Ard Biesheuvel
The PE/COFF spec permits the COFF signature and file header to appear anywhere in the file, and the actual offset is recorded in 4 byte little endian field at offset 0x3c of the image. When GRUB is emitted as a PE/COFF binary, we reuse the 128 byte MS-DOS stub (even for non-x86 architectures), put

[PATCH v3 3/8] arm64/linux: Remove magic number header field check

2022-08-18 Thread Ard Biesheuvel
The 'ARM\x64' magic number in the file header identifies an image as one that implements the bare metal boot protocol, allowing the loader to simply move the file to a suitably aligned address in memory, with sufficient headroom for the trailing .bss segment (the required memory size is described i

[PATCH v3 6/8] efi/efinet: Don't close connections at fini_hw() time

2022-08-18 Thread Ard Biesheuvel
When GRUB runs on top of EFI firmware, it only has access to block and network device abstractions exposed by the firmware, and it is up to the firmware to quiesce the underlying hardware when handing over to the OS. This is especially important for network devices, to prevent incoming packets fro

[PATCH v3 4/8] linux/arm: unify ARM/arm64 vs Xen PE/COFF header handling

2022-08-18 Thread Ard Biesheuvel
Xen has its own version of the image header, to account for the additional PE/COFF header fields. Since we are adding references to those in the shared EFI loader code, update the common definitions and drop the Xen specific one which no longer has a purpose. Signed-off-by: Ard Biesheuvel --- gr

[PATCH v3 5/8] linux/arm: account for COFF headers appearing at unexpected offsets

2022-08-18 Thread Ard Biesheuvel
The way we load the Linux and PE/COFF image headers depends on a fixed placement of the COFF header at offset 0x40 into the file. This is a reasonable default, given that this is where Linux emits it today. However, in order to comply with the PE/COFF spec, which allows this header to appear anywhe

[PATCH v3 7/8] efi: implement LoadFile2 initrd loading protocol for Linux

2022-08-18 Thread Ard Biesheuvel
Recent Linux kernels will invoke the LoadFile2 protocol installed on a well-known vendor media path to load the initrd if it is exposed by the firmware. Using this method is preferred for two reasons: - the Linux kernel is in charge of allocating the memory, and so it can implement any placement

[PATCH v3 8/8] linux: ignore FDT unless we need to modify it

2022-08-18 Thread Ard Biesheuvel
Now that we implemented support for the LoadFile2 protocol for initrd loading, there is no longer a need to pass the initrd parameters via the device tree. This means that when the LoadFile2 protocol is being used, there is no reason to update the device tree in the first place, and so we can ignor

[PATCH v3 0/5] Improve logic to check for fwsetup support

2022-08-18 Thread Robbie Harwood
In this version: add and check `fwsetup --is-supported, and include the changes for Paul's review that were left out accidentally in the previous version. Be well, --Robbie Javier Martinez Canillas (2): templates: Check for EFI at runtime instead of config generation time efi: Print an error

[PATCH v3 3/5] templates: Check for EFI at runtime instead of config generation time

2022-08-18 Thread Robbie Harwood
From: Javier Martinez Canillas The 30_uefi-firmware template checks if an OsIndicationsSupported UEFI var exists and EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set, to decide whether a "fwsetup" menu entry would be added or not to the GRUB menu. But this has the problem that it will only work if th

[PATCH v3 2/5] Make all grub_efi_guid_t variables static

2022-08-18 Thread Robbie Harwood
This is believed to result in smaller code. Signed-off-by: Robbie Harwood --- grub-core/commands/efi/efifwsetup.c | 4 ++-- grub-core/efiemu/i386/pc/cfgtables.c | 6 +++--- grub-core/kern/efi/fdt.c | 2 +- grub-core/loader/efi/fdt.c | 2 +- grub-core/term/efi/console.c

[PATCH v3 4/5] efi: Print an error if boot to firmware setup is not supported

2022-08-18 Thread Robbie Harwood
From: Javier Martinez Canillas The "fwsetup" command is only registered if the firmware supports booting to the firmware setup UI. But it could be possible that the GRUB config already contains a "fwsetup" entry, because it was generated in a machine that has support for this feature. To prevent

[PATCH v3 1/5] commands/efi/efifwsetup: Add missing grub_free()s

2022-08-18 Thread Robbie Harwood
Each call of grub_efi_get_variable() needs a grub_free(). Signed-off-by: Robbie Harwood --- grub-core/commands/efi/efifwsetup.c | 11 --- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/grub-core/commands/efi/efifwsetup.c b/grub-core/commands/efi/efifwsetup.c index eaca032

[PATCH v3 5/5] Don't display a uefi-firmware entry if it's not supported

2022-08-18 Thread Robbie Harwood
Add a new --is-supported option to commands/efi/efifwsetup and conditionalize display on it. Signed-off-by: Robbie Harwood --- grub-core/commands/efi/efifwsetup.c | 3 +++ util/grub.d/30_uefi-firmware.in | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/grub-core/commands

[PATCH v4 1/5] commands/efi/efifwsetup: Add missing grub_free()s

2022-08-18 Thread Robbie Harwood
Each call of grub_efi_get_variable() needs a grub_free(). Signed-off-by: Robbie Harwood --- grub-core/commands/efi/efifwsetup.c | 11 --- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/grub-core/commands/efi/efifwsetup.c b/grub-core/commands/efi/efifwsetup.c index eaca032

[PATCH v4 2/5] Make all grub_efi_guid_t variables static

2022-08-18 Thread Robbie Harwood
This is believed to result in smaller code. Signed-off-by: Robbie Harwood --- grub-core/commands/efi/efifwsetup.c | 4 ++-- grub-core/efiemu/i386/pc/cfgtables.c | 6 +++--- grub-core/kern/efi/fdt.c | 2 +- grub-core/loader/efi/fdt.c | 2 +- grub-core/term/efi/console.c

[PATCH v4 0/5] Improve logic to check for fwsetup support

2022-08-18 Thread Robbie Harwood
In this version: fix wrong arg parsing in patch to address Glenn's review. Be well, --Robbie Javier Martinez Canillas (2): templates: Check for EFI at runtime instead of config generation time efi: Print an error if boot to firmware setup is not supported Robbie Harwood (3): commands/efi/e

[PATCH v4 3/5] templates: Check for EFI at runtime instead of config generation time

2022-08-18 Thread Robbie Harwood
From: Javier Martinez Canillas The 30_uefi-firmware template checks if an OsIndicationsSupported UEFI var exists and EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set, to decide whether a "fwsetup" menu entry would be added or not to the GRUB menu. But this has the problem that it will only work if th

[PATCH v4 5/5] Don't display a uefi-firmware entry if it's not supported

2022-08-18 Thread Robbie Harwood
Add a new --is-supported option to commands/efi/efifwsetup and conditionalize display on it. Signed-off-by: Robbie Harwood --- grub-core/commands/efi/efifwsetup.c | 3 +++ util/grub.d/30_uefi-firmware.in | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/grub-core/commands

[PATCH v4 4/5] efi: Print an error if boot to firmware setup is not supported

2022-08-18 Thread Robbie Harwood
From: Javier Martinez Canillas The "fwsetup" command is only registered if the firmware supports booting to the firmware setup UI. But it could be possible that the GRUB config already contains a "fwsetup" entry, because it was generated in a machine that has support for this feature. To prevent