Files
buildroot/board/pc
Julien Olivain 1c1fa6ce67 board/pc/linux.config: enable CONFIG_EFI_STUB
When the Linux Kernel image does not include the EFI stub [1],
Grub2 EFI linux loader fallback to the legacy i386 loading.
See [2] [3]. Grub 2.14 enabled the NX compatible for the EFI
image in [4].

When booting a Linux Kernel without the EFI stub with Grub 2.14 with
NX flag, the boot fails before starting the kernel with a EDK2 page
fault error [5]:

!!!! X64 Exception Type - 0E(#PF - Page-Fault)  CPU Apic ID - 00000000 !!!!
ExceptionData - 0000000000000003  I:0 R:0 U:0 W:1 P:1 PK:0 SS:0 SGX:0

This commit adds CONFIG_EFI_STUB to board/pc/linux.config to make sure
grub will load the Kernel using its efi loading code.

This commit is needed with EDK2 with NX protection enabled and
Grub 2.14 also enabling NX.

[1] https://docs.kernel.org/admin-guide/efi-stub.html
[2] https://gitlab.freedesktop.org/gnu-grub/grub/-/blob/grub-2.14/grub-core/loader/efi/linux.c#L532
[3] https://gitlab.freedesktop.org/gnu-grub/grub/-/blob/grub-2.14/grub-core/loader/i386/linux.c#L675
[4] f5bb766e68
[5] https://github.com/tianocore/edk2/blob/edk2-stable202602/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c#L273

Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2026-05-29 20:53:55 +02:00
..
2025-02-04 15:38:16 +01:00

Bare PC sample config
=====================

1. Build

  First select the appropriate target you want.

  For BIOS-based boot strategy:

  $ make pc_x86_64_bios_defconfig

  For EFI-based boot strategy on a GPT-partitioned disk:

  $ make pc_x86_64_efi_defconfig

  Add any additional packages required and build:

  $ make

2. Write the image

  The build process will create a all-in-one image called disk.img in
  output/images.

  Write the image to a pendrive:

  $ dd if=output/images/disk.img of=/dev/sdX; sync

  Once it's done insert it into the target PC and boot.

  Remember that if said PC has another boot device you might need to
  select this alternative for it to boot.

  In the case of EFI boot you might need to disable Secure Boot from
  the setup as well.

3. Enjoy

Emulation in qemu (BIOS)
========================

1. Edit grub-bios.cfg

  Since the driver will show up in the virtual machine as /dev/vda,
  change board/pc/grub-bios.cfg to use root=/dev/vda1 instead of
  root=/dev/sda1. Then rebuild grub2 and the image:

    make grub2-rebuild && make

2. Run the emulation with:

qemu-system-x86_64 \
	-M pc \
	-drive file=output/images/disk.img,if=virtio,format=raw \
	-net nic,model=virtio \
	-net user


Emulation in qemu (UEFI)
========================

Run the emulation with:

qemu-system-x86_64 \
	-M pc \
	-bios </path/to/OVMF_CODE.fd> \
	-drive file=output/images/disk.img,if=virtio,format=raw \
	-net nic,model=virtio \
	-net user

Note that </path/to/OVMF.fd> needs to point to a valid x86_64 UEFI
firmware image for qemu. It may be provided by your distribution as a
edk2 or OVMF package, in path such as
/usr/share/edk2/ovmf/OVMF_CODE.fd .