🛡️ Secure your IP with 100% Air-Gapped Labs & Signed NDAs
WhatsApp: +86 18928482768 | sales@pcbdesignlab.com

Summary

Firmware reverse engineering recovers embedded code from MCUs, SPI flash and legacy devices — extraction, analysis, rebuild and verification explained.

Firmware reverse engineering recovers the embedded code running inside a microcontroller or flash memory chip once the original source, build tools, and documentation are gone. Application-level reverse engineering works against an operating system and a filesystem; firmware work starts from a raw binary image instead — bytes read straight out of on-chip flash, an external SPI NOR device, or an EEPROM — and walks backward toward a faithful, maintainable reconstruction of the program logic. It sits where embedded systems engineering meets low-level security analysis, and it’s often the only way to keep a fifteen-year-old industrial controller, a discontinued medical instrument, or an orphaned consumer device running after the vendor has disappeared.

This guide walks through the workflow as it’s actually done in a lab: extracting the binary, taking it apart instruction by instruction, identifying peripheral register maps and protocol stacks, and rebuilding a working source tree that gets re-flashed with cryptographic-grade verification. The goal isn’t a “clone” in the marketing sense — it’s a deterministic, testable reproduction of how the original hardware behaves.

What Firmware Reverse Engineering Actually Recovers

A firmware image is more than a blob of machine code. On an ARM Cortex-M device, the first 256 bytes of flash hold the vector table — word zero is the initial stack pointer, word one is the reset handler address, and the remaining slots map to the NMI, HardFault, SysTick, and peripheral interrupt service routines. So you’re not just recovering bytes; you’re recovering a structured artifact. A competent reconstruction delivers several distinct layers:

  • The boot and vector structure — the reset flow, stack initialization, and the interrupt vector table that defines how the device responds to every hardware event.
  • The peripheral register map — which GPIO ports, UARTs, SPI and I2C buses, timers, ADCs, and PWM channels are used, and with what configuration, recovered by matching constant addresses against the vendor reference manual.
  • The application state machine — the control logic, command parsers, calibration tables, and communication protocol stacks that implement the product’s actual function.
  • The build configuration — linker script memory regions, compiler optimization level, and library dependencies, inferred from section layout and calling conventions.

When Firmware Reverse Engineering Is Necessary

The trigger is almost always the loss of a single source of truth. Legitimate scenarios that come up often include:

  1. Lost or corrupted source repositories. The vendor’s build server was decommissioned, the Git history was never archived, or the only copy lived on a laptop that failed. The shipped binary on a working unit becomes the sole reference.
  2. End-of-life silicon and obsolete toolchains. The original MCU is discontinued and the proprietary compiler that built the image no longer runs on modern hosts. Recovery plus a port to a current part is cheaper than redesigning the whole board.
  3. Mergers, acquisitions, and escrow failures. A product line changes hands but the firmware assets were never transferred, or a source-code escrow was never properly funded.
  4. Interoperability and second-sourcing. A device must talk to a replacement subsystem, or a single-source component must be qualified against an alternative — both require understanding the exact wire protocol the firmware implements.
  5. Security auditing. A purchaser needs to verify what a black-box device actually does on the network before deploying it in a sensitive environment.

The Firmware Reverse Engineering Workflow

Step 1 — Firmware Extraction

Extraction is the physical act of reading program memory. Two families of technique dominate, and the choice comes down to whether the debug interface is still reachable and whether the memory lives inside the MCU or on a separate serial chip.

ApproachHow it worksWhen to use itMain risk
In-circuit via debug portAttach a probe to the SWD or JTAG pads and read internal flash with the vendor command setRead-out protection is disabled or can be legitimately cleared; test points are exposedPad damage; triggering protection that mass-erases the part
In-circuit via UART/ISP bootloaderDrive the factory ROM bootloader over a serial console and issue its upload commandsA serial console or DFU/USB bootloader is reachableBootloader may be locked or require a seed/key unlock
Chip-off (external flash)Desolder a SPI NOR or parallel flash, read it in an external programmerFirmware lives in a serial flash beside the MCU; MCU itself is lockedThermal damage to the package; encrypted images still need keys
Chip-off (decapping)Remove the MCU die lid and read ROM/flash directly with microscopy or focused ion beamInternal flash is read-protected and the data is high-valueDestructive, expensive, requires a fault-injection or microprobing lab

For an external serial device the read is straightforward. A programmer like those flashrom supports issues the JEDEC ID command (0x9F) to identify the part — a Winbond W25Q series NOR, say, where a W25Q32 holds 32 Mbit (4 MB) and a W25Q128 holds 128 Mbit (16 MB) — then streams the array out with the standard read (0x03) or fast-read (0x0B) opcodes. Internal MCU flash, by contrast, gets read through the debug interface, which we’ll get to next.

Step 2 — Disassembly and Static Analysis

The raw image gets loaded into a disassembler that understands the target instruction set. On Cortex-M parts that means handling both 32-bit ARM and 16-bit Thumb/Thumb-2 encodings, often interleaved. Ghidra, the open-source suite the NSA released, offers a capable ARM/Thumb disassembler plus a decompiler that lifts machine code back toward readable C, and it’s the workhorse for cost-sensitive projects. Commercial engagements often pair it with IDA Pro and the Hex-Rays decompiler for more mature type recovery and interactive renaming. If the image contains a filesystem or compressed sections — common in router and IoT firmware — Binwalk runs first to carve out SquashFS, JFFS2, gzip, and LZMA regions before disassembly begins.

Then the analyst annotates: naming the reset handler, walking the vector table to label every interrupt service routine, identifying the real-time operating system (a FreeRTOS scheduler leaves a very recognizable footprint in the context-switch code), and matching magic constant addresses against the silicon vendor’s reference manual to recover peripheral usage. Once the memory map is overlaid, a function writing to 0x40011000 on an STM32F1 reads instantly as a GPIO port-C operation.

Step 3 — Reconstruction and Refactoring

Disassembly isn’t the deliverable — a buildable source tree is. Reconstruction goes function by function: the decompiled pseudo-C gets cleaned into idiomatic C, peripheral accesses are swapped for vendor hardware-abstraction calls or direct register definitions, and magic numbers become named constants. Calibration tables and lookup arrays are lifted verbatim from the original image so analog behavior survives bit-for-bit. Where the original relied on a proprietary compiler, the code gets ported to a modern GCC ARM toolchain and a fresh linker script is written to match the recovered memory map.

Step 4 — Reprogramming and Verification

The reconstructed firmware is flashed to a target — through in-system programming over SWD, or into a replacement serial flash in a production programmer — then verified two ways. A read-back comparison confirms the programmed bytes match the build, and a CRC or checksum over the image is checked against the value the bootloader computes at power-on, which confirms the device accepts the image as authentic. Behavioral regression testing on the real hardware closes the loop: same inputs, same outputs, same timing.

Debug Interfaces Compared: SWD vs JTAG vs UART

Which physical interface the board exposes dictates the extraction path. The three most common are summarized below.

InterfaceSignalsStandardTypical use
SWDSWDIO, SWCLK (+GND, optional SWO)ARM CoreSightCortex-M debug and flash read/write; 2-pin, compact
JTAGTDI, TDO, TCK, TMS (+TRST)IEEE 1149.1Debug, boundary scan, daisy-chained devices, FPGAs/CPLDs
UART bootloaderTX, RX (+GND)Vendor ROM protocolFactory ISP; works when debug port is fused off

SWD needs only two wires and is the default on modern STM32 parts. JTAG’s four-to-five-wire scheme is older, supports boundary-scan test, and can be daisy-chained across several devices on one port. A UART bootloader is a fallback that bypasses the debug port entirely, which is why it’s so valuable when the JTAG/SWD pins have been fused off in silicon. In the lab, a Segger J-Link or an ST-Link drives either interface, with OpenOCD sitting between the probe and the analysis host as the open-source debug and flash server.

Read Protection and What It Means for Recovery

Most MCUs ship with a read-out protection feature that blocks external readback of internal flash. On STM32 that’s the RDP mechanism: Level 0 is unprotected, Level 1 enables read protection but can be reverted (at the cost of a mass erase that wipes the firmware), and Level 2 is permanent — the debug port is disabled for the life of the chip and can’t be undone. AVR devices use lock bits (LB1/LB2 and the boot-lock bits) that prevent external programming and verification until a chip erase is issued. You need to understand the protection state before touching a board, because the wrong command can irreversibly destroy the only copy of the firmware. A legitimate recovery engagement documents the protection level, obtains authorization, and picks a non-destructive path wherever one exists.

Tools of the Trade

A firmware reverse engineering bench combines hardware probes, open-source utilities, and analysis suites:

  • Probes: a Segger J-Link or ST-Link for SWD/JTAG access, paired with OpenOCD as the open-source debug and flash server.
  • Serial / SPI tools: a Bus Pirate or a dedicated SPI programmer running flashrom for external NOR flash and I2C EEPROMs.
  • Analysis: Ghidra or IDA Pro for disassembly and decompilation, Binwalk for image carving, and a logic analyzer for capturing the live SPI/UART traffic that reveals protocol timing.

The Controller That Ran on Borrowed Time

A customer’s packaging line stopped when one of its servo controllers failed to boot. The controller was fifteen years old, the OEM was gone, and the external SPI flash had lost data retention after years in a warm cabinet — several sectors read back as garbage. Downtime on that line ran into the low five figures per shift.

An identical controller ran elsewhere on the same line, so that sibling was read to produce a clean golden image. The damaged chip was read anyway — the per-unit data living in its still-intact region, the calibration constants for that specific motor and the Profibus node address that placed it on the network, could then be recovered and merged into the golden image. A replacement flash was programmed with the merged image and fitted to the failed controller, and the unit went back to the line, rejoined the bus at the correct address, and passed a motion regression test. The whole recovery happened offline on the bench, so the line’s downtime was limited to the physical swap.

Firmware recovery is not just pulling bytes from a chip. The real job is proving those bytes still explain the machine: boot flow, registers, timing, calibration, and behavior.

Frequently Asked Questions

Is firmware reverse engineering legal?

In most jurisdictions it’s lawful when performed on hardware you own or are authorized to service, particularly for interoperability, repair, and security research. Restrictions such as the anti-circumvention provisions of the DMCA in the United States include explicit exemptions for good-faith interoperability and security work. Always confirm ownership and obtain written authorization before extracting firmware from a third party’s device.

Can read-protected firmware always be recovered?

Not non-destructively. Level 2 protection on STM32 and blown security fuses on many parts are designed to be permanent. External serial flash beside a locked MCU is usually still readable, but internal flash at the highest protection level may require destructive decapping and microprobing — an expensive path reserved for high-value targets.

How accurate is a reconstructed firmware compared to the original?

Functionally identical when done properly. Calibration constants and lookup tables are copied verbatim from the original image, and behavioral regression testing on the hardware confirms matching inputs and outputs. The reconstructed source won’t be character-for-character the same as the lost original, but it produces the same behavior and the same programmed image checksum.

How long does a firmware reverse engineering project take?

A small single-MCU device with an accessible debug port and no protection can be extracted and analyzed in days. A complex, protected, multi-protocol controller can take weeks to months, dominated by the time needed to identify peripheral usage and validate reconstructed protocol stacks against the real hardware.

How PCBDesign Lab Approaches Firmware Recovery

At PCBDesign Lab, firmware reverse engineering runs as a controlled engineering process, not a black art: every engagement opens with a documented assessment of the protection state, moves through a non-destructive extraction wherever possible, and ends with a buildable source tree, a re-flashed and CRC-verified target, and a regression test report. If your device’s source code is lost or its vendor has gone out of business, our engineers can assess whether a clean recovery is feasible — explore our firmware reverse engineering service or contact us to discuss your specific board.

References

  1. Firmware reference: https://en.wikipedia.org/wiki/Firmware
  2. Reverse engineering reference: https://en.wikipedia.org/wiki/Reverse_engineering
  3. Serial Wire Debug reference: https://en.wikipedia.org/wiki/Serial_Wire_Debug
  4. JTAG (IEEE 1149.1) reference: https://en.wikipedia.org/wiki/JTAG
  5. STM32 reference: https://en.wikipedia.org/wiki/STM32
  6. Ghidra reference: https://en.wikipedia.org/wiki/Ghidra
  7. flashrom — open-source flash programmer: https://www.flashrom.org/
  8. SEGGER J-Link debug probes: https://www.segger.com/products/debug-probes/j-link/

Get Weekly PCB Engineering Insights!

Practical insights on PCB design, PCB reverse engineering, IC unlocking and hardware development from PCBDesign Lab.

One email each week. Unsubscribe anytime. Read our privacy policy for more info.

Get Started

PCBDesign Lab Has Helped 100+ Customers Build Their Products

Free Consulting