PostHeaderIcon Reverse Engineering NXP Chip LPC2106FBD48 Flash by Live Capture

There are two ways to obtain firmware from a device. The first is to read the memory and reconstruct the program from what is stored. The second is to let the device run and take what it is using while it runs. On an unprotected part both work, and they produce the same answer, which is why the distinction is easy to ignore.

On a part that resists the first approach, the second is often the only one that produces anything at all. It also happens to be the more informative of the two, because a running device exposes the relationship between code and state that a static file only implies.

What the debug unit actually provides

The ARM7TDMI-S core in this family carries an embedded in-circuit emulator — a small block of logic, separate from the CPU, that can stop the core, examine registers, and read or write memory over the JTAG scan chain. It also carries two watchpoint comparators and a handful of breakpoint comparators, plus a vector catch facility that halts the core when an exception is taken.

The practical consequences are worth spelling out:

  • The core can be halted at an arbitrary instruction address and its complete register state read out, including the program counter, the mode, and the banked registers for each exception mode.
  • Memory can be read and written while halted, without the application’s cooperation and without going through any driver.
  • A watchpoint can stop the core when a chosen address is accessed, which turns an unknown routine into a located one.
  • Vector catch stops the core at the first instruction of an exception handler, which is the cleanest way to find code that only runs on an error path.

None of this needs the flash to be readable through the loader. The debug path reaches memory through the core’s own bus, which is a different door from the one the boot loader guards.

Property Cold dump of the array Live capture at a halt
what you get bytes as stored code as it runs, plus registers and RAM
relocated routines stub left behind the copy in SRAM
compressed images packed data expanded working set
requires the port to be open yes yes, but the debug path, not the loader
risk to the device none watchdog, low power, clock change
typical use protected but readable readable and deliberately obscured

Why that matters on this part

Firmware written for a 256 kilobyte array with 16 kilobytes of SRAM in a small package almost always does something at start-up that a static dump misrepresents.

The common pattern is relocation. A routine is copied from flash into SRAM and executed there, either because it programs flash — code cannot write the array it is running from — or because it needs to run faster than the memory accelerator allows. Once copied, some designs overwrite or deliberately corrupt the flash copy, and what remains in the array is a stub that will never run again.

The second pattern is decompression. A compressed image is expanded into SRAM at boot, and the flash holds only the compressor’s output. A dump of the array then yields data that looks like noise in a disassembler and contains no recognisable instruction stream.

The third pattern is a validity check with consequences. Firmware that finds an unexpected checksum, an unexpected debug attach, or an unexpected read of a protected region may clear its own working set or refuse to initialise. A cold dump taken after such a decision records the aftermath, not the program.

Live capture sidesteps all three, because it takes the image after the device has already done the work of making it usable.

The procedure that produces something

Reset the device with the debugger attached but not halting at the first instruction, and let it reach its idle loop. Then halt. At that point SRAM contains the relocated code, the initialised data, the stack, and the heap — the state the firmware considers normal.

Read SRAM in full, then read the array, then compare the two. Regions that appear in both are the copies. Regions that appear only in SRAM are the decompressed or generated content, and they are frequently the part that mattered.

For code that only exists briefly, use the watchpoint. Pick the address the routine will touch — a peripheral register, a table it must read, a buffer it must fill — and let the device run until the access happens. The core stops with the program counter inside the routine, and the surrounding memory holds whatever it had just produced. Repeat with different watchpoints to walk through the sequence.

The failure modes of halting

Stopping a running product is not free, and on an embedded target three things commonly go wrong.

The watchdog resets the device while the core is halted, because halting the CPU does not stop the watchdog counter. Either disable it before halting, or configure the debug unit to stop it too if the silicon supports that, or accept a short window and work in bursts.

A low-power mode kills the clock the debug logic needs. A device that enters a deep sleep state may become unreachable until it is woken by the peripheral that normally wakes it, and a watchpoint on that peripheral’s register is the way back in.

Adaptive clocking matters on a board with an unusual core clock. The debug unit can be configured to return a clock to the host that tracks the target, and without it a design running at an odd frequency will attach and then lose sync on the first speed change.

What the capture gives the customer

The output of a live capture is not just a binary. It is a binary plus a set of observations that explain it: where the code runs from, which regions are generated at start-up, which handlers exist, and what the device does when it decides something is wrong.

That last item is often the most valuable. Products that clear state on a suspicious event are common in metering and access control, and the only way to see the behaviour is to watch it happen rather than to read about it in a listing.

Where this sits among the other routes

When the protection word is open, the simplest job is a read through the boot loader, described in LPC2102FBD48 data recovery. When it is closed, the debug unit is gone as well, and the choice narrows to the invasive routes covered in LPC2104FBD48 erase behaviour. The same silicon in the other package brings its own access problems, covered in LPC2106FHN48 firmware work. The interesting middle ground — where the debug port answers but the array does not — is where live capture earns its keep, and the same core-level techniques transfer to neighbouring parts such as AT91SAM7S256, where the vendor’s protection policy differs but the ARM7 debug architecture is the same.

One practical note

Record the reset behaviour before halting anything. A single capture of what the device does on power-up, taken from the pins rather than from the debugger, is the baseline that tells you whether the state you later halt in is normal or already degraded. It costs two minutes and it prevents the most embarrassing class of wrong conclusion, which is a faithful dump of a device that had already given up.

Comments are closed.