AI-Assisted UEFI Legacy Project Repair: Two Test Rounds and Troubleshooting Notes

    This article reports a two-round experiment using AI coding tools to repair a half-finished UEFI graphics project built on EDK2. It covers static code review, an immediate startup exit, GOP protocol acquisition failure, collision and input issues, plus practical troubleshooting checklists and limitations observed in long AI-assisted sessions.

    An Experiment in AI-Assisted Repair of a Legacy Project

    Large language models are already everyday tools for many developers. Most demonstrations, however, stop at generating a code snippet or solving an algorithm problem. Real engineering work more often involves legacy code and half-finished projects. This article describes two rounds of testing with a UEFI graphics program, records how AI tools performed in code review, runtime troubleshooting, and feature refinement, and summarizes a troubleshooting sequence that can be reused directly.

    Experiment Background and Scope

    The experiment compared two intelligent coding tools. The first completed a Breakout game in about 2.5 hours; it compiled on the first attempt and ran successfully on the first run. The second spent nearly 6 hours writing a Tetris game but did not produce a runnable environment. It did leave behind seven source files with a complete structure and modular separation.

    The author then asked the better-performing tool to take over the half-finished project left by the second tool. This is closer to real work than generating a project from scratch, because developers more often face code written by someone else.

    It should be noted that the time figures come from a single experiment by the author, without repeated tests or a strict control group. The project was built on the EDK2 framework, and all code files were imported into the new environment as-is, with no manual preprocessing. The specific EDK2 version, compiler, and firmware environment were not recorded, so readers who reproduce the experiment need to align those details themselves.

    Round 1: Getting the Program to Run

    The first instruction was simple: “Review this code and identify possible issues.” The tool checked the entry function, main loop, game logic, rendering module, and input handling one by one, and produced a list of issues. It pointed out that the entry function lacked initialization error handling, the main loop had an out-of-bounds access risk, the framebuffer pointer in the rendering module needed validation, and input handling did not account for special cases in non-blocking polling. These were candidate issues to be confirmed through runtime testing.

    The Program Exits Immediately After Startup. How Should It Be Investigated?

    After startup, the command line printed a single line, “Starting Game Loop,” and then the process exited directly. There was no crash message, but this was clearly not the normal flow.

    The author asked the tool to add debug output and observe execution progress through the serial port. The logs showed that the exception occurred after calling GOP (Graphics Output Protocol). After analysis, the tool concluded that the mode information pointer returned by QueryMode might already be invalid after SetMode was called, while later code was still using that old data.

    The fix was to reacquire the mode information after calling SetMode, read Mode->Info, and validate the pointer and SizeOfInfo. The old Info should not be reused across SetMode. After the change, the program no longer crashed immediately.

    GOP Protocol Acquisition Failure. How Should It Be Troubleshot?

    The program could now run stably, but there was no graphics output on the screen. The author fed the runtime result back to the tool. It checked the GOP protocol acquisition logic and found that the GUID constant used in the code did not match the specification.

    The GOP GUID is a fixed identifier defined by the UEFI specification, corresponding to gEfiGraphicsOutputProtocolGuid in EDK2. It does not switch with phase or version. After replacing it with the correct constant, recompiling, and running again, the display finally appeared.

    One troubleshooting habit is worth keeping here: when protocol acquisition fails, the function usually returns EFI_NOT_FOUND or EFI_UNSUPPORTED. You should print Status and check the header files and EDK2 version, rather than assuming a valid pointer was obtained and then accessing its fields.

    By the end of the first round, the program had gone from “unable to run” to “runnable but with a poor experience.” In this round, the tool was able to review static code and also infer causes from runtime logs.

    Round 2: Functional Refinement

    Being runnable is only the starting point. The game still needs correct mechanics and smooth input. The second round focused on three areas: block rotation logic, line-clear judgment and collision detection; keyboard input responsiveness; and color and refresh effects.

    After feedback that “blocks occasionally pass through fixed blocks while falling,” the tool first checked whether there were boundary issues in the coordinate transformations used for collision detection, then located the specific function and modified it directly. This shows that when the problem description is specific enough, the tool can narrow down the scope quickly.

    This round also exposed shortcomings. After many consecutive iterations, the tool occasionally forgot previous changes, causing conflicts between old and new code. This happened more often in long conversations and when multiple files were modified at the same time. Mitigation methods include asking the tool to list the changes made in each round, manually reviewing the diff, and, when necessary, starting a new session with a summary of the current design decisions.

    Capability Observations: Where AI Helps and Where to Watch Closely

    Three types of performance in this experiment are worth recording.

    First, cross-file understanding. The tool could quickly sort out the call relationships among the seven source files and use that understanding for review.

    Second, log-based localization. The more specific the logs, the faster the localization. With only “Starting Game Loop,” the tool could not determine the problem; serial debugging information had to be added first.

    Third, error correction within the same round. In this session, the tool avoided several repeated error patterns, but this ability was unstable. You cannot expect it to remain consistent throughout a long session.

    The shortcomings are also clear. The tool’s understanding of cases where hardware resources are still referenced after release was not stable enough, so memory lifetime needs manual review. Context consistency across multiple rounds also needs improvement. For frameworks such as UEFI that have less documentation, humans need to provide specifications or header file contents before the tool can judge protocol behavior more accurately.

    Practical Recommendations

    • Describe the problem at the function or module level. For example, “fix the coordinate out-of-bounds issue in a certain function” is more effective than “make the program better.”
    • Provide logs with status codes and key variable values, rather than just saying “the program exited.”
    • Handle only one or two issues per round, and proceed to the next round after verification passes.
    • In long sessions, remind the tool from time to time about modifications it made earlier.
    • Manually review generated code. For low-level UEFI code, check the following items one by one:
    1. Whether EFI_STATUS is checked after every protocol or service call.
    2. Whether old pointers and old mode information are still valid after calling interfaces such as SetMode.
    3. Whether GUID constants match the EDK2 header files in use.
    4. Whether loops have exit conditions and bounds checks.
    5. Whether input polling has timeout or non-blocking handling.
    6. Whether the framebuffer size and pixel format (PixelFormat) match.

    Firmware and display-related code can cause a device to have no display when misconfigured, and recovery may require a serial port, an alternate boot method, or reflashing. It is recommended to validate in a virtual machine such as QEMU first, and to keep recovery options available before testing on real hardware.

    Outlook

    In this experiment, code review, issue localization, repair, and verification formed a closed loop, but this occurred in only one project and one experiment. To show that this capability is general, it still needs to be repeated across more projects and more models.

    For developers, AI tools are suitable for taking on repetitive and tedious troubleshooting work. Architecture design, requirement tradeoffs, and final correctness judgment still need to be handled by humans.