Engineering Insights

Architecting Firmware for Long-Term Maintainability and Scalability

Firmware structure, module boundaries and the cost of change.

1. Executive summary

Long-term maintainability is the ability to correct and extend firmware throughout a product's service life with a clear understanding of how each change affects the system. Scalability is the ability to support additional boards and product features from a common codebase while continuing to meet the requirements of every supported configuration, including its timing and memory constraints.

When hardware-specific details are confined to board adapters, the same control logic can serve several products. That reuse depends on each adapter providing the behaviour the control logic expects, so the interface must define when an operation is complete, how time is measured and how failures are reported.

This paper examines the architectural and verification practices that make firmware changes manageable, from selecting product configurations to maintaining compatibility with devices already in service. An architecture should make the consequences of change visible so engineers can determine which behaviour they can reuse, where they need to adapt it and what evidence they need before release.

Publication details and citation

EEIO-INS-007 · Revision 1.1 · 2026

Published by EmbeddedExpertIO

Editor Israel Gbati

Suggested citation. EmbeddedExpertIO. Architecting Firmware for Long-Term Maintainability and Scalability. EmbeddedExpertIO Engineering Insights, EEIO-INS-007, version 1.1, 2026.

2. Architectural boundaries and change

Firmware architecture determines how far a change can spread through a product. A board replacement should allow us to retain control logic whose requirements still hold, while a new operating requirement may call for changes to that logic. Establishing this distinction early gives the team a practical basis for deciding where interfaces belong and what they need to preserve.

A family of actuator controllers illustrates where that boundary falls when the products use different boards and communications. The Basic product has one actuator, local sensing, 128 KiB of flash and 32 KiB of RAM. Connected adds Bluetooth Low Energy (BLE), and Industrial uses CAN, a higher-performance microcontroller and more logging capacity. All three accept commands and enforce operating limits, so they have control behaviour that can be developed and maintained together.

As shown in Figure 1, each product selects its board adapter and communication transport through configuration. Initialisation code then connects the selected components, while the shared control logic uses interfaces for samples, time, actuation and persistent state. A pin reassignment stays within the board description and its adapter, whereas a requirement for confirmed position reaches the state machine through the actuation interface.

Basic accepts local commands. Connected adds a BLE decoder and Industrial adds a CAN decoder. All three products feed a common command model into the shared validator, operating limits and control state machine. Dashed arrows point from the policy and board adapters to the capability interfaces they use or implement. With equivalent hardware behaviour, a pin change stays in the board mapping. On products that promise confirmed position, measured position travels up through the actuation interface to the state machine.
Figure 1. Where a board change reaches the control policy View full size

When the Basic board's microcontroller is replaced, the architectural requirement is to retain the command validator and control state machine wherever the new hardware provides equivalent timer, sensing and output capabilities. The platform changes can then be contained within startup code, the linker layout, board configuration and the affected adapters. A diff identifies which modules changed, and a board test tells us whether the replacement provides equivalent behaviour. The existing behavioural tests check that the shared logic still produces the expected decisions, while the board tests establish that the new platform supports the assumptions behind them.

Adding a communication interface can follow the same approach. A CAN decoder can translate incoming frames into the command model and engineering units already used by the BLE decoder, so the common validator can continue to enforce the same limits. If the product must also confirm that the actuator has reached its target, however, the state machine needs to evaluate position feedback, and the actuation interface must provide it.

We can review this architecture by expressing its intended benefits as requirements that can be tested. For example, replacing Industrial's CAN transport should leave the control state machine intact if the replacement preserves the command model and required timing. A quality-attribute scenario records who requests the change, what changes, the operating conditions, the affected components, the expected response and how that response will be measured [1].

3. Interface behaviour and hardware dependencies

Before we can decide whether a replacement adapter preserves an interface, we need to define what a successful operation establishes. On an STM32 timer with compare preload enabled, a write updates the preload register, and an update event transfers that value to the active register. The timer can then generate the requested waveform even if a disconnected motor remains stationary. With a drive connected over a bus, queue admission, transmission, acknowledgement and shaft movement occur at different times. An acknowledgement must therefore be interpreted according to the drive protocol before the control logic uses it to advance the actuator's state.

The USART interface in Arm's CMSIS-Driver makes a related distinction explicit. Its send-complete event can occur while the hardware is still transmitting, and a separate transmit-complete event reports the end of physical transmission where the driver supports that capability [2]. A transmit-complete event therefore cannot establish that a drive has stopped. If the controller must report that state, the actuation interface needs to provide evidence of the physical response.

For an asynchronous adapter in our controller family, acceptance means that the adapter has taken responsibility for an identified request. The state machine then records that request and its expiry time, while a busy result leaves responsibility with the caller. Completion must identify both the request and the event that occurred.

This identification matters when a stop supersedes an earlier motion command, because a delayed reply to that command must not return the state machine to its moving state. The state machine must therefore match each reply to its request and prevent replies to superseded commands from changing the current actuation state. Request identifiers must not be reused while an older reply with the same value could still arrive. A session identifier can extend that protection across restarts. Since the remote drive may still execute a command it has already accepted, the protocol also needs ordering or cancellation rules that make the stop effective.

A fan controller that sets a duty cycle and monitors a fault input may need no transaction state for each register write, whereas a positioning controller needs fresh, sufficiently accurate feedback before reporting “at position”. Its interface must make that feedback available and support the specified response if it is lost. Where a requirement sets a deadline for physical shutdown, verification must establish the response at the actuator under the specified load and fault conditions.

Request expiry and feedback freshness depend on the clock's resolution and behaviour during sleep, as well as the width of the value it returns. If a function returns 64-bit microseconds but its clock stops while the processor sleeps, an old command can appear recent after wake-up. The platform must account for the elapsed sleep time, or the controller must invalidate commands and samples whose age it can no longer establish. The interface also needs to specify the clock’s time origin across resets, the contexts from which it may be read and how long a read can take. On a processor that cannot read the counter in one operation, the implementation must obtain a coherent value.

Once a coherent counter value is available, we still need to establish the interval over which it gives an unambiguous elapsed-time measurement. For an unsigned counter, subtracting the start value from the end value modulo the counter range gives the elapsed ticks when the true interval is shorter than one complete counter period. A software extension can accumulate those deltas into a wider value, provided every interval between reads satisfies the same bound, including intervals that contain sleep. This condition belongs in the implementation and its tests because a wider return type alone cannot recover missed wraps.

To preserve these interface definitions across boards, we must also control which implementation details reach the shared logic. The product's initialisation code should connect that logic to the selected adapters through explicit interfaces. When the shared logic and its public interfaces are free of vendor dependencies, a host build can supply test implementations without vendor headers or libraries.

The production build needs a corresponding check of its actual header dependencies and target relationships, because conditional includes may introduce dependencies that the host build never encounters. CMake's PRIVATE, PUBLIC and INTERFACE scopes express linkage and usage requirements [3], and those declarations provide part of the information needed for this check. The project still needs to reject forbidden target relationships and globally exposed include paths that bypass those declarations. Passing the required interfaces when a component is constructed also makes them visible during review. A service locator that gives any caller access to hardware or storage can conceal those relationships, so its use requires the same dependency review.

Figure 2 shows a direct inclusion of a vendor header and a second route through a public header that exposes a vendor type. The build graph shows declared library dependencies. The actual includes also need to be checked because either route can reach the shared logic without a declared dependency on the driver library.

Two alternative compile-time dependency graphs. Arrows point from the importer to the imported interface. On the left, the control policy imports the vendor timer header directly and the vendor driver header indirectly through a public actuator header that exposes a driver handle. On the right, initialisation code binds policy and platform adapters. Both import vendor-neutral capability interfaces. Only the adapters import the vendor SDK. The clock contract defines behaviour during sleep. The actuation contract defines which event a completion confirms. Inspect actual production headers and target dependencies, and separately compile and link the policy on the host with test adapters and no vendor headers or libraries.
Figure 2. How a vendor dependency reaches a policy module View full size

4. Product configurations and resource limits

Once the control logic is independent of a particular board, we can build the supported products around the same implementation. If each board instead takes its own copy, a defect correction must be repeated and verified in every copy. We therefore need to represent product differences through configuration, so each build selects its board description, compiled features and operating settings without duplicating the shared logic.

In the controller family, Connected has two supported configurations with extended logging. One uses external flash, and the other uses reserved internal storage with its own retention limit. The supported builds are defined explicitly so that developers and release engineers work from the same set of product commitments. Static binding suits a known board configuration, whereas runtime selection serves products that discover supported hardware after boot.

Supported build Command inputs Extended log External flash
Basic Local Off Absent
Connected, internal storage Local and BLE On Absent
Connected, external storage Local and BLE On Fitted
Industrial Local and CAN On Fitted

The supported configurations reach release review through the validation and resource checks shown in Figure 3.

Four supported builds are shown. Basic uses local commands, with extended logging off and external flash absent. Both Connected builds accept local and BLE commands with extended logging enabled. One uses reserved internal storage and the other has external flash fitted. Industrial accepts local and CAN commands, with extended logging on and external flash fitted. Each board description is checked against the selected features. Selecting an external log backend without fitted external flash stops the build before linking. A valid configuration builds the selected modules with the shared control policy. The packaged image must fit its application partition before proceeding to release review. At runtime, the calibrated current limit is checked against the fitted actuator before its output is enabled.
Figure 3. Which product configurations reach a release image View full size

Treating local control, BLE, CAN, extended logging and external flash as independent binary options produces 2⁵ = 32 bit patterns. The table identifies the four combinations the team supports, which gives the build and test systems a defined scope. Configuration validation should also reject combinations that the hardware cannot support. Selecting an external log backend for a board without external flash, for example, should fail during configuration even if the driver itself compiles successfully.

Configuration checks need to distinguish what the board provides from what the software enables. Zephyr represents these separately through devicetree for hardware [4] and Kconfig for software features [5]. The resolved settings still require validation, because Kconfig's select can force a symbol despite unmet dependencies on that symbol [6]. A runtime current limit needs an additional check against the fitted actuator's capability before its output is enabled. Giving the limit an explicit unit, source and validation rule makes its origin clear and allows the controller to respond predictably to an invalid setting.

After selecting a valid build, we still need to establish whether its image fits the available application space. For the Basic product, take a 106 KiB image and a proposed diagnostic feature with an incremental linked cost of 18 KiB. Against 128 KiB of physical flash, the calculation 128 − 106 − 18 leaves 4 KiB. However, reserving 8 KiB of that flash for a bootloader leaves an application allocation of 120 KiB, which the proposed 124 KiB image exceeds by 4 KiB. If the quoted 128 KiB already describes the application slot, the bootloader reservation has already been accounted for. The release check therefore needs both the link map and the final packaged-image extent, with headers, alignment and trailers counted once against the actual partition boundaries.

For Basic's 32 KiB of RAM, the link map identifies static objects and reserved stacks, but it does not establish how much stack or buffer capacity the running system can require. Stack analysis and target measurements must therefore account for nested interrupts, the peak number of live buffers and any pools shared by several consumers. Recording which reservations already appear in the map prevents double counting. A measured stack high-water mark is useful evidence for the paths exercised, and a justified margin must address the remaining uncertainty.

The choice between copying a DMA buffer and passing it directly to a consumer should follow from these resource limits. Copying simplifies ownership but consumes bandwidth and execution time. If that cost threatens Industrial's measured acquisition budget and the consumer can meet a buffer-return deadline, a zero-copy path can be justified. Its ownership protocol must establish when DMA may write, when the CPU may read, who performs cache maintenance on a non-coherent target and how the system responds when a consumer misses its buffer-return deadline. Reusing the buffer too early can corrupt a sample even though every function uses the expected types. Short, infrequent commands rarely justify the same machinery.

5. Verification across host and hardware

Separating control logic from hardware gives us a useful way to organise verification. We can test a decision repeatedly on the host by controlling its inputs, then use the target hardware to establish whether the adapters provide those inputs correctly and deliver the requested response. The interface definitions connect the two bodies of evidence.

For the controller's over-temperature response, a host test supplies the previous state, a temperature in declared units, its validity, the acquisition time and the current time. This makes it possible to test the trip threshold directly, including the required outcome at equality. Holding a cool reading constant while advancing time then tests the freshness rule. The tests should cover readings just inside and just outside the freshness limit, together with equality at the limit. With the controller configured to inhibit motion on stale input, an old, cool reading must keep that inhibit active. Providing time and state explicitly makes the result reproducible without an ADC.

The hardware tests establish whether the data entering that logic has the meaning the host tests assume. If an adapter timestamps a buffered ADC reading when a task removes it from the queue, the value can appear fresh even after a long acquisition delay. Feeding a known input, delaying the consumer and comparing the reported timestamp with the acquisition event exposes that error. The same approach extends to actuation. Testing with the intended drive and load should record command acceptance, output change and the physical quantity that defines the required response, such as current falling below a specified limit. Bus load, timer phase and the slowest permitted sampling interval must be represented in the test conditions. A claim about worst-case response also needs analysis that bounds relevant conditions beyond those exercised.

Host execution remains valuable for faults that are difficult to reproduce on a bench, including delayed replies from superseded commands. Zephyr illustrates how a verification programme can use both target and host execution. Twister supports platform selection and execution on connected hardware [7]. The native simulator runs host-compiled code without emulating a particular embedded processor [8]. Release records should identify what was executed and where, because a successful build provides no result for a test that could not run.

Tests of normal operation do not establish that a component can be started or stopped safely. A controller instance and its dependencies must be ready before interrupts or tasks can call it, and shutdown must stop new work before quiescing or cancelling outstanding operations according to the driver contract. State can be released only when callbacks and other asynchronous users can no longer access it. Tests should therefore exercise completion during shutdown and a restart followed by a reply from the previous instance, because either sequence can expose access to an object whose lifetime has ended.

6. Compatibility across firmware generations

The meaning of an interface's result determines what its callers can safely do next, which makes that meaning part of the compatibility obligation. If storage_write() originally reported success after calibration became durable, a replacement that reports success when the write is queued could allow a caller to power down before the calibration has been stored. The interface therefore needs distinct outcomes for acceptance and durability. A compatibility adapter can preserve the earlier guarantee by waiting for durable completion when the backend exposes that event and the caller's timing and execution context permit the wait. Blocking an interrupt-context caller on a flash worker would violate those conditions.

Preserving the API's behaviour does not, by itself, establish that the new firmware can interpret records already stored on a device. In our controller, schema 1 contains a device identifier, gain and offset, while schema 2 adds a calibration timestamp. Migration can preserve the coefficients and validate their ranges, but the old record contains no calibration date to recover. Representing the timestamp as unknown preserves that distinction. If the product requires a known date before use, it needs recalibration. Using the upgrade time as the calibration time would give the existing coefficients a false provenance.

The migration procedure must retain a usable source record until the new record can be accepted. For this design, power may fail during any erase or program operation, the destination erase unit can fail without damaging the separate source unit, and the storage device provides documented completion and ordering guarantees. Under those conditions, we can retain the committed source record while writing a new record with its schema, generation and integrity information. After its contents have been verified, a commit marker records that the new copy is eligible for use. Using the guarantees of the chosen storage device, the reader must be able to distinguish a valid commit marker from an incomplete one.

On boot, the firmware accepts only committed records with a recognised schema, valid integrity data and permissible field values, then applies a defined generation-ordering rule to select a copy. If no record qualifies, it enters the calibration-recovery state. The integrity check detects corruption within its capabilities, while the write protocol and field validation establish the other conditions for accepting the record.

Because boards, calling software and stored records can follow different upgrade paths, each compatibility obligation needs its own acceptance or retirement condition, as shown in Figure 4. A replacement board adapter needs evidence that the supported hardware still provides the required behaviour. An API compatibility shim must remain while supported callers depend on it, and a record reader must remain while supported installations can still arrive with the older schema.

Three tracks compare generations A and B. Verify equivalent behaviour on supported old and new hardware assemblies. Keep the API shim until no supported caller relies on the legacy durability guarantee. Keep the schema 1 reader until no supported upgrade can start from schema 1. Schema 2 preserves the device identifier, gain and offset and adds a calibration timestamp, which remains unknown for a migrated record with no original date. Keep the committed schema 1 source in its own erase unit. Write schema 2 separately, verify its contents, commit it and then select the newest eligible committed record at boot. If power loss leaves schema 2 uncommitted, the valid schema 1 source can be selected. If old firmware would load stale schema 1 coefficients after recalibration, block that rollback before boot.
Figure 4. Which compatibility promise survives a migration View full size

Configuration changes can also affect compatibility even when the application continues to call the same storage functions. Zephyr NVS writes data before metadata and ignores data with invalid or missing metadata during initialisation. Its metadata checksum covers metadata, and payload protection uses a separate optional CRC. Enabling that payload CRC on records created without it invalidates those records [9]. Zephyr's 4.3 migration guide documents a further compatibility change in secure storage, where reducing identifiers from 64 bits to 30 bits causes authentication to fail for previously stored entries. The guide specifies CONFIG_SECURE_STORAGE_64_BIT_UID for upgrades that need to preserve those entries [10].

Migration tests should interrupt execution before and during destination erase, during the payload write, during commit and after commit. Each restart should verify the selected calibration and the result of retrying the migration. Rollback requires its own tests, particularly after the user has recalibrated under the new schema. An intact schema 1 record may then contain obsolete coefficients that an older image would load without recognising the problem. The release must define which image and record combinations are valid and block an incompatible rollback before the older image starts, with a recovery route available. The same review applies to protocol peers, bootloader metadata and diagnostic readers with independent release schedules.

Compatibility also needs a defined scope and an owner who can decide when support ends. Zephyr places stable APIs under its deprecation policy [11], while its private vendor interfaces carry no equivalent lifecycle or backward-compatibility guarantee [12]. Within a product family, retirement decisions should account for service and recovery images as well as normal application releases. This prevents the removal of an adapter or reader that remains necessary for a supported maintenance path.

7. Release evidence and maintainability

Before accepting a firmware change, the team needs a record that connects the architectural intent to the product's observed behaviour. For a replacement board, that record should show where the source changed, which existing commands remain valid and whether the events reported by the new adapters retain their meaning. The supported configurations must have recorded builds and resource headroom, with host tests for shared decisions and hardware evidence for timing and physical response. Where stored data changes, the record must also establish the supported migration and recovery paths.

The board revision, resolved settings, source and dependency commits, toolchain identity, release image and test results belong in the same record so the team can identify the configuration that produced the evidence. A frozen west manifest can record the project revisions as commit identifiers [13], while the application revision, local modifications, generated inputs and toolchain need their own records. This gives a future engineer enough information to relate a reported defect to the release that produced it.

If replacement hardware cannot preserve an existing behaviour, the team must make an explicit requirements decision and define the corresponding acceptance test. A maintainable architecture makes the affected dependencies visible, so the team can implement and verify that decision without spreading an unnecessary change across the rest of the product family.

Training for engineering teams

EmbeddedExpertIO provides professional training in embedded systems and firmware development. If you are planning training for your team, we can help you choose courses that suit your engineers’ experience and the work ahead. Teams can enrol in a selected group of courses or arrange access to the full course library.

Discuss your team’s training requirements · support@embeddedexpert.io

8. References

[1] Felix Bachmann, Len Bass and Mark Klein. Deriving Architectural Tactics: A Step Toward Methodical Architectural Design, CMU/SEI-2003-TR-004, March 2003, §2.1. SEI report

[2] Arm. CMSIS-Driver USART Interface, ARM_USART_Send, send-complete and transmit-complete events. Function reference

[3] Kitware. CMake 3.31, target_link_libraries, “Libraries for a Target and/or its Dependents”. Command reference

[4] Zephyr Project. Devicetree: Scope and purpose. Hardware description and build flow

[5] Zephyr Project. SoC Porting Guide, “Write Kconfig files”. Porting guide

[6] Linux kernel project. Kconfig Language, “Menu attributes”, entries for depends on and select. Language reference

[7] Zephyr Project. Test Runner (Twister), “Board Configuration” and “Device Testing”. Test runner

[8] Zephyr Project. Native simulator, “Architecture”. Board documentation

[9] Zephyr Project. Non-Volatile Storage (NVS), record layout, metadata ordering and data CRC compatibility. Storage documentation

[10] Zephyr Project. Migration guide to Zephyr v4.3.0, “Secure storage”. Guide source

[11] Zephyr Project. API Lifecycle, “Stable” and “Deprecated”. Public API policy

[12] Zephyr Project. Vendor-Specific API Placement Policy, discussion of private SoC interfaces. Placement policy

[13] Zephyr Project. West Manifests, “Freezing Manifests”. Manifest reference