VapourDev@gmail.com

Blog.

VapourDev

UEFI : Creating a x86_64 Simple UEFI Application

Introduction

In this Article, We are going to make a Simple x86_64 UEFI Application, that is able to print a text on screen and can be safely tested on a Real Hardware. We are going to make a simple application that use GNU-EFI as a bootloader, that supports x86 and 64 bit Architectures. We will be first Setup GNU-EFI bootloader. Then, We Configure Makefile, after that we will code a simple application in C, that can print texts. Then we can test it in our own PC. However, you want to grab the only source code instead of reading this blog, you can click the "Get Source Code" link.

Setting UP GNU-EFI

First Grab the Source Code of GNU-EFI from this Here (We are using GNU-EFI 3.0.13 - Which is Latest Now ). After Grabbing the source code extract it in your Main Project Root directory.

Open your Terminal, Change directory to your gnu-efi directory in your Main Project Root Directory, then Run make This will compile the raw library files.

Then, We need to make a build rule to compile our code, That is Very Simple, Open your Main Project directory with your Favoirite code editor, then Open "gnu-efi-3.0.13/Makefile".

On Line 45-47, you can see a SUBDIRS container, Replace that line with SUBDIRS = lib gnuefi inc apps boot We added one more value here that is "boot", this is the name of directory that consists our main Application code.

Then Create a "boot" named directory in gnu-efi-3.0.13 directory.

Code Time

That's All we are now going to code a very basic "Hello Universe" Application.

So, First of All, Create a new file "main.c" in "boot" directory and following code.

Above code is decribed by comments. This application will exit when any Keyboard Input.

We are completed our Hello Universe Code. Let's make rules to compile it.

Write Rules to Compile

Now, we have to make a rule to compile the our C files. If you know about Makefile, you can understand following script.

First Create Makefile in gnu-efi-3.0.13/boot/ directory. And copy the following script :

Note : Above code is not written by me, All Information is given in Top of file.

I am not going to explain this script, I can say only that This script set the rules for compiling C files to Object files or in other file formats.

Now we done, We can compile our code. To compile, First Change directory to main gnu-efi directory in terminal, then run make bootloader , This will compile the code and build our bootloader as efi file. You can see that file in the Project/gnu-efi/x86_64/boot directory. That is our bootloader.

Test It

Take a Pen drive, and make a directory named efi/boot/, then copy that main.efi file to that boot directory, and rename that file as bootx64.efi , That's all we have finished, now you can boot your Own UEFI Application.

Congratulations, It's now Completed.

Source Code

You can download the source code from this link.

Next Blog is Coming soon.

Related Posts

No any contents yet.