UEFI: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
m Bot: Replace deprecated source tag with syntaxhighlight
m Fix lint errors
 
(4 intermediate revisions by the same user not shown)
Line 123:
 
==Developing with POSIX-UEFI==
:''{{Main article: [[|POSIX-UEFI]]}}
 
One option to compile UEFI applications on POSIX like systems is POSIX-UEFI. It provies a [[libc]]-like API for your EFI application, and ships with a Makefile that can detect and set up the toolchain for you. It can use GCC or LLVM, and defaults to using the host compiler, but a cross compiler is still recommended.
Line 129:
It uses POSIX style typedefs (like ''uintn_t'' instead of ''UINTN''), and it does not ship with the standard EFI headers. You can still get interfaces not covered by POSIX-UEFI (such as GOP) by installing the EFI headers from GNU-EFI or EDK2. Also, it compiles with the MS ABI, meaning that UEFI services can be called natively (i.e., without uefi_call_wrapper) so long as your apps are compiled with it as well.
The traditional "Hello, world" UEFI program goes like this.
<sourcesyntaxhighlight lang="c">
#include <uefi.h>
Line 137:
return 0;
}
</syntaxhighlight>
</source>
Makefile looks like this:
<syntaxhighlight lang="make">
Line 146:
 
==Developing with GNU-EFI==
:''{{Main article: [[|GNU-EFI]]}}
 
GNU-EFI can be used to develop both 32-bit and 64-bit UEFI applications. This section will address 64-bit UEFI applications only, and assumes that the development environment itself is running on an x86_64 system, so that no cross-compiler is needed. For a more thorough walk-through of a proper (non-gnu-efi) development environment, see [[UEFI App Bare Bones]].
Line 161:
 
The traditional "Hello, world" UEFI program is shown below.
<sourcesyntaxhighlight lang="c">
#include <efi.h>
#include <efilib.h>
Line 173:
return EFI_SUCCESS;
}
</syntaxhighlight>
</source>
 
A few notes:
Line 241:
 
===Creating disk images===
:''{{Main article: [[|Bootable Disk]]}}
 
To launch a UEFI application you will need to create a disk image and present it to QEMU. UEFI firmware expects UEFI applications to be stored in a FAT12, FAT16, or FAT32 file system on a [[GPT]] or [[MBR]]-partitioned disk. Many firmwares only support FAT32, so that's what you'll want to use. Depending on your platform, there are several different ways to create a disk image containing your UEFI application, but they all start by creating a zeroed disk image file. The minimum FAT32 partition size is 33,548,800 bytes, plus you will need space for the primary and secondary GPT tables, plus some slack space so the partition can be aligned correctly. Throughout these examples we will be creating a 48,000,000 byte (93750 512-byte sectors, or 48 MB) disk image.
Line 251:
The uefi-run application is useful for quick testing. It creates a temporary FAT image containing your EFI application and starts qemu.
 
<sourcesyntaxhighlight lang="bash">
$ uefi-run -b /path/to/OVMF.fd -q /path/to/qemu app.efi -- <extra_qemu_args>
</syntaxhighlight>
</source>
 
uefi-run is not currently packaged for any distribution. You can install it using cargo (the Rust package manager) though ("cargo install uefi-run").