LLM Coding in UEFI: Turning Broken AI-Generated Code into a Runnable Game
A hands-on UEFI game development experiment explores whether one language model can repair another model’s failed code. The walkthrough covers code review, serial logging, a stale graphics information pointer, and an incorrect protocol GUID, with practical lessons on building effective feedback loops for AI-assisted development.
Background: A Demanding Coding Test in UEFI
I recently tried an unusual experiment: building a graphical Breakout game directly in the UEFI firmware environment, without an operating system. This is a demanding test of an LLM’s coding abilities. There is no standard library or familiar debugger to rely on; the application must work through the low-level interfaces provided by the firmware.
In the first phase, I assigned two different models tasks of roughly comparable difficulty. One built Breakout, while the other worked on Tetris. The outcomes were very different:
- Model A, assigned Breakout: Finished in about 2.5 hours. The code compiled on the first attempt and ran successfully on its first launch. Working with a mainstream AI coding agent tool, the development process went smoothly.
- Model B, assigned Tetris: Spent nearly six hours without correctly setting up the build environment. Its final code could not produce a runnable application.
One reader pointed out that comparing models on different tasks was unfair. That was a reasonable criticism. However, my original goal was not a controlled benchmark; it was to show how useful AI could be in a real development workflow.
The comment also suggested a different experiment. Model B’s code did not run, but it consisted of seven files with a modular design and an orderly structure. Rather than discard it, why not ask another model to take over and repair the mess?
That became the second experiment: Model A would repair Model B’s code. The plan had two rounds—first, make the application run; then, refine and optimize it.
Round 1: From Broken Code to a Running Application
Step 1: Review the Codebase
I copied all of Model B’s source files into a new environment without modifying them, started Model A, and gave it a simple instruction:
Review this codebase, find potential issues.
Model A examined the code module by module, covering the entry point, main loop, game logic, rendering, and input handling. Within a few minutes, it produced a list of issues and claimed that fixing them would make the application run.
I asked it to implement the changes.
Issue 1: The Application Exited Immediately
The code compiled, the application launched, and the initial screen appeared. But immediately after displaying “Starting Game Loop,” the application exited.
That was already progress compared with having no runnable program at all, but it was still far from a playable game.
My next step was to give the model better visibility into execution. I asked it to insert debug messages along critical paths and send them through the serial port. This was essential: in firmware development, serial logs are often the most dependable way to see what is happening.
With logging in place, Model A quickly narrowed the failure down to a graphics output protocol call. Further analysis identified a stale pointer to display-mode information. After the application set the display mode, the memory referenced by the old pointer was no longer valid. Accessing it afterward caused the crash.
The fix was straightforward: retrieve the framebuffer information again after setting the display mode, rather than reusing the old pointer.
After that change, the application stopped crashing.
This highlighted an important difference in how models handle lifetime-related bugs, such as dangling pointers and invalidated memory. Producing a correct fix requires understanding the memory ownership and lifetime semantics of low-level interfaces. In this experiment, that understanding was a notable strength of the newer model.
Issue 2: The Wrong Protocol GUID
The application no longer crashed, but the graphical interface still failed to appear. I reported the behavior to Model A and continued the debugging cycle.
The model traced the problem to an incorrect GUID used during protocol lookup. The UEFI development framework contained several graphics-related GUID definitions that looked very similar. Using the wrong identifier meant the application could not locate the intended graphics output protocol.
This kind of mistake can be difficult for a human developer to spot as well. The compiler reports no error, the surrounding logic looks plausible, and the failure becomes apparent only at runtime.
After the GUID was corrected, graphics initialization succeeded. The first-round objective was complete: code that had been entirely unusable could now enter the game’s main loop.
Practical Lessons for AI-Assisted Development
This experiment in having AI repair AI-generated code suggested four useful lessons.
Design a feedback loop instead of expecting first-attempt success.
The practical difference between the two development experiences was not simply which model was “smarter.” It also depended on whether the developer could keep supplying useful evidence of failure. Serial logs, compiler errors, and runtime screenshots all give the model concrete information to work with.Code review and code generation are different tasks.
Reviewing an existing codebase with a reasonable structure can be easier for an AI model than building a project from scratch in an unfamiliar environment. Taking over imperfect code can be a productive use of AI assistance.Observability determines iteration speed in low-level development.
In a UEFI environment without a readily availableprintf, establishing a serial logging channel should come before rushing into application logic. Without reliable execution traces, each debugging cycle becomes harder.Treat structure as useful, but verify semantics.
AI can help organize files and divide a program into modules. That does not establish the correctness of pointer lifetimes, protocol identifiers, or other low-level details. Those must be checked through actual execution.
Conclusion
The most interesting result was not which model won. It was that AI-generated code judged a failure could be recovered by changing the model and improving the feedback strategy.
The practical ceiling of LLM-assisted coding depends heavily on the developer’s ability to build a generate–validate–feedback loop. A model needs more than a prompt: it needs observable failures and repeated opportunities to test its fixes.
For teams building cloud-based AI-assisted development pipelines, connecting logging services, containerized build environments, and code hosting is a practical direction for turning that workflow into a repeatable process.
