gnu-efi or EDK2

Programming, for all ages and all languages.
Post Reply
srg4096
Posts: 7
Joined: Sun Apr 04, 2010 3:12 pm

gnu-efi or EDK2

Post by srg4096 »

Hi

I've not been here in a while, glad it's still going strong!

I want to do some playing around with writing UEFI applications but I've noticed there's two choices available.

What are the relative advantages and disadvantages of gnu-efi and the EDK2 (I use linux BTW, but I do have a windows machine I could play on).

I've heard that you can't do as much with gnu-efi as you can with EDK2 but that may not bother me.

Thanks!
User avatar
elderK
Member
Member
Posts: 190
Joined: Mon Dec 11, 2006 10:54 am
Location: Dunedin, New Zealand
Contact:

Re: gnu-efi or EDK2

Post by elderK »

Bump. I'd find the answer to this question interesting :)
~K
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: gnu-efi or EDK2

Post by jnc100 »

The main difference is in the build system used. Note that (x86_64) UEFI applications, drivers etc are supposed to be in the PE file format, using the Microsoft x64 calling convention.

EDKII can use various different compilers (e.g. MSVC, ICC or a cross-compiled GCC it will build itself) to produce executables in this format. It also comes with an extensive collection of support libraries (e.g. std C library, math library etc) and example applications and drivers (including a PS/2 mouse driver which is particularly useful). Its main disadvantages, IMHO, are its sheer size and the fact you need to use its own customized makefile format to build anything useful.

gnu-efi approaches this a different way: it uses the native gcc on your system, which it expects to produce binaries in ELF format, and then uses a cross-compiled objcopy to convert these to PE with customized linker scripts and section names. Of course, this doesn't fix the problem that the compiled code still expects to use the sysV calling convention, rather than the Microsoft one. To get around this, all calls to UEFI functions need to go through uefi_call_wrapper() to put the arguments in the right places.

I have come up with a third way, using a gcc cross-compiler. Unfortunately there is no gcc target along the lines of x86_64-efi etc, so you need to choose something close. The most appropriate one I have found is i686-pc-mingw32-gcc for 32-bit and x86_64-w64-mingw32-gcc for 64-bit. These are available as cygwin packages and should also be available pre-built on most linux distributions. You should use the header files from gnu-efi and invoke as:

Code: Select all

x86_64-w64-mingw32-gcc -Ignu-efi/inc -Ignu-efi/inc/x86_64 -Ignu-efi/inc/protocol -ffreestanding -Wall -Wextra <options to disable mmx/sse etc> -c -o kernel.o kernel.c
x86_64-w64-mingw32-gcc -nostdlib -Wl,-dll -shared -Wl,--subsystem,10 -e efi_main -o kernel.efi kernel.o
where 'gnu-efi' is the path the gnu-efi distribution. The main drawbacks of this method are that the 32-bit version appends leading underscores to names (you need to tell the compiler not to do this), and that it defines the preprocessor macro 'WINDOWS' which causes some 3rd party packages to expect windows.h to be available, when it clearly isn't in a freestanding boot environment. For an example of this method, see the code and Makefiles here.

Regards,
John.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: gnu-efi or EDK2

Post by Combuster »

My personal experience with gnu-efi is that it is a world of hacks. It requires startup code to perform relocation fixups that are otherwise solved by the PE format itself, and at the same time creates illegal binaries that make binutils crash when you try to objdump them.

And with the version I got, the end result was non-functional.

Would not use gnu-efi ever again.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply