Building a bootable UEFI application entirely in Python — no NASM, no linker, and no C compiler for the EFI binary.
What makes this interesting is that the .efi executable itself wasn't produced from C or assembly source. The program was written in Python using Aetherix, which emits the required machine code and packages it into a valid UEFI executable.
from aetherix.uefi.app import UefiApp
from aetherix.uefi import console, keyboard, diskimage
from aetherix import regs
app = UefiApp()
@app.entry
def main(prog, sys_table):
console.clear_screen(prog, sys_table)
console.set_cursor_position(prog, sys_table, 0, 0)
console.println(prog, "Hello from Aetherix UEFI!", sys_table)
console.println(prog, "", sys_table)
console.println(prog, "This machine code was generated entirely by aetherix.uefi --", sys_table)
console.println(prog, "no nasm, no ld, no C compiler toolchain for the .efi itself.", sys_table)
console.println(prog, "", sys_table)
console.println(prog, "Press any key to continue...", sys_table)
keyboard.read_key(prog, sys_table, regs.R12, regs.R13)
console.set_cursor_position(prog, sys_table, 0, 8)
console.println(prog, "Key received. Returning control to firmware.", sys_table)
efi_path = app.build(str("uefi_hello.efi"))
print(f"Built: {efi_path} ({efi_path.stat().st_size} bytes)")
img_path = diskimage.write_disk_image(efi_path.read_bytes(), str("uefi_hello.img"))
print(f"Built: {img_path} ({img_path.stat().st_size} bytes)")
print(r'Boot it with: qemu-system-x86_64 -drive if=pflash,format=raw,readonly=on,file="D:\Program Files\qemu\share\edk2-x86_64-code.fd" -drive if=pflash,format=raw,file=.\vars.fd -drive file=uefi_hello.img,format=raw')
Resources
📦 Install
pip install aetherix
🔗 GitHub
https://github.com/DivyanshuSinha136/Aetherix
⭐ If you enjoyed this article, consider starring the repository.
Feedback and contributions are always welcome!
Top comments (0)