[Question] efi: First 512 bytes of image oddity.

From: Ariel Cabello Mateos
Date: Thu Jun 30 2022 - 17:54:47 EST


Hello:

I am not able to understand why the function efi_pe_entry in
drivers/firmware/efi/libstub/x86-stub.c
(which if im not mistaken its the first function executed in a efistub
kernel) does not copy the part of setup_header which is in the first
512 bytes of the kernel image.

There is a comment that says:

/*
* Fill out some of the header fields ourselves because the
* EFI firmware loader doesn't load the first sector.
*/

But from what I understood about the uefi spec, the boot firmware
should do a loadImage() which in turn does a OpenEx() in the file to
load it. It does not mention anything about not loading the 512 first
bytes of the image so... why does the stub do that?

Thanks in advance,
Ariel.