Loading UEFI compatible software into USB and running it

81 views Asked by At

I have a compiled and linked C file supposedly runnable by a UEFI system as a kernel, and I noticed that using qemu to run it is tedious.

Is there any way of running this code as if it were a BIOS bootloader (inject the raw binaries, perhaps the EFI or the IMG file, into a USB stick and turn on the computer it is connected to)?

1

There are 1 answers

2
Brendan On

For UEFI to boot an executable file on USB flash, you need:

  • either "MBR partitions" or GPT on the USB flash; with one partition formatted as a FAT file system. This partition probably also needs to be marked as "EFI System Partition" in the partition table (the UEFI specs aren't very clear but it makes sense to me).

  • the file you want executed must be in a specific directory and have a specific name that depends on what the platform is (e.g. "\EFI\BOOT\BOOTx64.EFI" for 64-bit 80x86)

  • the "Machine Type" field in the executable's PE header must match the name it was given (e.g. 0x8664 for 64-bit 80x86).

The other restriction is that you either need to make sure SecureBoot is turned off in UEFI's settings; or figure out how to digitally sign your executable with a key that the firmware accepts.

Note that the rules for removable media (e.g. USB flash) are different than the rules for fixed media (e.g. internal SATA drives).