Last updated: 2026-05-30
What this is. Opinion + Experience + Fact (40% opinion · 35% experience · 20% fact · 5% fiction). Written in collaboration with AI — I discuss, I do not outsource.
1. The bug that only lived in the field
There is a kind of firmware bug that behaves itself on the bench and only misbehaves in the field. The unit runs clean for a week on your desk, then a customer two time zones away hits a state you have a hard time recreating. You fly the logs back and forth. You add instrumentation, ship a build, and wait for it to happen again. The loop is measured in days, sometimes weeks.
The move that closes that gap is older and simpler than most teams reach for. It is not a better debugger or a faster probe. It is running the same firmware on your laptop — the actual logic, the actual state machines, the actual message bus — with the hardware swapped for a stand-in you control. Host simulation.
The idea sounds modest. In practice it changes the rhythm of a whole project, because the slowest part of firmware work has always been the loop between "change something" and "see what happened." Host simulation collapses that loop from minutes on hardware to seconds on a laptop.
▸ First principle. The hardest bugs to fix are the ones you have a hard time reproducing — so the cheapest tool you can build is the one that lets you reproduce on demand.
2. What host simulation actually is
Host simulation means compiling the same firmware code for your development machine instead of the target chip, and running it there. Same C, same modules, same logic. The only thing that changes is the bottom layer — the part that talks to real silicon.
This works when the architecture keeps a clean line between application logic and hardware. The logic above that line does not care whether a temperature reading came from a real sensor over I2C or from a number a test handed it. It just sees a reading. When that line is honest, the entire application can run on a laptop with the hardware faked underneath it.
Most embedded code earns this almost by accident, then gives it up the first time a module reaches straight past the line and pokes a register directly. Keeping the line clean is the whole discipline. The payoff is that the bulk of your firmware becomes ordinary software that runs anywhere.
▸ First principle. If your logic only runs on the target, the target becomes a bottleneck on every change. If your logic runs anywhere, the bottleneck moves to your imagination.
3. The fake HAL is the whole trick
The seam that makes this work is the hardware abstraction layer — the HAL. On the target, the HAL drives real peripherals. On the host, the HAL is a simulated stand-in: a fake sensor that returns scripted values, a fake timer that the test advances by hand, a fake bus that records what was sent.
Because the application talks only to the HAL interface, swapping the implementation underneath it is invisible to everything above. The same read_temperature() call resolves to a real driver on the chip and to a test double on the laptop. No application code changes between the two.
That single seam is what unlocks everything else. A simulated HAL lets you drive the system into any state on purpose — brownout at boot, a sensor that drifts, a message that arrives out of order — and watch exactly how the logic responds, in seconds, with no hardware in the loop.
▸ First principle. A clean hardware seam is not a convenience. It is the line that decides whether your firmware can be tested at the speed of software.
4. What it looks like to run
Here is the shape of it. The same project that builds for the target also builds and runs on the host:
$ make run-host
cc app/*.c hal/sim/*.c -o build/host/app
./build/host/app --scenario warmup
[t=0.00] boot.reset cause=power_on
[t=0.01] state.change fsm=heater from=idle to=warmup
[t=0.40] msg.rx id=temp value=18.2C
[t=1.20] state.change fsm=heater from=warmup to=run
[ok] scenario 'warmup' completed in 1.3s
Six lines of command, and the whole control path ran on the laptop: boot, the warmup state, a simulated sensor reading, the transition to run — all without a board attached. The scenario finished in seconds. Change a line of logic, run it again, see the new trace immediately.
The same trace is what an AI agent reads to understand the system, and the same command is what it runs to check its own change. A coding agent can extend a feature, run make run-host, and read the scenario output to confirm the behavior — in the same loop a human uses, at the same speed.
▸ First principle. When the test loop runs in seconds on a laptop, the cost of trying an idea drops low enough that you try more of them.
5. The hours it reclaims
The reclaimed time shows up in three places. The first is the inner loop: the gap between editing code and seeing the result shrinks from a flash-and-watch cycle to a rebuild that finishes before you look up. Over a sprint, those minutes add up to hours.
The second is continuous integration. Firmware that runs on the host runs in CI — a server that has no board can still build the firmware and run every scenario on every commit. Regressions surface within seconds of being introduced, not at integration time on hardware.
The third is the field bug from the first chapter. When the logic runs on the host, the state that only appeared two time zones away becomes a scenario you script once and replay on demand. The bug that used to take a round-trip of days becomes an afternoon at your desk.
▸ First principle. Host simulation does not replace hardware testing. It moves the work that does not need hardware off the critical path, and leaves the board for the work that truly needs it.
6. Why it is table stakes now
None of this is new. Running code on a host with a faked bottom layer is a technique older than most of the chips on your bench. What changed is the cost of going without it. Sprints are shorter, CI is expected, and there is now a second reader of your code — the AI agent — that needs to run the system as easily as it reads it.
A host-simulated architecture serves all three at once: the human gets a fast loop, the CI server gets a target it can build, and the agent gets a system it can exercise. The teams that build the hardware seam on day one spend the rest of the project moving fast on a laptop. The teams that skip it spend it waiting on a board.
The discipline is small and the payoff compounds every single day of the project. That is about the best return embedded work offers.
▸ First principle. The cheapest place to run your firmware is the machine already on your desk — and an architecture that lets you do it pays back on every commit.
What part of your firmware could already run on your laptop today — and what is the one dependency on real hardware that is holding the rest of it back?
Next: seven specific things AI agents need from firmware — concrete, addressable, and in the framework today.
Labeled: Opinion + Experience + Fact (40% opinion · 35% experience · 20% fact · 5% fiction)
Sources: Written from direct experience across many firmware projects. No external sources cited.
(Written in collaboration with AI — I discuss, I do not outsource.)
— Ritesh | ritzylab.com
#FirmwareEngineering #EmbeddedSystems #HostSimulation #TestAutomation #SystemsArchitecture
Stay in the loop
New essays on embedded systems, firmware quality, and engineering craft. No noise.
Discussion
No comments yet. Be the first to share your thoughts.
Leave a comment