Using an LLM to Repair Unfinished UEFI Graphics Code: A Debugging Case Study
This case study follows an LLM as it takes over an unfinished UEFI game project, reviews seven source files, and uses serial logs to diagnose a startup failure and a blank screen. It highlights the importance of resource lifetimes, protocol identification, runtime validation, and iterative human–AI collaboration when repairing legacy code.
Using an LLM to Repair Unfinished UEFI Graphics Code: A Debugging Case Study
1. Background: Why Run This Experiment?
In an earlier comparison, I asked different next-generation large language models to build small games for a UEFI environment. The results varied considerably. One model delivered a compilable, playable brick-breaker game in just over two hours. Another spent nearly six hours without getting the build environment working, leaving behind seven source files with a modular design and an orderly structure—but no working program.
A reader pointed out that comparing models on different tasks was not entirely fair. That was a reasonable criticism, and it suggested a more useful experiment: instead of discarding the unfinished project, let another model take over and repair it.
Using AI to fix code left behind by AI could reveal more about engineering comprehension and troubleshooting than simply measuring who writes code faster. It also resembles everyday software development: engineers routinely inherit code and continue work started by someone else.
The experiment was divided into two rounds. The first aimed to get the program running; the second was intended for refinement and optimization. This account focuses on the first round.
2. Round One: From Compilation to a Working Program
Step 1: Start with a Full Code Review
The first step in taking over an unfinished project is to understand it, not immediately start changing it.
I copied all seven source files, unchanged, into a fresh build environment and gave the model a straightforward instruction: review the code and identify issues that could prevent it from running.
The model examined the entry point, main loop, game logic, rendering module, and input handling. Within a few minutes, it produced a list of problems and concluded that the program should run after those issues were fixed.
That list turned out to be incomplete. Some problems only became apparent during execution.
Problem 1: The Program Exited Immediately After Startup
On the first run, the program printed "Starting Game Loop" and then exited without an error message.
Failures like this can be difficult to diagnose in a UEFI environment. Without an operating system’s usual exception-handling and diagnostic facilities, an invalid memory access may leave little visible evidence. In this test, the failure appeared as a silent exit.
To narrow down the problem, I had the model insert serial debug output along the critical execution path. The logs placed the failure immediately after a Graphics Output Protocol (GOP) call.
Using that evidence, the model traced the problem to the handling of display-mode information:
- The code queried a display mode with
QueryModeand retained the returned information pointer. - After calling
SetModeto change the resolution, the code treated the previously obtained information as though it still described the active graphics state. - It then used that stale pointer while retrieving framebuffer information, triggering the failure.
The repair was straightforward: after SetMode completed, refresh the current mode information and obtain the framebuffer base address, width, height, and pixel format before initializing the renderer.
With that change, the program no longer exited at startup.
The broader lesson is about sequencing and resource lifetimes. In this case, querying information, changing the state, and then refreshing the information was a safer approach than continuing to rely on an earlier pointer. Code should not assume that information associated with firmware-managed resources remains valid or current after a state change.
These dependencies are easy to overlook. Once the model had serial logs, however, it could connect the failure to the relevant sequence of operations. That is where AI-assisted troubleshooting became useful: not in guessing from symptoms alone, but in reasoning from runtime evidence.
Problem 2: The Graphics Never Appeared
The startup failure was gone, but the screen remained black. The game was still not rendering.
After receiving this new observation, the model identified another issue: the GUID used to locate the graphics output protocol did not match the intended protocol interface.
UEFI uses distinct identifiers for its protocol interfaces, and confusing them can lead the code to request something other than the interface it expects. A successful LocateProtocol call does not establish that the program requested the correct protocol; it only indicates that the requested identifier was located.
In this project, the model attributed the blank screen to that mismatch. The subsequent rendering code was not operating through the intended GOP interface.
After correcting the GUID and rebuilding, the game graphics appeared and the main loop ran normally.
3. Lessons from AI-Assisted Legacy Code Repair
This experiment provided a more concrete view of what it means for an LLM to take over unfinished code.
Review before making changes.
Asking the model to read the entire project and produce an issue list helped it establish a working understanding of the code. Even though the initial review missed important problems, that context made later troubleshooting more focused.Debug output is the most useful shared language.
Rather than asking the model to speculate, provide serial logs and return codes exactly as they appear. Its diagnosis became noticeably more accurate when it had all three inputs: observed behavior, logs, and source code.Resource lifetimes deserve particular attention in firmware code.
Dangling pointers, stale buffers, and protocol-interface misuse can be especially unforgiving in a bare-metal environment. Application developers often have runtime diagnostics or operating-system protections to help expose failures; firmware development requires stricter attention to these details.Iterate toward clear acceptance criteria.
Getting the program to run and making it run well are different goals. Separate them into rounds, with explicit criteria for each. This makes human–AI collaboration easier to validate and manage than a single attempt at a complete delivery.
The project went from an unfinished, non-running codebase to a working graphical program. The model handled most of the analysis, while I supplied runtime evidence, verified the changes, and made the decisions.
That division of responsibility may be the more practical way to use AI in software development today: not as a replacement for engineering judgment, but as a collaborator that helps investigate and repair inherited code, one failure at a time.
