boot: pxe: pass the initrd to EFI applications
PATCH 1/1 boot: pxe: pass the initrd to EFI applications
Since commit 841abbc6d561 ("boot: pxe: support booting PE/COFF EFI applications") label_boot() runs every image with a PE/COFF header via efi_binary_run(). That includes regular arm64 distro kernels, which carry both the "MZ" PE header and the ARM64 Image magic and were booted with booti before.
The initrd named in the label is still loaded to ramdisk_addr_r, but it is not handed to efi_binary_run(), so the EFI stub starts the kernel without an initramfs. With a stock Debian arm64 kernel (storage drivers and ext4 as modules, root=UUID=) this ends in
VFS: Cannot open root device "UUID=..." or unknown-block(0,0): error -6
Kernel panic - not syncing: VFS: Unable to mount root fs
Pass the loaded initrd to efi_binary_run(), which installs it with efi_install_initrd() so the EFI stub can fetch it through the LoadFile2 initrd protocol.
Tested on FriendlyElec CM3588 NAS (RK3588) with Debian linux-image-arm64
--- boot/pxe_utils.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
boot/pxe_utils.c +10 -1
@@ -807,13 +807,22 @@ int label_boot(struct pxe_context *ctx, struct pxe_label *label)if (IS_ENABLED (CONFIG_CMD_BOOTEFI ) &&efi_check_pe (buf, kernel_size,NULL ) ==EFI_SUCCESS ) {void *fdt =EFI_FDT_USE_INTERNAL ; +void *initrd =NULL ; +size_t initrd_sz =0 ;efi_status_t efi_ret;log_debug ("using bootefi\n" );if (bootm_argv[3 ]) fdt =map_sysmem (hextoul (bootm_argv[3 ],NULL ),0 ); - efi_ret =efi_binary_run (buf, kernel_size, fdt,NULL ,0 ); +/* hand the initrd to the EFI stub via LoadFile2 */ +if (initrd_addr_str && initrd_addr_str != kernel_addr) { + initrd =map_sysmem (hextoul (initrd_addr_str,NULL ),0 ); + initrd_sz =hextoul (initrd_filesize,NULL ); + } + + efi_ret =efi_binary_run (buf, kernel_size, fdt, initrd, + initrd_sz);if (efi_ret !=EFI_SUCCESS )log_err ("efi_binary_run failed (ret=%lu)\n" , efi_ret);/* Try bootm for legacy and FIT format image */
Signature · 1 line
2.53.0
Hi Tim,
Thanks for your work.
Quoted 43 lines · Tim Surber
Since commit
841abbc6d561("boot: pxe: support booting PE/COFF EFI applications")label_boot()runs every image with a PE/COFF header viaefi_binary_run(). That includes regular arm64 distro kernels, which carry both the "MZ" PE header and the ARM64 Image magic and were booted with booti before.The initrd named in the label is still loaded to
ramdisk_addr_r, but it is not handed toefi_binary_run(), so the EFI stub starts the kernel without an initramfs. With a stock Debian arm64 kernel (storage drivers and ext4 as modules, root=UUID=) this ends inVFS: Cannot open root device "UUID=..." or unknown-block(0,0): error -6
Kernel panic - not syncing: VFS: Unable to mount root fsPass the loaded initrd to
efi_binary_run(), which installs it withefi_install_initrd()so the EFI stub can fetch it through the LoadFile2 initrd protocol.Tested on FriendlyElec CM3588 NAS (RK3588) with Debian linux-image-arm64
Fixes 841abbc6d561 ("boot: pxe: support booting PE/COFF EFI applications")Signed-off-by Tim Surber <[email protected]>--- boot/pxe_utils.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)boot/pxe_utils.c +3
-1@@ -807,13 +807,22 @@ int label_boot(struct pxe_context *ctx, struct pxe_label *label)if (IS_ENABLED (CONFIG_CMD_BOOTEFI ) &&efi_check_pe (buf, kernel_size,NULL ) ==EFI_SUCCESS ) {void *fdt =EFI_FDT_USE_INTERNAL ; +void *initrd =NULL ; +size_t initrd_sz =0 ;efi_status_t efi_ret;log_debug ("using bootefi\n" );if (bootm_argv[3 ]) fdt =map_sysmem (hextoul (bootm_argv[3 ],NULL ),0 ); - efi_ret =efi_binary_run (buf, kernel_size, fdt,NULL ,0 ); +/* hand the initrd to the EFI stub via LoadFile2 */
boot/pxe_utils.c int label_boot(struct pxe_context *ctx, struct pxe_label *label) · line 828
Quoted 10 lines
boot/pxe_utils.c +7
-0+if (initrd_addr_str && initrd_addr_str != kernel_addr) { + initrd =map_sysmem (hextoul (initrd_addr_str,NULL ),0 ); + initrd_sz =hextoul (initrd_filesize,NULL ); + } + + efi_ret =efi_binary_run (buf, kernel_size, fdt, initrd, + initrd_sz);if (efi_ret !=EFI_SUCCESS )log_err ("efi_binary_run failed (ret=%lu)\n" , efi_ret);/* Try bootm for legacy and FIT format image */
Your patch fixes the missing initramfs in my PXE boot setup on my several RISC-V boards.
However, the tabs in this patch seem to have been replaced with spaces. This also affects the context lines, so b4 shazam fails to apply it:
Applying: boot: pxe: pass the initrd to EFI applications Using index info to reconstruct a base tree...
Patch failed at 0001 boot: pxe: pass the initrd to EFI applications
error: patch failed: boot/pxe_utils.c:807
error: boot/pxe_utils.c: patch does not apply
error: Did you hand edit your patch?
I had to apply it with git apply --ignore-whitespace. Could you please check and resend it with the tabs preserved?
Signature · 2 lines
Best regards, Junhui Liu
Quoted 72 lines · Junhui Liu
Hi Tim,
Thanks for your work.
Quoted 43 lines · Tim Surber
Since commit
841abbc6d561("boot: pxe: support booting PE/COFF EFI applications")label_boot()runs every image with a PE/COFF header viaefi_binary_run(). That includes regular arm64 distro kernels, which carry both the "MZ" PE header and the ARM64 Image magic and were booted with booti before.The initrd named in the label is still loaded to
ramdisk_addr_r, but it is not handed toefi_binary_run(), so the EFI stub starts the kernel without an initramfs. With a stock Debian arm64 kernel (storage drivers and ext4 as modules, root=UUID=) this ends inVFS: Cannot open root device "UUID=..." or unknown-block(0,0): error -6
Kernel panic - not syncing: VFS: Unable to mount root fsPass the loaded initrd to
efi_binary_run(), which installs it withefi_install_initrd()so the EFI stub can fetch it through the LoadFile2 initrd protocol.Tested on FriendlyElec CM3588 NAS (RK3588) with Debian linux-image-arm64
Fixes 841abbc6d561 ("boot: pxe: support booting PE/COFF EFI applications")Signed-off-by Tim Surber <[email protected]>--- boot/pxe_utils.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)boot/pxe_utils.c +3
-1@@ -807,13 +807,22 @@ int label_boot(struct pxe_context *ctx, struct pxe_label *label)if (IS_ENABLED (CONFIG_CMD_BOOTEFI ) &&efi_check_pe (buf, kernel_size,NULL ) ==EFI_SUCCESS ) {void *fdt =EFI_FDT_USE_INTERNAL ; +void *initrd =NULL ; +size_t initrd_sz =0 ;efi_status_t efi_ret;log_debug ("using bootefi\n" );if (bootm_argv[3 ]) fdt =map_sysmem (hextoul (bootm_argv[3 ],NULL ),0 ); - efi_ret =efi_binary_run (buf, kernel_size, fdt,NULL ,0 ); +/* hand the initrd to the EFI stub via LoadFile2 */ boot/pxe_utils.c int label_boot(struct pxe_context *ctx, struct pxe_label *label) · line 828
Quoted 10 lines
boot/pxe_utils.c +7
-0+if (initrd_addr_str && initrd_addr_str != kernel_addr) { + initrd =map_sysmem (hextoul (initrd_addr_str,NULL ),0 ); + initrd_sz =hextoul (initrd_filesize,NULL ); + } + + efi_ret =efi_binary_run (buf, kernel_size, fdt, initrd, + initrd_sz);if (efi_ret !=EFI_SUCCESS )log_err ("efi_binary_run failed (ret=%lu)\n" , efi_ret);/* Try bootm for legacy and FIT format image */ Your patch fixes the missing initramfs in my PXE boot setup on my several RISC-V boards.
However, the tabs in this patch seem to have been replaced with spaces. This also affects the context lines, so b4 shazam fails to apply it:
Applying: boot: pxe: pass the initrd to EFI applications Using index info to reconstruct a base tree...
Patch failed at 0001 boot: pxe: pass the initrd to EFI applications
error: patch failed:boot/pxe_utils.c:807
error:boot/pxe_utils.c: patch does not apply
error: Did you hand edit your patch?
Quoted 3 lines
I had to apply it with git apply --ignore-whitespace. Could you please check and resend it with the tabs preserved?
Hello Aswin, hello Junhui,
Function label_boot() is called by this call sequence:extlinux_boot->pxe_process->handle_pxe_menu->label_boot
But also by bls_boot() and extlinux_pxe_boot->pxe_process.
The description of 841abbc6d561 ("boot: pxe: support booting PE/COFF EFI applications") sounded like it would only concern network booting via boot method PXE and not other boot methods like extlinux and bls and specifically not booting from block devices.
The extlinux boot method before 841abbc6d561 booted via the Linux legacy entry point and not via EFI.
If a change of the bls and extlinux boot methods is intended, this should be clearly communicated.
Best regards
Heinrich
Hi Heinrich and Tim
[...]
Quoted 14 lines
Quoted 1 line
Hello Aswin, hello Junhui,
Function
label_boot()is called by this call sequence:extlinux_boot->pxe_process->handle_pxe_menu->label_bootBut also by
bls_boot()andextlinux_pxe_boot->pxe_process.The description of
841abbc6d561("boot: pxe: support booting PE/COFF EFI applications") sounded like it would only concern network booting via boot method PXE and not other boot methods like extlinux and bls and specifically not booting from block devices.
Quoted 5 lines
The extlinux boot method before
841abbc6d561booted via the Linux legacy entry point and not via EFI.If a change of the bls and extlinux boot methods is intended, this should be clearly communicated.
I agree we should fix the original patch and intention. However, Tim's patch enhances functionality and seems irrelevant to the breakage, it just happens to fix it, although we still priotarize EFI instead of extlinux for example.
I'll have a closer look at the patch tomorrow, but I don't see anything wrong with it.
Thanks
/Ilias
Quoted 4 lines
Best regards
Heinrich
Quoted 23 lines · Ilias Apalodimas
Hi Heinrich and Tim
[...]
Quoted 19 lines
Quoted 1 line
Hello Aswin, hello Junhui,
Function
label_boot()is called by this call sequence:extlinux_boot->pxe_process->handle_pxe_menu->label_bootBut also by
bls_boot()andextlinux_pxe_boot->pxe_process.The description of
841abbc6d561("boot: pxe: support booting PE/COFF EFI applications") sounded like it would only concern network booting via boot method PXE and not other boot methods like extlinux and bls and specifically not booting from block devices.The extlinux boot method before
841abbc6d561booted via the Linux legacy entry point and not via EFI.If a change of the bls and extlinux boot methods is intended, this should be clearly communicated.
One unintended change is that the extlinux fdtoverlay parameter (see CONFIG_OF_LIBFDT_OVERLAY) in extlinux.conf will be ignored for EFI binaries.
Quoted 15 lines
I agree we should fix the original patch and intention. However, Tim's patch enhances functionality and seems irrelevant to the breakage, it just happens to fix it, although we still priotarize EFI instead of extlinux for example.
I'll have a closer look at the patch tomorrow, but I don't see anything wrong with it.
Thanks
/IliasQuoted 4 lines
Best regards
Heinrich