Fail-Safe Firmware Upgrades: Failure Model, Requirements and Design Objectives

This article is part of a three-part series on fail-safe firmware upgrades.

Part 1: Fail-Safe Firmware Upgrades: Failure Model, Requirements and Design Objectives (you are here)
Part 2: Fail-Safe Firmware Upgrades: Architecture, Components and Responsibilities
Part 3: Fail-Safe Firmware Upgrades: Failure Analysis, Limitations and Mitigations

Part 1 of 3. A power loss, storage fault or defective image during an in-field upgrade must never leave a device unbootable. This part defines the failure model, the system requirements and the design objectives for a multi-stage boot chain.

An in-field firmware upgrade rewrites boot-critical code in place, on the storage the device boots from, and the new image has never executed on that unit. A power loss, a failed flash write or a defective image in that window can leave no bootable image, which turns a routine update into a costly on-site reflash or a return (RMA).

This series describes a fail-safe upgrade mechanism for a multi-stage boot chain. Part 1 defines the problem, the requirements and the design objectives. Part 2 describes the architecture of the proposed solution. Part 3 analyzes its failure points, residual limitations and mitigations.

Deployment context

The mechanism was developed for a client that provides mission-critical communication infrastructure, deployed in remote locations that are costly to service. The cost of a failed upgrade is very high for that client, so the architecture keeps a fallback image installed on the device at all times. A deployed device carries two release slots (A/B) and a golden image. The golden image is factory-tested and supports a restricted feature set, enough to reinstall a release image.

The same architecture supports a cost-optimized configuration for consumer electronics, where flash storage capacity affects the bill of materials. That configuration drops the second release slot and keeps one bootable release image plus the golden image. A failed upgrade is recovered by the golden image, which retries the previous version. Part 2 describes both configurations.

Problem statement

The boot chain has four stages: a boot ROM or small loader, a primary boot loader (PBL), a secondary boot loader (SBL) and the operating system. Each stage verifies and starts the next. The upgrade application runs in the OS on a live device and can replace the PBL, SBL and OS images.

Three constraints shape the design:

  • No safe window. The upgrade writes to the same storage the device boots from, so any write can be interrupted.
  • Failure continues after the write. A correctly written image can still hang, reset repeatedly, or boot without ever reaching a healthy state.
  • No external recovery path. An early-boot failure has no network or console, so recovery must be autonomous.

Goal: the device always ends up running a known-good image, using the smallest and most predictable mechanism available.

Failure model

The scope is accidental faults. Protection against deliberate tampering is out of scope for this release.

FailureExample
Power lossSupply drop or brownout during an image write or a metadata update
Storage faultA write that does not take effect, or a block that reads back incorrectly
Bad imageA corrupt, incomplete or defective image
Boot failureA new image that hangs, resets repeatedly or never signals success
Corrupted stateDamage to the record that selects the image to boot
Total lossNo release image is bootable

System requirements

The design defines more than a dozen numbered requirements. These eight drive the architecture.

  1. No overwrite of the running image. An upgrade shall write only to a slot that is not in use. The running image shall stay bootable until the new image is confirmed.
  2. One upgrade in flight. A second upgrade shall not start until the first is confirmed or abandoned.
  3. Verified writes. Every write shall be read back and checked before the system relies on it.
  4. Bounded retries. A new image shall get a fixed number of boot attempts (three in the current configuration). After that it shall be abandoned and the previous image restored automatically.
  5. Independent recovery image. If no release image boots, the device shall boot a minimal golden image whose only function is to reinstall a release.
  6. Reset-tolerant state. The record of the image under trial and its attempt count shall survive warm resets, watchdog resets and power loss at any point.
  7. Confirmation by the OS. Only the running OS, after its own health checks, can declare an upgrade successful. Reaching the OS is not sufficient.
  8. Encryption at rest. Images are decrypted by dedicated hardware during boot. The loader holds no keys.

Out of scope for this release: malicious images, rejection of older versions (anti-downgrade), manual rollback and update of the golden image. Each is recorded as a future item.

Design objectives

The objectives below were the criteria for resolving design trade-offs.

ObjectiveMeaning
Fall back to the last stable versionAny failure during an upgrade leaves the previous version running, never a partial image
Minimal boot-time logicThe decision code runs earliest, with the least support and no field debug access, so each branch is a risk
Atomic state transitionsA power loss at any point resolves to the state before or after a change, never between
Ordered writes over lockingWhere two updates must go together, choose a write order in which every intermediate state is safe
Hardware assistanceA watchdog converts a hang into a reset; registers retained across warm resets carry boot state
Testable failure pathsEvery failure mode can be injected on a bench. The test plan has more than forty cases

Implications for the architecture

The requirements and objectives imply redundant image slots, a persistent record of the trial in progress, a bounded retry policy, an independent recovery image and a hardware watchdog. The engineering problem is arranging these so that no single interruption yields an unbootable device.

Part 2 describes that arrangement and follows one upgrade from start to finish.

Bluehatsoft has implemented this design on several hardware platforms and has worked with SoC design companies to build the supporting hardware aids into their SoCs. Bluehatsoft is available for consulting on the subject, covering design, architecture and implementation. An implementation that includes secure boot is also available and will be covered in a future article series.

Get in touch with us or email us at contact(at-the-rate)bluehatsoft(dot)com.