UEFI News and Commentary

Wednesday, October 31, 2012

GNU EFI

If you really want to write UEFI applications under Linux (using GPL instead of BSD), you can, with the GNU-EFI project on SourceForge. The latest version was released about 6 months ago and contains libraries and header files to creating UEFI executables under a Linux/GCC toolchain. Since I've worked mostly with the EDK2 setup at tianocore.org, it was a fresh look at what it really takes to create an app instead of the conventions I am used to.

Matthew Garrett does a pretty good job of walking through the process of writing a basic app on his blog, including how to print things, how to use the basic UEFI services, etc. as well as giving the "why" of things.

The biggest hang-up I have is realted to the uefi_call_wrapper(). It is used for some CPU architectures because the Linux calling convention and the UEFI calling convention don't match. But having to use the call wrapper makes code harder to read and defeats the parameter error checking (because it uses varargs underneath). The EDK2 toolchain uses the EFIAPI modifier instead, even for GCC and this allows the compiler to automatically determine when to use the different calling convention. I'm not sure why GNU-EFI doesn't do the same.

There are some other minor nits. For example, there are a lot of constants in the header files that don't make sense. Why is the firmware vendor set to "INTEL" and why is the specification revision set to EFI 1.02?

It is fairly complete for basic UEFI apps. And it looks friendly to a Linux developer.

3 comments:

Unknown said...

Hi Tim,
So gnu-efi has used EFIAPI for this in the past (when cdecl was used), but it suffered when everything switched to 64-bit. At the time, gcc didn't have a function-level operator to use the MS/AMD 64-bit API.

At some point one was added, and it looks like: __attribute__((ms_abi)). Not the prettiest thing ever, but it (mostly) works.

Last week, I posted a patch series to fix this. Unfortunately, there's no mailing list for gnu-efi, so you'll have to look at them at my mirror of the source tree on github.

There are still some minor outstanding problems. For now you need to make sure you use "-DGNU_EFI_USE_MS_ABI -maccumulate-outgoing-args" when compiling, and variadic functions won't work: see this bug against gcc.

But it's better than it was.

Tim Lewis said...

Peter, thanks. That looks like forward progress. The variadic stuff would still be a problem for a small number of functions (InstallMultiple comes to mind).

Unknown said...

So after some more thinking and grepping about this, I figured out another thing we can do. With that in mind, I've pushed another patch to my github tree.

This should allow our implementation of anything like InstallMultiple to work around this issue. Of course, we'll need InstallMultipleV or somesuch to actually /write/ that wrapper in anything other than a macro.