# Rust OS Dev Journey Pt.1 : creating and launching a basic UEFI application
In this first post, I'm going to write a basic UEFI application that will later serve as the bootloader for my OS.
Following instructions from those :
- https://wiki.osdev.org/POSIX-UEFI
- https://wiki.osdev.org/UEFI
## Prerequisites
I will be using the Rust programming languages and a few tools that I will install from cargo. You can install it from here https://rustup.rs/. (You won't need Rust if you're following along this first post. I will use cargo to install a program at some point but there are alternatives I will mention.)
## Setting up a development environment
I'm starting by downloading the contents of this https://gitlab.com/bztsrc/posix-uefi/-/tree/master/uefi folder into `bootloader/uefi`. Then I'm going to add this bit of code into `bootloader/main.c` :
```c
#include <uefi.h>
int main (int argc, char **argv)
{
printf("Hello, world!\n");
return 0;
}
```
Finally, I'm adding this into `bootloader/Makefile` :
```make
TARGET = syscontrol_64.efi
include uefi/Makefile
```
The included `bootloader/uefi/Makefile` should do all the work for me and just output a nice `syscontrol_64.efi` file after I run `make`. Of course, you can replace `syscontrol_64` with whatever OS name you want.
## Launching my application
### OVMF
To launch my application on QEMU (the emulator I will be using and that I recommend you use too) I will need something called OVMF, it will allow me to launch UEFI applications with it. (For more info read this : https://github.com/tianocore/tianocore.github.io/wiki/OVMF-FAQ).
I Installed it with a package using the following command on Manjaro :
```
sudo pacman -Sy ovmf
```
Your Linux distribution (if you use Linux, which I also recommend for this kind of thing) probably offers a similar way to install it. You can find builds here too https://www.kraxel.org/repos/jenkins/edk2/.
After installation, I could find all the files I needed in `/usr/share/edk2-ovmf/x64`. You might want to look at the "Package contents" section here https://archlinux.org/packages/extra/any/edk2-ovmf/ if you're also using an arch-based distro but doing this a bit differently.
### Getting to launch on QEMU
I'm going to be using `uefi-run` which will do most of the work for me (creating a disk image and launching qemu). You can install it with cargo :
```sh
cargo install uefi-run
```
If you don't want to use it there are alternatives, see the "Creating disk images" and "Launching UEFI applications" sections here https://wiki.osdev.org/UEFI.
I'm going to create a little `launch.sh` script just so I don't have to retype / remember the command to launch uefi-run :
```sh
uefi-run -b /usr/share/edk2-ovmf/x64/OVMF.fd -q /usr/bin/qemu-system-x86_64 ./bootloader/syscontrol_64.efi
```
You'll probably want to change the file paths if you installed OVMF to a different location or named your OS differently.
Don't forget to make the file executable `chmod +x ./launch.sh` !
Let's test everything and run `./launch.sh`

And after about 5 seconds of waiting... Hooray ! We can see "Hello, world !" popping up in the UEFI shell.
I'm going to add this at the beginning of my `launch.sh` file so that it rebuilds my bootloader every time I launch it
```sh
cd bootloader
make
cd ..
```