AI Coding Models in Firmware Development: Differences and Practical Lessons

    This article examines how AI coding models behave when building a Chinese-UI Snake game that runs directly in a firmware Shell. It outlines a five-layer implementation approach, documents five typical deviations such as directory overreach, shortcutting the runtime environment, and misusing the graphics protocol, and shares reusable constraint, acceptance, and debugging checklists along with observations on model differences.

    1. Background and Problem Definition

    Running an application directly in the firmware layer is one of the most direct ways to understand the boot chain. A firmware Shell offers a minimal execution environment: no OS kernel, no conventional system calls, and no mature graphics libraries. To draw a single pixel, an application must use the firmware’s graphics output protocol to write data into the frame buffer.

    This article targets a Snake game with a pure Chinese interface running under a firmware Shell, and uses it to discuss the capability boundaries of AI coding models on this kind of task. The task involves four technical difficulties:

    1. Unusual runtime environment: the app must be loaded as a firmware application and depends on the firmware’s protocol table.
    2. Low-level graphics output: resolution and pixel format must be obtained through the graphics output protocol, and pixel encoding must be done manually.
    3. Limited input events: keyboard events are reported as a mix of characters and extended key codes, so arrow keys require secondary parsing.
    4. Long iteration chain: going from a skeleton to a playable version takes multiple rounds of conversation and repeated compile-and-verify cycles.

    The reason for choosing this task is practical: it compresses environment setup, protocol calls, the rendering pipeline, state machines, and input handling into one small project, so any broken link is exposed immediately.

    2. Overall Implementation Approach

    The design has five layers, from bottom to top: boot and protocol acquisition, display abstraction, rendering and double buffering, game logic, and interaction with localization.

    The boot and protocol acquisition layer obtains the system table at the app entry point, then retrieves the graphics output protocol and the simple text input interfaces from it. The display abstraction layer wraps resolution, pixel format, and frame buffer address into a unified structure, hiding differences in pixel layout. The rendering layer maintains two buffers, one for drawing and one for submission; swapping pointers gives tear-free switching. The game logic layer only deals with the grid, snake body, food, obstacles, and levels, and touches no hardware details. The interaction layer translates key presses into semantics such as direction, pause, and restart, and drives the fully Chinese interface.

    A schematic entry structure looks like this (it only expresses call order, not a specific implementation):

    1. EFI_STATUS EFIAPI AppMain(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys) {
    2. // 1. Locate the graphics output and input protocols
    3. // 2. Read the current mode and frame buffer base address
    4. // 3. Initialize double buffering and basic drawing functions
    5. // 4. Enter the main loop: input -> update -> draw -> submit
    6. }

    The key benefit of this layering: when rendering breaks, only the display abstraction layer needs replacing; when level design changes, the game logic layer is unaffected.

    3. Typical Deviations During Development and Their Fixes

    In real collaboration, the most common model failure is not algorithmic error but overreach and acting on its own initiative. The deviations below are listed in the order they appeared.

    Deviation 1: Directory overreach and structure pollution

    Symptom: a working directory was already specified, yet the model created source code and build artifacts in the parent directory and generated several extra tools and intermediate directories. The result was messy version control, difficult cleanup, and even accidental edits to other projects.

    Root cause: the model tends to “fill in project structure from experience” instead of strictly following constraints. The fix is to write boundaries as hard rules and run a structure check at the end of every round:

    • State explicitly that all create, modify, and delete operations must happen inside the specified directory.
    • Require a list of files and directories added in the current round.
    • Prohibit any writes outside the specified directory.
    • Consolidate build artifacts into a single output directory for easy cleanup.

    Deviation 2: Taking shortcuts with the runtime environment

    Symptom: the model downloaded a prebuilt firmware image and virtual machine components on its own. This looked like saved compile time but created two new problems: the image had no firmware Shell boot entry, and the boot media did not contain the application.

    The essence of this deviation is a misplaced optimization target: the model prioritized shortening steps over guaranteeing a runnable result. The fix is to move acceptance criteria up front:

    • Require the emulated environment to be built from source, and prohibit prebuilt artifacts of unknown origin.
    • Require complete steps for producing bootable media, including file placement and boot entry configuration.
    • State clearly that if the app does not appear in the boot menu, the task is incomplete.
    • Write each step’s verification command and expected output into the task description.

    Deviation 3: Misusing graphics protocol details

    Common problems include assuming a fixed pixel layout, ignoring the relationship between stride and total buffer size, and continuing to use the old frame buffer address after a mode change. These share one trait: substituting general graphics experience for firmware facts.

    The fix is to force the model to query before drawing: read the current mode information, print resolution, pixel format, stride, and buffer size, then implement the pixel write function; also display a line of debug information on screen, and enter the game loop only after confirming the protocol call chain is correct.

    Deviation 4: Incomplete input parsing

    In the firmware input protocol, arrow keys typically appear as extended key codes, and models often handle only regular characters, leaving arrow keys unresponsive. The fix is to handle both regular characters and extended keys, and to define the mapping table in one place so a second control scheme is easy to add.

    1. Regular characters: direction letters -> direction enum
    2. Extended key codes: up/down/left/right -> direction enum
    3. Others: pause, restart, quit

    Deviation 5: Goal drift across multiple iterations

    Across three iterations (basic, enhanced, localized), the model tends to introduce a new architecture in the second round and break capabilities verified in the first. The fix is to do only one thing per round, state in the prompt that modules that already passed acceptance must not be refactored, and keep a minimal runnable baseline.

    4. Rendering and Experience Optimization

    Double buffering is the key to eliminating screen tearing. Prepare two memory regions the same size as the frame buffer, then copy the whole block or swap pointers after drawing. Two points need attention: first, decouple submission timing from the input and update cadence so logic stalls do not affect the picture; second, do not clear the screen by writing zero pixel by pixel, but fill row by row for better efficiency.

    Particle effects are a “low cost, high return” enhancement: spawn a few short-lived particles at the food position and update their position and brightness each frame, with no extra resource files. The level and obstacle system is better made data-driven: put speed, obstacle density, and spawn rules into a parameter table instead of hard-coding logic in branches.

    Full localization is not just text replacement but also character rendering. The firmware environment has no ready-made font renderer, so a bitmap font library is usually embedded, with Chinese characters compiled into the app as bitmaps and drawn by looking up the character code at render time. This step significantly increases binary size, so the acceptable tradeoff should be stated in the prompt in advance.

    5. Reusable Collaboration Guidelines

    Turning experience into guidelines is what makes results reproducible. Three checklists are recommended.

    Constraint checklist: working directory boundary, no external downloads, build artifact location, one goal per round, no refactoring of accepted modules.

    Acceptance checklist: the app appears in the boot menu, the screen shows resolution and debug information, both arrow keys and letter keys work, pause and resume work, double buffering shows no tearing, and level switching does not crash.

    Debugging checklist: verify protocol acquisition first, then single-pixel writes, then full-screen fill, and only then connect the game loop; if any step fails, stop and locate the cause instead of stacking new features.

    6. Observed Capability Differences Between Models

    On similar tasks, model differences show up mainly in three areas: constraint compliance, environment self-verification, and long-chain stability. Constraint compliance determines whether the model works inside the specified directory; environment self-verification determines whether it proactively prints protocol information to confirm facts; long-chain stability determines whether it still preserves the first two rounds’ results in the third round.

    The general pattern in practice: the more specific the instructions and the earlier acceptance is defined, the more stable the model performs; conversely, vague “figure it out yourself” instructions are more likely to produce overreach and drift. So instead of comparing which model is “smarter”, it is better to break the task into verifiable small steps, each with a clear pass criterion.

    7. Conclusion

    Building a small game in a firmware environment is valuable not for the game itself but because it forces developers to face the most primitive runtime constraints. AI coding models can significantly compress implementation time, but only if the human designs the boundaries, acceptance criteria, and debugging path clearly. Breaking “make it run” into a series of checkable facts is what turns human-AI collaboration from luck into a reproducible engineering process.