AI Coding on Bare Metal: Lessons from Building a UEFI Graphics Application
This article reviews an experiment in AI-assisted programming on bare metal, using a graphical Breakout game running under the UEFI Shell with Chinese text rendering as the target. It explains how the absence of an operating system, standard libraries, and debugging tools changes the development process, describes the staged approach from a minimal buildable version to rendering and text display, and summarizes reusable collaboration practices such as context-first prompting, small verifiable milestones, deterministic constraints, and cost-aware model selection. Readers will gain insight into where general-purpose models struggle at the low level and how workflow design, context quality, and verification mechanisms determine the outcome.
1. Why Run AI Coding Experiments on Bare Metal
Most discussions about AI coding focus on web, mobile, or desktop applications. These environments offer mature frameworks, abundant examples, and debugging tools that are always within reach. Bare metal is the opposite: there is no OS scheduler, no ready-made graphics library, and no standard input or output. Even printing a single log line has to be implemented from scratch. Testing AI coding in such an environment exposes its capability boundaries and collaboration patterns more honestly.
The experiment described here had a concrete goal: run a graphical Breakout game under the Extensible Firmware Interface (UEFI) Shell with support for Chinese text display. The constraints were strict: the local codebase started empty, the developer wrote no business code, and only the target description plus necessary domain knowledge were provided, with the AI coding tool completing the entire implementation autonomously.
Breakout was not chosen at random. The program is moderate in size yet covers five core areas: graphics rendering, user input, collision detection, state management, and resource management. That makes it a classic benchmark for programming ability. In earlier experiments on web and mobile platforms, the main difficulty was interaction design. On bare metal, the difficulty shifts to the missing supporting system itself.
2. How Bare Metal Programming Differs from Conventional Development
Understanding these differences is a prerequisite for writing good prompts.
- No runtime: there is no default implementation of processes, threads, or a heap manager; memory allocation must be routed to the allocator provided by the firmware.
- No standard library: string handling, formatted output, and math operations must be explicitly imported or implemented by hand.
- A special input path: mapping keyboard scan codes to characters, tracking modifier key state, and handling key repeat all require manual work.
- Limited display capability: typically only a simple frame buffer or the Graphics Output Protocol is available, so drawing a line means computing pixels yourself.
- Scarce debugging options: without a graphical debugger, the only options are screen output, serial logs, or the breakpoint mechanism built into the firmware.
These constraints mean that an AI relying only on general-purpose training data will easily produce code that looks correct but does not run. So the first phase of the experiment was not writing code, but filling in the context.
3. Experiment Design and Ground Rules
To keep the conclusions reproducible, the rules had to be strict:
- The development environment kept only a basic integrated development environment, with no additional third-party libraries installed.
- The initial code volume was zero, and no human intervention in business logic was allowed.
- No expert-level line-by-line guidance was given, only the goal, the constraints, and staged acceptance criteria.
- All output had to build and run for real in the target environment.
On model selection, a general-purpose large model with fast responses and clear reasoning worked well early on, but pay-as-you-go billing made it expensive for everyday development. An analogy helps here: a high-performance sports car is impressive, but what most people actually need is an economical family car. The experiment ultimately used a model from a cloud vendor’s coding package, which validated the selection principle of “good enough and sustainable.”
4. Staged Progress: From Compiling to Displaying
Phase 1: Feature enhancement. The first step was to get a minimal closed loop working: initialize graphics output, clear the screen, draw one rectangle, and respond to the exit key. The main problem at this stage was over-engineering, with the AI introducing a large number of abstraction layers at once. The fix was to state explicitly in the prompt: “build a runnable minimal version first, and do not reserve unused abstractions.”
Phase 2: Visual refinement. This phase added borders, a color scheme, sprite drawing for the paddle and the ball, and score display. The work required translating visual requirements into coordinate and pixel arithmetic, so the prompt had to supply concrete parameters such as screen resolution, color format, and the coordinate origin.
Phase 3: The display challenge. Chinese text rendering was the hardest part. The general approach is to embed a bitmap font: extract only the Chinese characters that are needed, generate bitmap arrays, compile them into the firmware image, and then look up each character by its encoding and output it pixel by pixel when drawing.
/* Illustration: glyph lookup and rendering from a bitmap font */typedef struct { unsigned int code; const unsigned char *bitmap; } Glyph;void draw_text(int x, int y, const char *s, unsigned int color) {while (*s) {const Glyph *g = lookup_glyph((unsigned char)*s++);if (!g) { x += 8; continue; }for (int row = 0; row < 16; ++row)for (int col = 0; col < 8; ++col)if (g->bitmap[row] & (0x80 >> col))put_pixel(x + col, y + row, color);x += 8;}}
Side note: a detour with Shell compilation. Early on, the AI generated code that depended on standard library headers, and the build failed outright. The correction was not to let it guess, but to feed it the protocol definitions provided by the firmware and the list of available headers as context, and to require all output to go through a unified logging wrapper. This episode shows that in bare metal scenarios, the accuracy of the context matters more than the model’s reasoning ability.
5. The Claim That “AI Does Not Understand Low-Level Code”
A common view holds that domains such as register operations and firmware protocol stacks lack training data, so AI cannot handle them and senior engineers must still do the work by hand. That judgment is half right: general-purpose models do tend to make mistakes on protocol details. But there are many ways to improve, such as building a local knowledge base, supplying protocol headers and excerpts from chip manuals as retrieval context, and constraining output with test cases.
More important is restructuring the workflow. Firmware development generally falls into two categories: creative programming and new-platform porting. For the former, AI is good at generating skeletons and algorithms. For the latter, AI is good at bulk rewriting, consistent naming, diff comparison, and filling in documentation. Freeing human effort from repetitive work and directing it toward architecture decisions and hardware validation is where the real efficiency gains come from.
6. A Reusable Collaboration Model and Risk Control
- Context first: put protocol definitions, register descriptions, and the list of available interfaces in place before discussing implementation.
- Small, verifiable steps: advance one verifiable goal per round to avoid large-scale rework.
- Deterministic constraints: state prohibitions explicitly (for example, do not introduce libraries that were not provided) to reduce the room for hallucination.
- Observability: implement logging and on-screen debug output before writing business logic.
- Knowledge capture: turn notes on pitfalls into a local knowledge base, creating a positive feedback loop.
- Controlled cost: select models by the complexity of the everyday task, and reserve expensive models for architecture work and difficult problems.
7. Conclusion
The bare metal AI coding experiment shows that model capability is not the only variable. Context quality, the granularity of task decomposition, and the acceptance mechanism together determine success or failure. For developers, the real payoff is not writing a few fewer lines of code, but shifting the development paradigm from line-by-line implementation to specification description plus verification-driven work. With the general-purpose coding and knowledge base capabilities offered by platforms such as Baidu AI Cloud, this approach can be carried over smoothly to a wider range of low-level scenarios, including firmware, drivers, and embedded systems.
