BadUefi is a UEFI application designed to decode and render MPEG-1 video directly in the pre-boot environment (before the operating system even loads). Utilizing the Graphics Output Protocol (GOP) playing Bad Apple!!.
- Bare-Metal Playback: Video decoding and rendering without relying on any OS-level APIs.
- High-Precision Synchronization (Master Clock): Uses CPU cycles via
AsmReadTsc()to calibrate execution time and dynamically compensate for VRAM latency, maintaining a rock-solid framerate (FPS) and preventing video drift. - High VRAM Performance: Sends decoded frames directly to video memory using highly optimized block copying (Fast Memcpy), bypassing the speed limitations of uncached VRAM access.
Developing in pure C for UEFI can be cumbersome. This project implements several ready-to-use, object-oriented C++ wrappers to easily interact with the firmware:
Graphics: Abstracts the complexity of the GOP (Graphics Output Protocol). Makes it easy to clear the screen, draw pixels, render rectangles, and display frames directly to the FrameBuffer with automatic scaling and centering.UefiFile: A clean and safe wrapper aroundEFI_FILE_PROTOCOLto easily handle file system operations (read, write, get sizes, and seek) from the boot drive.
The core of this media engine is pl_mpeg. However, since the original library depends heavily on the C standard library (libc), it was completely rewritten and ported to run natively within the EDK II ecosystem.
- All dependencies on
<stdio.h>,<stdlib.h>, and<string.h>were removed. - Memory allocations (
malloc,free,realloc) were replaced with UEFI APIs (AllocatePool,FreePool,ReallocatePool). - Memory operations (
memcpy,memset) were adapted to native firmware functions (CopyMem,ZeroMem). - Primitive types were converted to UEFI architecture standards (
UINTN,UINT8,INT32, etc.).
Want to see it in action before compiling? Check out the showcase on YouTube:
To compile BadUefi correctly and fully leverage its C++ wrappers and debugger integration, it is required to use the VisualUefiEx development environment.
Created by me (based on the excellent original VisualUefi project by ionescu007), VisualUefiEx solves the biggest headaches of modern EDK-II development in Visual Studio 2022. It automates the EDK-II libraries compilation, sets up the necessary system environment variables, and provides a ready-to-use, modern C++ UEFI Project template for Visual Studio.
- Set up the Environment: First, go to the VisualUefiEx repository and follow its installation guide to properly configure your Visual Studio 2022 with the EDK-II tools.
- Clone this Project: Clone the BadUefi repository and open it using your newly configured Visual Studio.
- Compile: Build the project for the
x64architecture. - Prepare the Media File: You must copy the
BadApple.mpgfile from theVideofolder of this repository and paste it into your build output folder (e.g.,x64\Release\). - Deploy & Enjoy
This project was only made possible thanks to the following open-source projects:
- pl_mpeg by Dominic Szablewski (phoboslab): MPEG1 Video and MP2 Audio decoder in a single C file (rewritten in this project for UEFI support).
- FastMemcpy by skywind3000: Used for aggressive optimization in memory block copying, ensuring high framerates when rendering to the FrameBuffer.
- VisualUefi by ionescu007: The VisualUefiEx development environment used to build this project is based on the incredible original work by Alex Ionescu, which greatly simplified UEFI development in Visual Studio.
Developed by Lincoln Dias