Measuring LLM Coding Skill in Firmware: From Broken Legacy Code to a Maintainable Build
This article reports a firmware-level experiment with large language models: taking a structurally decent but non-running graphics mini-game, then using review, logging, and staged patches to reach a runnable and more maintainable system. It covers evaluation criteria, two repair rounds, lifecycle and protocol pitfalls, and how to fold models into an auditable engineering loop.
Background: From Generating Code to Getting a System Running
In application development, large language models often produce business code. Firmware, drivers, and boot environments are harder: little reference material, weak runtime feedback, limited debugging, and a single mistake can blank the screen or reboot. That makes low-level work a useful test of overall skill—not only writing code, but reading interface lifecycles, analyzing logs, spotting protocol misuse, and converging to a runnable state with sparse feedback.
In an internal trial, two general-purpose models were asked to complete a simple graphics mini-game in a firmware environment. Results differed: one produced a compilable first-run version relatively quickly; the other took longer and left a well-structured, modular project that still would not run. A fair objection followed: the tasks were not the same, so a direct comparison is unfair. Hardware abstraction, graphics APIs, input, and log visibility all vary; elapsed time alone proves little.
A more useful question is not a brand contest but a general engineering one: given leftover code that looks structured but will not run, can a model use review, log analysis, and stepwise repair to move the system from non-running to running, then to maintainable? That closer to real development. Testing used two rounds: first get a basic run; then polish and engineer the project.
Evaluation Criteria: Do Not Judge Speed Alone
Assess coding ability on several dimensions at once:
- Buildability: the code compiles under the given toolchain and constraints, not merely looks correct.
- Bootability: a cold start reaches the main flow and does not exit immediately after init.
- Functional completeness: core interaction works—input, render, and state update form a loop.
- Stability: bounds, error returns, and resource release are handled; no garbage display, overflows, or infinite loops.
- Maintainability: clear module boundaries, explicit contracts, logs and error codes that support later diagnosis.
- Iteration cost: how many feedback rounds a fix takes, and whether the model finds root causes in logs instead of guessing.
- Human review cost: whether the output is easy to review and whether it hides low-level risk.
Bootability and iteration cost are easy to miss. Application bugs often come with stacks, exceptions, and mature logging. Firmware may offer only a serial line, or nothing. Whether the model suggests logging, narrows the search, and designs a minimal check then matters more than dumping a large first draft.
Round One: Take Over Legacy Code—Review Before Changing
The non-running project was moved unchanged. The first instruction was not “fix it,” but:
Review this code. Find issues that could prevent boot, fail graphics init, or break the main loop. List them by risk, and state how to verify each.
That order matters. Immediate large rewrites can hide the real bug. Review first builds a global picture and lets humans judge whether the model understood module relationships.
The model walked entry, graphics init, main loop, render, input, and exit, and reported:
- Lifecycle errors in init order: querying display mode, setting mode, and fetching framebuffer info are ordered; the code reused stale info after set mode.
- Protocol GUID/identifier mismatch risk: similar interfaces exist; the wrong ID fails lookup, and error paths were incomplete.
- Insufficient logs: init failure exited with no stage markers or error codes, so protocol, mode set, and draw could not be distinguished.
- Weak framebuffer checks: pixel format, stride, and resolution were not validated, risking out-of-bounds draws or bad display.
- Weak input and loop bounds: exit conditions, debounce, and throttling were incomplete.
- Reasonable modules but unclear contracts: raw pointers and implicit state between modules raised later change risk.
The list was not guaranteed complete, but it shrank the search from the whole tree to a few high-probability areas and cut human exploration cost.
3.1 Reproducing the Symptom: Startup Logs, Then Immediate Exit
The first run did not crash at once. A log similar to “Starting Game Loop” appeared, then the program exited. Better than a total failure, but not a stable loop.
The model was asked to add staged debug: status codes and key pointers before/after protocol get, after mode query, after mode set, after framebuffer get, and around the first draw—and to test one hypothesis at a time.
That exposed the first root cause: after a mode switch, previously queried display info can become invalid, but the code still used the old reference. Query mode, set mode, and get framebuffer are not a simple linear chain. Set mode can change display state; current mode and framebuffer must be queried again. Otherwise calls may “succeed” while later access fails.
Repair intent (abstract names; the point is lifecycle order):
// Pseudocode: re-query current display info after mode switchdisplay_t init_display(gfx_protocol_t *gfx) {display_t d = {0};mode_info_t *old_info = query_mode(gfx);if (!old_info) {log_error("query mode failed");return d;}if (set_mode(gfx, choose_mode(old_info)) != STATUS_OK) {log_error("set mode failed");return d;}// Critical: do not reuse old_info from before the switchmode_info_t *cur = query_current_mode(gfx);if (!cur) {log_error("query current mode failed");return d;}d.info = cur;d.fb = get_frame_buffer(cur);if (!d.fb) {log_error("get frame buffer failed");return d;}d.width = get_width(cur);d.height = get_height(cur);d.stride = get_stride(cur);d.format = get_pixel_format(cur);return d;}
After the fix, the program no longer flashed off. This is a resource-lifetime issue, not a syntax error. Completing code is not enough; runtime behavior plus interface semantics are required to see a stale reference.
3.2 No Graphics: Wrong Protocol Identifier
Once the main loop ran, the UI still did not show. After feeding run results, logs, and key state back, the model suggested checking graphics-output protocol acquisition.
Firmware often has several similarly named, differently used interface IDs. The wrong ID fails protocol get. If return values are ignored, empty or uninitialized interfaces are called: the program “runs,” the screen stays blank.
Repair in three steps:
- Centralize protocol identifiers; avoid scattered hardcodes.
- Check the return immediately after get, with contextual errors.
- Validate version or capability so the environment actually supports the needed output.
Graphics then appeared; basic render and the loop ran. Round one targeted “it runs”: build, boot, display, exit, and locatable logs—not elegance.
Round Two: From Runnable to Usable—Polish Is the Real Work
Generated code often “demos” but is far from production. Round two targeted stability, maintainability, and testability.
4.1 Framebuffer and Pixel-Format Checks
Do not assume resolution, stride, or pixel layout. Record and validate width, height, stride, bits per pixel, and color format at init. Clip rectangles in draw paths to avoid out-of-bounds writes.
Dirty-rect refresh redraws only changed regions and is often more useful on constrained hardware than fancy effects. Double buffering or a back buffer can reduce tearing if memory allows; if not, keep a stable single-frame draw order.
4.2 Input and Main-Loop Throttling
Map keys, debounce, and detect edges. Do not busy-wait; throttle with platform clocks or timers, and define a clear exit. Prefer deterministic state: the same input sequence yields the same game state for replay and tests.
4.3 Errors and Resource Lifetime
Every fallible init step should return a clear status; on failure, release what was acquired; on exit, tear down in reverse order. Logs should include stage, error code, and key parameters without dumping sensitive data. Models often complete the happy path and leave error paths thin; prompt them to fill those in.
4.4 Module Boundaries and Testability
Legacy code was modular but contracts were vague. Decouple game-state updates, collision, render, and input. Pure logic can run off-hardware with fixed input sequences; hardware pieces sit behind abstract interfaces for simulators or other boards.
A reusable prompt pattern:
Context: firmware graphics app exits after init; logs are as follows...Goal: locate the lifecycle issue first, then a minimal patch.Constraints: do not rewrite all modules; verify one hypothesis at a time; keep existing interface style.Output: 1) hypotheses and priority; 2) minimal change; 3) rationale; 4) verification steps; 5) regression risks.
What Actually Matters in Low-Level Work
What stood out was not generation speed, but:
- Multi-file context: relating entry, render, input, and protocol wrappers.
- Log-driven debug: suggesting staged logs from symptoms and narrowing scope.
- Inferring specs and semantics: init order, lifetime, and return checks.
- Stepwise repair: small patches around one hypothesis after human feedback, not endless rewrites.
- Engineering communication: issue lists, verification steps, and risk notes for a team.
Limits remain: a model is not a debugger and does not replace hardware validation. Advice can look sound and still miss platform constraints. Registers, memory maps, boot paths, and safety-critical code need human review and real-environment tests.
Landing This in Enterprise: An Auditable Loop
To use this in product work:
- Pin the toolchain and runtime so builds reproduce.
- Give the model full error logs, a minimal repro, and interface constraints.
- Require an issue list and verification plan before patches.
- After each change: build, static checks, simulator tests, and hardware tests as needed.
- Human-review low-level writes, memory access, and exception paths.
- Turn fixed bugs into regression tests.
At scale, general compute, object storage, logging, and monitoring (for example from Baidu AI Cloud) can host isolated build, regression, and audit pipelines; design still depends on security, cost, and compliance.
Conclusion
Moving leftover firmware from broken to runnable showed that low-level value is not “perfect code in one shot.” With clear acceptance criteria, models help with review, hypotheses, logs, and staged repair. Round one answers “can it run”; round two answers “can it be maintained.” Both are required.
Treat the model as a collaborator that needs strict context: constraints, feedback, verification, and a bounded change set. What teams reuse is not a single generation, but a loop: review, instrument, patch, verify, polish. Only inside a testable, auditable process does code generation become stable productivity rather than a demo.
