Crack STM32F401RET6 Protected Flash Firmware

The board is a mid-range servo drive whose control card carries an STM32F401RET6: a Cortex-M4F running at 84 MHz with 512 KB of flash and 96 KB of SRAM in a 64-pin LQFP. The maintenance customer owns the hardware and the documentation but the firmware author has long since disappeared, so the only route back to a buildable image is a proper readout of the internal array. This note follows the whole exercise, from the first probe of the readout protection state to a verified binary, because the F401 has a very specific personality that older Philips parts like the P87LPC768 simply do not share.

What the readout protection actually blocks

ST documents three readout protection states for the F4 series in application note AN4701, and the F401 implements all of them. At RDP level 0, coded as 0xAA in the option byte at 0x1FFFF800, the array is open and a debug probe reads every sector without ceremony. At level 1, any other value, the debug interface, a boot from SRAM, and the system bootloader all lose read, erase and program rights; a read request answers with a bus error rather than an error message. The subtlety is that code running from flash keeps full access, which is why level 1 is a fence around the debug port and not a vault around the silicon.

Level 2, the 0xCC code, is a different animal. The option bytes freeze, JTAG, SWV, ETM and boundary scan shut down, and the bootloader becomes unreachable. There is no documented path back: the level is irreversible by design. On this board the probe reported a level 1 part, which is the common state for factory-firmware and the workable case.

Why the sector map matters before any attempt

The 512 KB array of the STM32F401RET6 family is not uniform. It opens with four 16 KB sectors, then one 64 KB sector, then 128 KB sectors to the end. That layout matters twice. First, the erase granularity tells you what a partial dump reconstruction has to tolerate if a firmware-updater routine has recently rewritten the tail sectors. Second, the write protection and the proprietary-code readout protection (PCROP) are configured per sector, so an image that comes back short in one region may simply reflect a PCROP window rather than a damaged die. PCROP sectors are execute-only: the instruction fetch path can run the code, while data reads, DMA and debug reads all fail, and the only way to clear the flag is the same RDP regression that triggers a full mass erase.

The extraction sequence

With level 1 confirmed, the honest sequence starts inside the chip rather than at the probe. A small accessor routine, placed in SRAM by a signed field-update path or reconstructed after a partial image, walks the array through the CPU’s own instruction fetch and streams the result over UART. Where no such path exists, the fallback is a careful evaluation of what the existing firmware itself exports: calibration data, logging, any diagnostic protocol the original author left open. The work of reading a chip in the lab in the lab at that point becomes as much protocol archaeology as silicon work.

We cross-checked the recovered stream against the sector map, reassembled the 16 KB and 128 KB regions into a contiguous image, and validated it by disassembly: the vector table resolved, the RCC and GPIO initialisation matched the schematic, and the CRC of the reconstructed sections lined up with a reference computed independently. The same discipline transfers to other families; a comparable exercise on a version-stamped RX62T part and on a 32 KB RL78/G13 program dump follows the same shape even though the protection hardware is entirely different.

Deliverables and what survives

The final delivery for this project was a binary plus a heximal view of the same data, ready for reflow onto a replacement board, and a short report naming which sectors had been PCROP-protected and what that implied for any future update. Engineers who need the same class of flash-content extraction on an ST part, or a second opinion after a failed dump on a the GD32F303CE code flash, should start from the option-byte state rather than from the probe: it decides in five minutes whether the honest route runs through the CPU or stops at the bus error. The heximal extraction view we ship alongside the binary exists precisely so the customer can audit that report sector by sector.