Ground Embedded KO Subscribe

Notes / Firmware Design & Quality

Firmware update: changing devices in the field safely

Fixing bugs after release needs an update path. A structure that avoids bricking with A/B slots, signature verification and rollback.

GROUND EMBEDDED · NOTEFirmware Design & Quality 08Firmware updates 1volatile uint32_t *ODR 2 = (uint32_t*)0x40020014; 3*ODR |= (1u << 5); 4while (1) { 5 if (flag) toggle(); 6}

Update paths

Path Examples
Wired UART, USB DFU, CAN (vehicle diagnostic tester)
Wireless (OTA) BLE, Wi-Fi, LTE

What causes a brick

Receive new imageVerify CRC · signatureWrite the switch flagRebootConfirm once it runs correctly
The order that survives a power loss during the download.
  • Power loss during a write
  • A corrupted image
  • New firmware that boots but cannot communicate, so it cannot be updated again
RoadmapSee where this note sits in Firmware Design & Quality→

A safe structure

BootloaderSlot Arunning nowSlot Breceives new firmwareSettings
Two slots. New firmware is received into the free one and the switch happens only after verification. On failure it goes back to the previous one.
  1. A/B slots: leave the running image (A) as it is and write the new image to B
  2. Verification: integrity with a CRC, origin with a digital signature (blocks firmware made by just anyone)
  3. Trial boot: the bootloader boots B and leaves it "pending confirmation"
  4. Confirmation: the new firmware runs its self-checks (communication, sensors) and marks itself confirmed
  5. Rollback: if there is a reset without confirmation (watchdog and so on), the bootloader goes back to A

Open-source bootloaders such as MCUboot provide this structure.

Also

  • An anti-rollback counter that prevents version downgrades
  • Dangerous loads such as motors and heaters must be stopped during an update
  • Vehicles have a standard procedure for flashing through UDS diagnostic services (see the automotive software subject)
FREE PDFGet the 3 free ebooksIf you want to keep reading this topic as one book: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →