A Linux developer's guide to writing bare-metal apps on UEFI firmware
First steps in bare-metal programming using UEFI
Kevin Boone's five-part series walks experienced Linux developers through building bare-metal applications for UEFI-based PCs, assuming no prior UEFI knowledge. It covers the toolchain, compiling and linking, creating a bootable disk image for DVD or USB, the EFI system partition, and basic file handling via the Simple File Protocol. The parts build on each other, so they're meant to be read in order.
Please note that I wrote these articles to be read in order. Each one relies on information from the previous articles, and it might be difficult to follow them out of sequence.
- the_panopticon
For "Get used to the lack of a C standard library" mentioned in https://kevinboone.me/efitest4.html there's always https://github.com/tianocore/edk2-libc.
And on "Be aware of the Windows-ness of EFI" commentary the resemblance to Windows coding style https://computernewb.com/~lily/files/Documents/NTDesignWorkb... is no accident. We leveraged this coding methodology as we evolved the original Intel Boot Initiative then EFI and then UEFI code and specification https://www.intel.com/content/dam/www/public/us/en/documents...
- kevin_thibedeau
> The linker won’t complain if your code calls functions that don’t exist – it will just mark them as external, expecting them to be provided by some other code. But they won’t be, and the program will just crash when it calls one of these missing functions.
You can verify no external symbols remain after linkage with: nm -D --undefined-only. This can be incorporated into a build script to verify the binary is valid.
- edoceo
This guide is fantastic for getting rolling in the UEFI space. I used this as one of the references when building a bootloader with Zig. Has its own set of issue, especially that 16bit character situation.
Once you dig into those there are a bunch of sharp edges, or maybe it's just that that EFI environment is so weird compared to typical Linux system or application development.
- hocusPokeUs
Other cool uefi programming resources:
Irc client in uefi: https://github.com/codyd51/uefirc
UEFI library the irc client relies on: https://github.com/rust-osdev/uefi-rs
No more separate GRUB/boot loader code paths needed; boot Linux from UEFI by loading a kernel: https://pretalx.com/devconf-cz-2024/talk/W3AVCT/
Have noodled around with a side-project generating an entire system from boot loader via LLMs but haven't had energy for it given job is the same headspace that needs to be ignored once in a while to not burnout; ultimately want to boot a model of my Linux use (am using bpf to plan and model everything possible and convert it to a compute schedule for sched_ext) and just have a kernel <> model architecture
For security am considering how to embed in the model various authentication obligations to block access to certain blocks of memory without confirmation via webcam and key or something
- mrlonglong
Yikes. UEFI is way worse than I thought it was.
Best thing to do with it is treat it as a bootloader and use something else a lot more sane than UEFI.
Dare I live in hope that a newer revision will use 8 bit UTF and better conventions.