Evaluating LLM-Assisted Firmware Development: From Code Review to Runtime Verification

    This article examines how large language models can assist low-level firmware development, arguing that evaluation should shift from code generation speed to problem-solving capability. It introduces a systematic workflow for debugging firmware graphics programs, covering runtime environment constraints, establishing minimal runnable loops, diagnosing common failures, and refining code for maintainability. The key principle: reliable AI-assisted development requires a traceable engineering loop where every modification is backed by verifiable runtime evidence.

    Evaluating LLM Capability: From Code Generation to Problem Solving

    When discussing the programming ability of large language models, the most immediately observable metric is code generation speed—how quickly the model can scaffold a directory structure, decompose functional modules, and fill in key functions. However, there remains a significant gap between code that looks complete and a program that actually runs reliably.

    This gap is especially pronounced in low-level development. A program may compile successfully, yet exit immediately after initialization. It may enter the main loop, but nothing appears on screen. Logs may show every step executing, while the program is actually accessing a stale pointer or an incorrect memory region.

    Therefore, the more valuable questions are not “how much code can an LLM write in one pass,” but rather:

    • Can it understand the execution paths and constraints of an existing codebase?
    • Can it distinguish between build failure, initialization failure, and runtime exceptions?
    • Can it propose testable fault hypotheses based on log output?
    • Can it complete regression testing after modifying code, rather than merely claiming the issue is resolved?
    • Can it clearly articulate the parts where evidence is insufficient and the remaining risks?

    A graphics-oriented game running in a firmware environment is a suitable scenario for observing these capabilities. The game logic itself is easy to understand, but graphics output, input polling, timing control, and resource management are all constrained by the runtime environment. This scenario tests both the model’s handling of business logic and its understanding of low-level interfaces and state transitions.

    Why Firmware Graphics Programs Expose Problems More Readily Than Ordinary Applications

    1. Different Runtime Infrastructure

    Ordinary applications can typically rely on the operating system for window management, input events, process scheduling, and comprehensive diagnostic mechanisms. Firmware applications face a different set of conditions: the program must obtain graphics output capabilities through firmware services, handle keyboard input, and manage associated resources.

    This does not mean firmware environments completely lack memory allocation or basic services—rather, it means that the dependencies, interface behaviors, and debugging approaches assumed in desktop applications do not automatically apply.

    If an AI-assisted tool fails to explicitly recognize this boundary, it may generate implementations that are logically sound but environmentally invalid—for example, referencing runtime libraries not provided by the current build environment, or declaring the entry function with the wrong calling convention.

    2. Graphics Output Is Not Simply Writing Pixels

    Before directly manipulating the frame buffer, a program must confirm the current graphics mode and its parameters, including resolution, pixel format, bytes per scan line, and buffer range.

    The bytes per scan line does not always equal the visible width. If the offset is calculated as “screen width multiplied by Y coordinate,” image misalignment can occur in certain modes.

    Similarly, one cannot assume that all graphics modes support direct frame buffer writes in a uniform format. The program should check mode capabilities first, then decide between direct writes or firmware-provided graphics operations.

    3. Successful Initialization Does Not Guarantee the Persistence of State

    Information returned by low-level interfaces often carries lifecycle and ownership constraints. A pointer may be valid at one stage but unsuitable for continued use after a state transition.

    Two distinct issues need to be separated:

    First, whether the memory is still valid; second, whether the information it describes still corresponds to the current state. Even if a queried memory block has not been freed, it may describe a previously queried mode rather than the currently active mode after a switch.

    Issues like this are often loosely attributed to “dangling pointers,” but an accurate diagnosis must go further—examining the interface contract, deallocation location, caching strategy, and state changes—rather than jumping to conclusions from surface symptoms.

    Taking Over Existing Code: Restore the Execution Path First, Then Modify

    When faced with a project that has already been split into multiple modules but never runs successfully, the safest approach is not to immediately rewrite it, but to first establish an overall model of how it works.

    1. List Modules and External Dependencies

    The project can be divided into the following parts:

    Module Primary Responsibility Priority Check Items
    Program entry Establish initial state, control exit path Calling convention, return values, failure branches
    Graphics initialization Locate protocol, select mode Protocol identifier, status codes, mode capabilities
    Rendering module Draw background, blocks, and text Pixel format, stride, bounds checking
    Input module Read and interpret key presses Blocking behavior, no-input state
    Game logic Movement, rotation, collision, line clearing Coordinate ranges, state consistency
    Main loop Coordinate input, update, and render Timing control, exit conditions
    Cleanup module Release resources and restore necessary state Ownership, double-free, missing free

    The module breakdown is only an analysis entry point—it does not constitute evidence of correctness. What actually needs to be traced is: what the entry point calls, where it jumps on failure, which objects are preserved across stages, and under what conditions the main loop terminates.

    2. Turn Review Conclusions into Testable Hypotheses

    High-quality code review should not merely offer suggestions like “optimize initialization” or “fix graphics issues.” It should include:

    • Specific suspicious locations;
    • Conditions that could trigger the error;
    • Expected observable symptoms;
    • Minimal verification methods;
    • Behaviors to check after the modification.

    For example, “the drawing parameters from the old mode are still used after a mode switch” is a testable hypothesis. One can record the mode number, resolution, stride, and buffer information before and after the switch, then check which data set the drawing module actually uses.

    By contrast, “the graphics module might have issues” provides no actionable direction.

    Establish a Minimal Running Loop Instead of Fixing Everything at Once

    When debugging a complex project, the first goal should be to compress the scope. The first phase does not require a complete game—it only needs to prove that the critical dependencies hold in sequence:

    Program enters entry point → Successfully acquires graphics capability → Displays a recognizable pattern → Reads one input → Exits cleanly.

    This closed loop significantly narrows the fault domain. If a basic rectangle cannot be displayed, there is no point in prioritizing the block rotation algorithm. If the program has not entered the main loop, there is no need to adjust the falling speed.

    It is recommended to proceed in the following order:

    1. Confirm the project builds in a reproducible environment;
    2. Confirm the target entry point is actually executed;
    3. Confirm the graphics protocol can be located;
    4. Confirm the current mode parameters are trustworthy;
    5. Draw a solid background or fixed rectangle;
    6. Verify input and exit;
    7. Finally, reconnect the game state and rendering logic.

    After each step, preserve verifiable runtime evidence. This way, even if a later modification introduces a problem, you can fall back to a known-good state.

    Two Typical Faults: Sudden Exit and No Display

    1. Sudden Exit After Initialization: Distinguish Normal Return from Abnormal Termination

    The screen printing “entering loop” and then going blank does not by itself prove a memory anomaly. Other possible causes include returning through an error branch, an incorrect initial value for the exit condition, or input handling treating a normal state as a termination signal.

    Therefore, the following should be recorded at critical boundaries:

    • The operation about to be invoked;
    • The state after the invocation completes;
    • Whether key pointers are null;
    • The current loop and exit flags;
    • The final return path.

    Serial port logs are valuable in this scenario because they do not rely on the graphics module itself working correctly. However, logs should be organized around state transitions, avoiding high-frequency output per frame that could alter program timing and mask the original problem.

    2. Data Usage After Mode Switch: Check Both Ownership and Timeliness

    When handling graphics modes, one must clearly distinguish between query results and the currently active state.

    Data returned by a query interface may require the caller to release it per convention; the current mode description is maintained by the protocol object. The two must not be conflated in ownership or usage.

    A safe flow can be summarized with the following pseudocode:

    1. Locate the graphics protocol
    2. Check the location result
    3. Query the target mode
    4. Check whether the mode satisfies drawing requirements
    5. Release the query result per interface convention
    6. Switch to the target mode
    7. Check the switch result
    8. Read the current active mode information
    9. Check resolution, pixel format, scan line stride, and buffer range
    10. Initialize the drawing context

    The key principle is not mechanically “re-fetching the pointer after a switch,” but ensuring that the data used for drawing is both valid and consistent with the currently active mode.

    3. Program Still Running but No Picture: Check Protocol and Drawing Chain

    A protocol is typically located via a globally unique identifier. Related identifiers may have similar names, but the “protocol identifier used to obtain the interface” and other related identifiers are not the same concept.

    If the identifier is wrong, protocol location usually fails first. The return status must therefore be checked—an invalid interface pointer must not continue into the drawing logic.

    If location succeeds, further checks are still needed:

    • Whether the expected output device was selected;
    • Whether the current mode supports the drawing path being used;
    • Whether the drawing coordinates are within the visible screen;
    • Whether the foreground and background colors are distinguishable;
    • Whether the frame is subsequently cleared, covering the rendered content;
    • Whether the pixel format matches the write method.

    “No picture” is just a symptom—it cannot be automatically attributed to a single protocol identifier.

    Phase Two Refinement: From “It Runs” to “It Is Maintainable”

    1. Separate Game State from Drawing Code

    The board, active piece, score, and game-over flag should be maintained by the logic layer. The rendering layer should only read state and must not implicitly advance the game during drawing.

    This separation allows collision, rotation, and line-clearing rules to be verified independently of the graphics environment, lowering debugging costs.

    2. Distinguish Input Polling Rate, Update Rate, and Render Rate

    Simply waiting a fixed duration after each loop iteration is easy to implement but can couple input responsiveness to the block’s falling speed.

    A better approach is to advance state based on time deltas: input can be polled more frequently, blocks fall at configured intervals, and rendering occurs when state changes or a refresh condition is met.

    The specific time source and wait method must be determined by what the environment supports—do not assume the same timing capabilities as a desktop system.

    3. Define Boundary Rules Explicitly

    At a minimum, the following scenarios should be covered: left/right movement out of bounds, bottom collision, rotation overlap, consecutive line clears, spawn position occupied, and resource cleanup on exit.

    These rules should have defined inputs and expected outputs, not be judged by manual play-testing alone. For game logic, small-scale, repeatable state tests are generally more effective at locating errors than prolonged blind testing.

    4. Keep Modifications Revertible

    Each round of changes should focus on a single fault. If input, rendering, and the main loop are all restructured at once, it becomes impossible to tell which change actually fixed the program—even if it starts running again.

    A stable working rhythm is:

    Form hypothesis → Minimal change → Build check → Runtime verification → Regression test → Record results.

    How to Objectively Assess the Development Value of LLMs

    Time spent on different tasks cannot be directly used as a capability ranking. Existing code quality, build conditions, interaction count, human prompting level, and success criteria all influence the final result.

    What is more informative is observing the complete process under comparable constraints:

    • Whether the first build succeeds;
    • How far the first run reaches;
    • Whether fault diagnosis is supported by logs;
    • Whether the fix addresses the root cause;
    • Whether new regressions are introduced;
    • Which critical decisions were taken over by humans;
    • Whether the final result can be reproduced.

    In particular, one must distinguish between “the model claims it fixed the issue” and “runtime evidence shows it was fixed.” Without actual execution conditions, conclusions should be labeled as static analysis judgments, not verified facts.

    Conclusion: The Real Value Lies in a Traceable Engineering Loop

    The value of LLM-assisted low-level development is not in producing more files that look well-structured, but in helping developers organize execution paths, propose fault hypotheses, design verification steps, and progressively narrow down the problem space.

    At the same time, interface semantics, memory ownership, and environment constraints still require careful verification. Explanations offered by the model can serve as debugging leads, but they cannot replace runtime evidence.

    Reliable AI-assisted programming ultimately comes down to a traceable chain: requirements have boundaries, modifications have reasons, logs can locate problems, tests are reproducible, and conclusions match the evidence. Only then does “generated code” truly become “delivered, working software.”