AI Coding Assistants in UEFI Development: A Practical Retrospective

    This article reviews a real-world experiment in using AI coding assistants for UEFI firmware development, where a single bad pointer can crash the system before the OS loads. It covers a two-round workflow: first getting a legacy graphical demo to compile and run by fixing a stale pointer after mode switching and correcting a protocol GUID, then improving maintainability across error handling, input, rendering, and logging. The key takeaway is a reusable loop of code review, minimal single-issue fixes, and serial-log verification.

    1. Why Use AI in a Tough Environment Like UEFI

    In application-layer code, a compile error usually means nothing more than a type mismatch. In a firmware environment like UEFI, a single bad pointer access can terminate the program during boot, with no operating system to fall back on. Putting an AI coding tool into this scenario really tests three things: whether it can understand an unfamiliar module structure, whether it can locate problems based on runtime feedback, and whether it can debug over a serial connection without a graphical interface.

    The material in this article comes from a real relay-style development effort. One AI coding tool first attempted to build a small graphical game, leaving behind a source tree of seven files with a clear layered structure, but the environment was never brought up. A second AI coding tool then took over the “mess,” with the goal of getting it running first and optimizing later. To keep the discussion neutral, the two tools are referred to below as “AI Coding Tool A” and “AI Coding Tool B,” with the focus on method rather than product.

    2. Round One: From “Compiles” to “Runs”

    1. Review the Code First, Don’t Change It Right Away

    The first instruction when taking over a legacy project should not be “fix this for me,” but rather “review this code and list the possible problems.” The reason is that letting the model build a global understanding first and produce a structured issue list gives humans a basis for judgment, and avoids the model making sweeping changes up front that spread the problems.

    When reviewing, it helps to explicitly ask for a module-by-module breakdown—for example, checking the entry function, main loop, game logic, rendering, and input handling separately—and to require each item to be tagged with “severity + reproduction conditions + suggested fix.” This kind of prompting compresses vague answers into actionable items.

    2. Problem One: Exits on Launch, a Classic Wild Pointer

    After launch, the program printed initialization logs and then exited. After adding more detailed debug output and watching the serial console, the exception was traced to a point right after the graphics output protocol call. The root cause was that the information pointer returned by the mode query became invalid after the mode switch—that memory region had been reallocated or freed, so continuing to read it was a wild pointer access.

    The fix is very general: for any “query, then set, then use” sequence, you must re-fetch the latest information after the set completes, rather than reusing the old pointer. Illustrative code:

    1. // Wrong: reuse the info pointer obtained before SetMode
    2. info = GraphicsOutput->QueryMode(GraphicsOutput, Mode, &Size);
    3. GraphicsOutput->SetMode(GraphicsOutput, Mode);
    4. Width = info->HorizontalResolution; // info may already be invalid
    5. Height = info->VerticalResolution;
    6. // Correct: query again after SetMode
    7. GraphicsOutput->SetMode(GraphicsOutput, Mode);
    8. info = GraphicsOutput->QueryMode(GraphicsOutput, Mode, &Size);
    9. Width = info->HorizontalResolution;
    10. Height = info->VerticalResolution;

    The value of this kind of problem is that it is not a “unique defect” of any particular tool, but a very common lifecycle error in firmware development. As long as the AI has the serial log, it can reproduce the same reasoning path.

    3. Problem Two: Runs but Black Screen, Wrong Protocol GUID

    The program no longer exited, but the interface never appeared. After being given the runtime symptoms, the tool determined that the identifier configuration for the graphics output protocol was wrong: in a firmware development framework, there is more than one identifier constant related to graphics output, and using the wrong one means no usable protocol instance is obtained, showing up as “no error but no picture.”

    The practical recommendation is to manage these constants centrally in the code and explicitly validate the handle and protocol return values during initialization, turning “silent failure” into “explicit error”:

    1. Status = gBS->LocateProtocol(&gEfiGraphicsOutputProtocolGuid, NULL, (VOID **)&GraphicsOutput);
    2. if (EFI_ERROR(Status) || GraphicsOutput == NULL) {
    3. Print(L"LocateProtocol failed: %r\n", Status);
    4. return Status;
    5. }

    3. Round Two: Refinement and Maintainability

    Getting it running is only a passing grade. The second round should shift the goal to maintainability, with four recommended directions:

    • Resource and error handling: every buffer allocation needs a failure branch to avoid inconsistent state from exiting midway.
    • Input handling: key scanning should handle debounce and long-press to avoid “one press moving multiple cells.”
    • Rendering performance: reduce full-screen clearing every frame, switching to dirty rectangles or double buffering to lower flicker.
    • Observability: keep a leveled logging switch so serial output can be turned off with one action at production time.

    When issuing instructions to the AI, break “optimization” into mutually exclusive small tasks, changing only one dimension at a time and verifying immediately after each change. The success rate is clearly higher than “optimize everything for me.”

    4. A Reusable Collaboration Pattern

    This practice can be abstracted into a four-step loop: review and produce an issue list → make the minimal change to fix a single problem → verify with serial logs → move to the next round. Humans are responsible for setting goals and acceptance; the AI is responsible for enumeration and rewriting. If stronger engineering safeguards are needed, the code can be hosted on a code repository service, with a pipeline for automated builds and a logging service with monitoring alerts to collect runtime feedback. These are all general cloud capabilities, not something proprietary to any one vendor.

    5. Conclusion

    The real level of AI in a high-constraint scenario like firmware is this: it can understand structure, locate typical problems based on feedback, and push a program from “compiles” to “runs stably” within two rounds. Its shortcoming is equally clear—without runtime observability, it easily guesses in the wrong direction. Therefore, doing these three things solidly—serial logs, explicit error validation, and small-step verification—is the key to making AI coding tools truly deliver efficiency.