Archive for the ‘Reverse Engineer Microcontroller’ Category
Reverse Engineering MCU ATMEGA48P Program
Reverse Engineering MCU ATMEGA48P Program from flash memory and copy heximal program to new microcontroller atmega48p secured chipset;
Not all 16-bit accesses uses the Temporary Register for the high byte. Reading the OCRnA/B/C 16-bit registers does not involve using the Temporary Register, To do a 16-bit write, the high byte must be written before the low byte. For a 16-bit read, the low byte must be read before the high byte.
The following code examples show how to access the 16-bit timer registers assuming that no interrupts updates the temporary register. The same principle can be used directly for accessing the OCRnA/B/C and ICRn Registers. Note that when using “C”, the compiler handles the 16-bit access.

unlock encrypted atmega48pv microcontroller protective system and dump embedded heximal file from flash memory
The assembly code example returns the TCNTn value in the r17:r16 register pair. It is important to notice that accessing 16-bit registers are atomic operations when breaking microcontroller atmega48p atmel avr chip fuse bit. If an interrupt occurs between the two instructions accessing the 16-bit register, and the interrupt code updates the temporary register by accessing the same or any other of the 16-bit Timer Registers, then the result of the access outside the interrupt will be corrupted.
Therefore, when both the main code and the interrupt code update the temporary register, the main code must disable the interrupts during the 16-bit access after readout microcontroller atmega48pa binary file and heximal from eeprom and flash memory. The following code examples show how to do an atomic read of the TCNTn Register contents. Reading any of the OCRnA/B/C or ICRn Registers can be done by using the same principle.
If writing to more than one 16-bit register where the high byte is the same for all registers written, then the high byte only needs to be written once. However, note that the same rule of atomic operation described previously also applies in this case.
Decapsulate Protected GD32F303RET6 MCU: When Software Fails
Most GD32F303 recoveries are electrical. The GD32F303RET6 in an LQFP64 body with 512 KB of flash is no exception — until the part is set to SPC level 2. At that point the debug port, the bootloader and the fault-injection windows are all gone, and the only route left is to decapsulate the protected GD32F303RET6 MCU and reach the silicon itself, reading the array without ever asking the core for permission.
Level 2 is a different problem
Level 1 refuses reads but leaves the part electrically alive and attackable. Level 2 seals it: the chip will not enter debug, will not answer the bootloader, and cannot be returned to level 0 even by a mass erase. There is no bus-level trick that opens it, because the protection is latched in a way the part enforces for its whole life. This is the line where software recovery ends and physical recovery begins, and it is why we keep a decapsulation capability on the bench rather than only electrical rigs.
What decapsulation actually does
The LQFP64 is opened by removing the mould compound over the die, usually by a controlled chemical etch that stops at the passivation layer. The bond wires and leads stay intact, so the part remains functional on the fixture even with the lid off. With the surface exposed we can probe the flash directly, read it through the test structures, or prepare the die for laser or FIB work that would be impossible through the package. Decapsulating a protected GD32F303RET6 MCU is the prerequisite, not the read itself, and it is done with the part powered and responding so we know the die is alive before we commit to the read.
Reading the die after the lid is off
Once open, the 512 KB array can be reached by methods that do not invoke the lock at all. Dual-probe and flying-probe techniques, described in our probe test notes, contact the relevant buses and recover the contents directly off the silicon. The larger flash is an advantage here: more redundancy and clearer structures make the die-level read more reliable than on a tiny part, and the LQFP64 bond layout is well understood, so fixture risk stays low.
When decap is the only honest option
Level 2 is not common, but it is final, so it must be identified before any electrical attempt that could stress the part. The table shows how the decision splits on this 512 KB device, and why a wrong guess wastes a unit.
| SPC level | Electrical read | Die-level read |
|---|---|---|
| 0 – open | yes | yes |
| 1 – read lock | glitch | yes |
| 2 – chip lock | no | yes, after decap |
What we do with the opened part afterwards
Decapsulation is not destruction, but it is not reversible either. The RET6 leaves the bench with its lid off and its bond wires intact, fully functional but no longer sealed against the environment, so it is returned as-is only when the customer wants the die, and otherwise the recovered image is what travels and the opened part stays with us. This is different from every electrical recovery, where the unit goes back exactly as it arrived. Before the etch we photograph the package and after we photograph the die, so the customer has a record of exactly what was done. The trade is worth stating plainly: a level-2 lock forces a physical read, and a physical read ends the part’s sealed life even when the firmware is perfectly recovered. For most owners the image is the prize and the opened die is a fair price; for a few who need the original hardware running, a decrypted clone on a fresh part is the better path, and we say so before we etch anything.
Returning the result
After the array is read at the die the image is reconstructed, verified, and delivered with a note on the level-2 state we found. If a running clone is needed the recovered image is written to a blank decrypted part with the lock set to level 0. This is the fallback that makes even a sealed GD32F303RET6 recoverable: when software fails, decapsulating the protected MCU is what still gets the firmware out, and the data decode that may follow treats the recovered array like any other image.
GAL16V8: Reading a Fusemap That Is Not Code
Everything about this device is different from a microcontroller, and the habits carried over from firmware work are actively unhelpful. There is no instruction set, no program counter, no stack. There is an array of connections between sixteen input signals and eight output macrocells, and what it implements is whatever those connections happen to compute.
The good news is that the output is more useful than a firmware dump. Equations can be read, checked against a truth table, and re-implemented anywhere. The bad news is that the recovery question is not “can I read it” but “is the array still readable”, and that depends on one bit.
The architecture in one paragraph
Twenty pins: sixteen inputs, eight outputs, power and ground. Each output pin drives a macrocell, and each macrocell contains a flip-flop, a set of multiplexers, and an output enable. The AND array has sixty-four product terms of thirty-two literals each — two literals per input signal, true and complement — and the macrocells combine those terms into sum-of-products logic, either combinationally or registered.
That is the whole device. Two thousand and forty-eight array bits plus a small number of architecture bits, and the architecture bits decide what the array means.
| Region | Size | Function |
|---|---|---|
| AND array | 2048 bits | The actual logic, one row per product term |
| Architecture bits | a few dozen | Macrocell mode, feedback path, polarity |
| Electronic signature | 64 bits | User data, often a date code or part number |
| Security cell | 1 bit | Whether the array can be read at all |
The bit that decides whether there is a job
The security cell is a single bit whose only purpose is to stop a programmer from reading the array. When it is set, a read returns a legal-looking file whose array section is all zeros or all ones, and a JEDEC reader will happily parse it and produce nonsense.
Recognising that pattern is the first skill. A real array is never uniform; a secured one is. If every product term decodes to either “always true” or “always false” — that is, every row is either all fuses intact or all fuses blown — stop, because you are looking at the security state, not at the logic.
Whether the cell can be cleared depends on the manufacturer and the date code. Some parts allow a bulk erase that clears both the array and the security bit, which reopens the device for reading only because the logic is gone with it. Others treat the cell as one-time. Establishing this from the specific part marking, before spending a day on a plan, is the sensible order of events.
Decoding the array
For each of the sixty-four rows, the thirty-two array bits say which literals participate in that product term. Under the standard convention an intact link contributes its literal and a blown link does not, and a row with every link blown is a term that evaluates to true unconditionally.
Read the rows in order, and the structure of the design becomes visible, because designers and compilers both write in patterns:
- Consecutive rows feeding the same macrocell are usually the terms of one output.
- A row containing a single literal is usually an enable condition or a clock qualifier.
- Blocks of rows that reference the same few inputs are usually a decoder — an address comparison, a state decode, a chip select.
- Rows that reference an output’s own feedback are usually latches or state machines, and they are the ones that need care.
The macrocell mode is half the meaning
The same array bits mean different things depending on how the macrocell is configured. In combinational mode the sum of products drives the pin directly. In registered mode the sum feeds a flip-flop clocked from a dedicated pin, with the output enable on another pin. In the third mode the output is a dedicated input and the term structure changes again.
Getting the mode wrong produces equations that look plausible and behave nothing like the original, which is a failure that only shows up when somebody builds a replacement and it does not work. The mode is set by architecture bits in the file and, on many parts, is also inferable from the pin usage on the board: a clock on pin one and an enable on pin eleven means the registered configuration is in play.
From equations to something that runs
The output of the decode is a set of Boolean equations, one per output, in sum-of-products form. Three things follow from that, and all three are worth doing before touching a soldering iron.
Minimise and sanity-check. Feed the equations through a logic minimiser and compare against the original term count. A design that shrinks from twenty terms to four was probably mis-decoded.
Verify by exhaustive simulation. Sixteen inputs is sixty-five thousand combinations. A simulator covers all of them in well under a second, and comparing the re-derived equations against the decoded array row by row eliminates the entire class of transcription error that this work is prone to.
Choose a target. A modern CPLD accepts the equations directly. A small microcontroller can implement them in software if the timing allows, which is usually the case for a slow glue-logic design and never the case for a fast one. Knowing which kind of design this is determines the answer.
Why this matters for legacy products
These parts sit in equipment that was designed in the late eighties and nineties and is still in service: industrial timers, machine tool interlocks, instrumentation front panels, bus arbiters. The logic is trivial by modern standards and completely undocumented, and the original designer is retired.
A recovered equation set is a complete specification. It is more portable than a firmware image, more readable than a schematic someone reverse-drew from a photograph, and it can be re-implemented on a part that is still manufactured. That is the whole value proposition, and it is why the effort of learning the fusemap format pays off on the first job.
Related reading
- ATmega1284 and what an image does not contain — the equivalent problem for a device that does contain a program.
- ATmega1284V and how initialised data sits in the image — tables versus code, in a different architecture.
- ATmega128PA and a fuse that changes the machine — another case where one bit redefines everything.
FAQ
Can a secured GAL16V8 be read at all? Not through the programming interface. The array is inaccessible while the security cell is set, and whether that cell can be cleared varies by manufacturer and process.
How long does a decode take? The mechanical part is quick. The interpretation — deciding what each term is for — is the work, and it typically runs to a few hours for a design of this size.
Is the electronic signature useful? Often. It frequently holds a part number, a date code, or a pattern the designer chose, and it survives independently of the array.
Can the equations be rebuilt from a working board by probing? For slow designs, sometimes, by driving inputs and observing outputs. That produces a truth table, not equations, and it misses any state the device holds internally.
Conclusion
A logic device is a table of connections, and the job is to turn the table back into equations that a person can read and a modern part can implement. The only real obstacle is one bit, and everything after it is methodical.
ATmega640A: Reading a Revision You Cannot Look Up
Documentation lags silicon. A revision that left the fab last quarter may have no errata sheet worth reading, no change list, and a device signature byte that no tool recognises. The temptation is to treat such a part as “the same chip as last time” and proceed — and most of the time that works, which is exactly why the exceptions are expensive.
The alternative is to build a description of the part from measurements. Three of them are enough to catch the differences that matter.
Measurement one: the signature
Three bytes, read before anything else. Vendor and family are stable; the third byte is the model. When a revision changes nothing observable, the third byte is unchanged and the toolchain proceeds without complaint.
When it does change, the read still succeeds — the tool is what fails. Recording the three bytes is worth doing even when the part is recognised, because it is the one piece of evidence that identifies the die later in the process, and it takes a second.
Measurement two: the fuse and lock readback
The fuse map is stable across revisions, which makes it a calibration reference. Read it, record it, and compare it with what the image says should be there.
A discrepancy between the fuse byte you read and the assumptions in the firmware is informative. It can mean the device was reprogrammed in the field with different settings, that the part came from a different production run, or that the fuse byte is being read through a marginal interface. All three are worth knowing before an image is interpreted.
The lock byte readback is the same kind of evidence: it states the protection mode as the hardware sees it, which is the only authority on the question of whether a read is permitted.
Measurement three: erase behaviour
Erase the part and read it back. On a healthy part the array is uniformly FF and the lock bits are clear. Deviations from that, in order of frequency:
| Observation after erase | Interpretation |
|---|---|
Uniform FF, locks clear |
Normal |
Uniform FF, locks still set |
Erase did not complete; supply or timing |
Isolated non-FF bytes |
Partially erased page; charge pump or supply |
Some pages FF, some unchanged |
Erase aborted partway; bus or clock fault |
That table is the most useful diagnostic in the whole sequence, because it separates three things that otherwise look identical: a working part, a marginal setup, and a damaged die.
It also has a cost that must be stated plainly — the erase removes whatever was there. It belongs after the read has been attempted and after the decision that the contents are not recoverable by other means.
What the image says about the revision
Firmware written for a specific silicon revision often contains a workaround. Workarounds are recognisable: a redundant register write, a delay loop before a peripheral is enabled, a check of a status bit that the datasheet says is fixed.
Finding one in a recovered image is evidence about the die. A delay inserted before enabling a specific peripheral implies the revision needed it. That kind of code-level fingerprint is sometimes the only documentation a revision has.
It also matters for reproduction. An image restored onto a newer part carries workarounds that are unnecessary; an image restored onto an older part may be missing one that is essential. Neither failure mode is visible without knowing which revision the image was written for.
The practical stance
Treat an unidentified revision as a part whose electrical envelope is unknown rather than as a part identical to its predecessor. Concretely:
- Read at the design rail, never at the bottom of the range.
- Verify every page twice.
- Record signature, fuses, and lock byte with the image, not separately.
- Note the date code from the package, which is often the only revision evidence available.
The date code is underrated. It is printed on the part, it survives every toolchain’s indifference, and it distinguishes two otherwise identical units.
Related notes
- ATmega640 and the external bus — the shape question that precedes any revision question.
- ATmega640P and the three interfaces — which door the fuses left open.
- ATmega644A and revision footprints — the same problem on a smaller die.
FAQ
Does an unknown signature mean the part is counterfeit? No. It means the die is not in the tool’s table. Counterfeits usually reproduce a known signature rather than an unknown one.
Can I read a revision-specific fuse field safely? Reading is safe. Writing a fuse field whose meaning you are unsure of is not, because some settings remove the interface you would need to undo them.
Is the date code a reliable revision indicator? It is a production indicator. Two units with different date codes may still be the same revision, but two different revisions cannot share a date code.
Should workarounds be removed from a recovered image? Only with an understanding of what they compensate for. Removing one that was still necessary produces an intermittent fault that is hard to trace.
Conclusion
An undocumented revision is not a mystery, it is an unmeasured part. Signature, fuse readback, and erase behaviour describe it well enough to work with, and the workarounds inside its firmware often document it better than any published note. The mistake to avoid is assuming continuity — that is the assumption whose failures cost the most.
ATmega640P: Three Ways In, and the Fuse That Removes One
A microcontroller with a lot of pins can afford more than one programming interface, and this family does. There is serial programming over the SPI pins, there is JTAG over four dedicated pins, and there is the high-voltage parallel mode that every AVR supports as the last resort.
Three doors, three different sets of conditions, and a fuse that can close one of them for a reason that has nothing to do with security.
The three interfaces, compared
| Interface | Pins used | Closed by | Can it clear lock bits |
|---|---|---|---|
| Serial ISP | Reset, SCK, MOSI, MISO | SPIEN unprogrammed, RSTDISBL set | no |
| JTAG | TCK, TMS, TDI, TDO, Reset | JTAGEN unprogrammed, lock mode 2 | no |
| Parallel (HVPP) | Reset plus the data and control bus | nothing, always available | no |
The last column is the important one and it is the same for all three: no interface clears lock bits without an erase. The interfaces differ in how you get in, not in what you are allowed to do once inside.
The JTAG fuse is a pin-count decision
JTAG occupies four pins. On a part where those four pins are also port pins with useful peripherals behind them, a designer counting pins will disable JTAG to get four GPIOs back. The fuse is called JTAGEN and it is programmed by default — enabled — so disabling it is a deliberate act.
The result is a device that can only be entered over serial programming. That is usually fine, until the same designer also needs the reset pin as an output and sets RSTDISBL. Then both convenient doors are closed and only the parallel interface remains.
None of that is defensive design. It is pin budgeting, and it produces a configuration that looks deliberate from the outside.
What JTAG offers that ISP does not
For examination purposes JTAG has one genuine advantage: it can halt the core and inspect registers and memory while the firmware runs. On an unlocked part that is a far more informative view than a static dump, because it shows what the code does rather than what it says.
Two caveats. The debug capability is gated by the lock bits — in mode 2 the JTAG programming interface is still reachable enough to erase, but the debug access is gone. And the on-chip debug system has its own enable fuse on some members, separate again from JTAGEN.
So “the part has JTAG” is not the same as “the part can be debugged”. The fuse byte decides, and it decides separately for programming and for debugging.
Why the parallel interface always survives
The parallel interface exists because a factory needs a way to program a part whose serial interface might be disabled by a mistake in the fuse settings. It is the recovery path for the fuse byte itself: a part with SPIEN off and JTAGEN off can still be reached in parallel mode, and the fuses can be restored.
It is also the only interface that works on a completely blank part with no clock configured, which is why it is used in production programming rather than serial programming for high volume.
What it does not do is bypass protection. A parallel programmer reads the lock byte, sees mode 2, and behaves exactly as the serial one would: it can erase, and the erase takes the contents.
Establishing which doors are open
Before any read attempt, four cheap measurements:
- Supply at the socket, at the design rail.
- Signature over whichever interface responds. If serial fails, try JTAG before concluding anything.
- Fuse byte. SPIEN, JTAGEN, RSTDISBL — three bits that explain most “no device” reports.
- Lock byte. Determines whether a read is even permitted.
Only after those four is a decision about the memory meaningful. Skipping them produces a conclusion about the die that is really a conclusion about the wiring.
The interpretation trap
A part that responds to signature reads but refuses flash reads is locked. A part that responds to nothing is unpowered, miswired, or fuse-disabled. Those are different problems with different costs, and the same programmer error message covers both.
The distinguishing observation is the fuse read. If the fuse read succeeds, the interface works and the lock byte is the obstacle. If the fuse read fails too, the interface itself is closed or the connection is wrong — and the fuse byte, ironically, is the only thing that could tell you which.
That circularity is why the parallel interface exists, and why it is worth having an adapter for it before a locked device arrives rather than after.
Related notes
- ATmega640 and the external bus — the other thing that can make an image incomplete.
- ATmega640PA and the erase threshold — what happens to an erase at low voltage.
- ATmega644PA and RSTDISBL — the fuse discussed above, in detail.
FAQ
Which interface should I try first? Serial, because it needs the fewest connections. Then JTAG if the part has it and a fuse read is refused. Parallel only when both fail.
Can JTAG be used to read flash on a locked part? No. Debug access is removed by the lock bits; JTAG remains useful only to reach the erase command.
Does disabling JTAG improve security? Marginally, by removing a debug path. It is almost always done to recover four pins, not to protect anything.
Is the parallel adapter worth owning? If you regularly receive parts whose fuse history is unknown, yes. It is the only interface that cannot be closed by a fuse.
Conclusion
Three interfaces, three closure conditions, one shared constraint: none of them bypasses the lock byte. The practical work is establishing which doors remain open before drawing any conclusion about the die, and the fuse byte is the only measurement that answers it — which is exactly why a parallel adapter earns its place on the shelf.
ATmega1284V: Initialised Data Appears Twice in the Image
Point a disassembler at an AVR image and it will decode everything as instructions, because that is what it was asked to do. Somewhere in the middle of the output there will be a region that decodes into instructions that make no sense — reads from implausible addresses, jumps into the middle of themselves, opcodes that the part does not implement.
That region is usually not corruption and not encryption. It is data that the programmer never intended to execute, and the reason it sits in the flash at all is one of the more useful pieces of structure in an AVR image.
Why the data is there
The AVR has a modified Harvard architecture: program memory and data memory are separate address spaces. A global variable lives in SRAM, but its initial value has to survive a power cycle, and SRAM does not. So the compiler stores the initial value in flash, in a section that the linker places after the code, and generates a startup routine that copies it into SRAM before main runs.
The same routine zeroes the block of variables that start at zero, which need no stored value at all. Between the two, the startup block defines the entire static memory layout of the program.
| Section | Lives in | Contains | Executable |
|---|---|---|---|
.text |
Flash | Instructions | Yes |
.data load image |
Flash | Initial values of globals | No |
.data run address |
SRAM | The same values after copy | No |
.bss |
SRAM only | Zero-initialised globals | No |
.rodata |
Flash | Constants, string literals | No |
.progmem |
Flash | Tables the code reads by address | No |
Finding the copy loop
The loop is easy to recognise once you know what to look for. It is one of the first things after the reset vector, it reads from flash using the load-from-program-memory instruction, it writes to SRAM through a pointer register pair, and it terminates on a comparison against an end address.
Three values in that loop are the whole map:
- The flash source address, which tells you where the data block begins.
- The SRAM destination address, which tells you where the variables live.
- The length, either as a count or as an end address, which tells you how big the block is.
Write those three down. The data block is now a known region that must be excluded from disassembly, and the SRAM window is a known range that the code will address by direct load and store throughout.
The zeroing loop immediately after
The second loop writes zeros to a different SRAM range. That range is .bss, and its size tells you something practical: how much of the part’s SRAM the design uses. On a device with a generous SRAM this is a fast way to see whether the firmware is tight or comfortable, and a tight firmware tends to be hand-optimised in ways that make the code easier to read.
Why the data block matters to the analysis
Two reasons, and both save hours.
It removes false instructions from the output. A disassembler that decodes a block of initial values produces hundreds of lines of nonsense that a reader has to evaluate and discard. Cutting the region out at the start means everything remaining is either code or a table you have already identified.
It reveals the program’s vocabulary. Initialised globals are rarely random bytes. They are configuration structures with recognisable contents: a baud divisor, a timeout in milliseconds, a set of default setpoints, a string with a version number. Reading the data block as data — hex plus ASCII — frequently produces more insight per minute than reading the code, because the values are the design decisions.
Where the compiler puts the rest
Three other regions cause confusion and are worth locating deliberately.
String literals and constants. Placed with the code but never executed. They are recognisable by producing readable ASCII at a hex offset, and by being referenced through the load-immediate-address instructions rather than by a jump.
Tables read by address. Lookup tables, font bitmaps, segment maps, CRC tables. These decode as instructions and are the most common source of “why does the firmware jump into a table” confusion. A table is usually referenced by a Z register load, not by a call, and that reference is the way to find its boundaries.
Interrupt vector table and the boot section. Fixed by the silicon rather than the compiler, and already covered by the vector analysis. The boot section, if present, is a separate program with its own startup and possibly its own data block, so the copy-loop pattern appears twice.
Reconstructing a map
The exercise that pulls all of this together is to produce a memory map of the image: code from here to here, data block here, strings here, tables here, boot section here. It is not a reconstruction of the source, but it is the closest thing to a table of contents that a binary will give you, and every later question is answered faster with it in hand.
The map also has a diagnostic use. Two images of the same product from different firmware versions should differ in code and in strings and should have nearly identical data blocks. If the data blocks differ wildly, the two versions were built with different compiler settings or different configurations, which is worth knowing before comparing behaviour.
Related reading
- ATmega1284P and the vector table as an index — the fixed part of the map.
- ATmega1284 and what the flash image does not contain — memory layout from the other direction.
- ATmega128P and layout past the sixty-four kilobyte line — where the load instructions change form.
FAQ
Can the two copies ever disagree? Only if the firmware writes to those variables, which is normal. The flash copy is the initial value; the SRAM copy is the current one.
What if there is no copy loop? A program with no initialised globals has nothing to copy, which is common in small firmware. The absence is itself informative.
Does the compiler always place the data block immediately after the code? The linker decides, and it usually places it after the code region. The copy loop’s source address is authoritative regardless of where the block sits.
Why do constants sometimes execute correctly by accident? Because they occasionally decode into valid instructions that do not crash. That is worse than an obvious crash, since it produces plausible but wrong analysis.
Conclusion
Two copies of the same bytes, one of them patently not code, and a three-value loop that connects them. Finding that loop first turns an unreadable 128 KB into a map with regions, and regions are what make the rest of the work tractable.
Decode Locked NRF52833-QDAA-R7 Source Code: QFN40 512 KB Read
The NRF52833-QDAA-R7 carries the same nRF52833 silicon as the rest of the family, an Arm Cortex-M4 with FPU at 64 MHz, 512 KB of flash and 128 KB of RAM in a QFN40 5 x 5 mm body, and the R7 suffix only names the 7-inch reel container it ships on. When the flash has been pulled and the image is sitting there with no symbol table attached, the job is to decode locked NRF52833-QDAA-R7 source code into something that can be compiled again, and the difficulty is entirely in what the image does not say about itself.
The container code changes nothing
Nordic’s ordering codes put the shipping format in the last letters, so R is 13-inch tape and reel, R7 is a 7-inch reel and T is a tray, and the silicon, package, memory and temperature rating are identical across all three. A recovery on the NRF52833-QDAA-R7 therefore produces a binary that also fits the R and T parts.
What a 512 KB image gives you
A Cortex-M4 image starts with a vector table, and that table anchors everything after it. The initial stack pointer bounds the RAM the firmware was linked for, the reset vector points at the startup code, and each entry after that maps one exception or interrupt to its handler, which is how the interrupt structure becomes legible. From the handlers the call graph extends outward, and the branch targets inside each function mark its boundaries. Where the compiler has inlined a small helper, the boundaries blur, so the call graph is read as a graph. Literal pools holding string and constant data sit between functions, and each one marks the tail of the code block before it, fixing the function edges from the other direction.
Reading the reconstruction signals
The parts of the image that carry structure are not obvious at the start, so each is read against what the hardware can prove. Reading them together is what makes it possible to decode locked NRF52833-QDAA-R7 source code with reasonable confidence, because a constant pool carrying the PWM channel masks confirms a register address that was ambiguous on its own.
| Image region | What it yields | Confidence |
|---|---|---|
| Vector table | Interrupt structure, RAM bounds, reset path | High |
| Call graph and branch targets | Function boundaries and call relationships | High |
| Literal pools | Constants, strings, peripheral register masks | Medium |
| Peripheral register addresses | Which hardware each routine drives | Medium |
| SoftDevice area | Encrypted at rest, not decompilable | None |
Naming the peripherals from the addresses
The nRF52 peripheral set is wide and its register map is fixed, so a word read from a constant address identifies the block it came from. PWM, SAADC, SPIM, TWIM, UART, TIMER, RTC and GPIO accesses are all recognisable in the instruction stream by their address ranges, and that alone turns a column of constants into a map of what the firmware drives. The four 4-channel PWM units with EasyDMA, the 12-bit 200 ksps ADC, the 64-level comparator, the temperature sensor and the two UARTs each show up as their own cluster of accesses. Our dual probe and flying probe notes cover reading those pads.
Why this peripheral set complicates things
Three things make an nRF52 image harder to read back as source than a plain microcontroller. First there is the programmable peripheral interconnect, so a task on one peripheral can be triggered by an event on another without the CPU ever issuing a transfer, and that relationship lives in registers rather than in code, so it has to be reconstructed from access patterns. Second, EasyDMA means the descriptors are data rather than code, laid out in RAM and pointed at by registers, so a DMA-driven buffer never appears as instructions and has to be recovered as a structure. Third, the RF register block is largely invisible from the disassembly, because most radio configuration happens in hardware.
The region that cannot be rebuilt
One part of the 512 KB image is out of reach for a different reason. The SoftDevice Bluetooth stack area is delivered encrypted and is decrypted into RAM at boot, so a debugger read of that flash region returns ciphertext and it cannot be decompiled. It is not part of the reconstructed source, and no amount of work on the remainder will change that. We state it plainly in the report rather than shipping placeholders that pretend otherwise.
What you get back
You receive the flash binary image of the NRF52833-QDAA-R7, a disassembly-based source reconstruction organised into a compilable tree with the vector table, the interrupt map and the peripheral assignments documented, and a verification report recording which regions are proven code and which are unreachable encrypted content. The same bench handles the QDAA-R encrypted flash attack and the nRF52832 source rebuild, while a flash recovery pass confirms the image is whole first. The same technique covers the STM32G473RCT6 data on other silicon.
ATmega861V: The Clock Prescaler That Changes Every Constant
Timing constants in embedded code are rarely expressed in seconds. They are loop counts, and a loop count is only meaningful in relation to the clock that drives it. Change the clock and every count becomes wrong by the same factor — silently, and without a single instruction changing.
On this family the clock can be divided by a prescaler at start-up, which means the same code and the same oscillator can produce timing that differs by nearly an order of magnitude depending on how two bits were set.
Two settings, one clock
The effective clock is the oscillator frequency divided by the prescaler. Both are set in the same byte, and both can be changed at run time.
| Prescaler | Effect on a delay loop | Effect on a bit-banged bus |
|---|---|---|
| divide by 1 | reference timing | reference timing |
| divide by 8 | eight times slower | eight times slower |
| divide by 64 | sixty-four times slower | likely outside the protocol window |
| divide by 256 | almost certainly a mistake | certainly outside it |
The last row is not hypothetical. A device configured for the slowest division is either a very low-power design or a misconfiguration, and the firmware’s constants tell you which: a design that intended the division has constants scaled accordingly.
Why this is a reading problem
The prescaler setting is made in the first few instructions after reset, which makes it part of the initialisation sequence that any reconstruction must read first.
Two failure modes follow if it is ignored:
A reconstruction that assumes the default. The reconstructed code runs at the wrong speed, and every timing-dependent behaviour differs. The code is correct and the device behaves differently.
A misread of intent. A loop of ten thousand iterations looks like a very long delay until you notice the prescaler divides by 256, at which point it looks like a reasonable one. The same number means two different things.
Where the constants give it away
Firmware written for a specific effective clock has a consistent internal arithmetic. Three signals confirm the intended value:
- Delay loops with round counts at the effective frequency, not at the oscillator frequency.
- Serial bit periods expressed as counts that divide evenly into the effective clock.
- Timer prescaler settings chosen so that an overflow corresponds to a meaningful interval.
When all three agree, the effective clock is established. When they disagree, the code was probably ported from a build with a different setting, and the disagreement itself is a finding.
The V suffix in the picture
The low-voltage grade narrows the frequency range at the bottom of the supply range. A design that runs at full speed at five volts may exceed the specification at 1.8, which is why low-voltage products often set a prescaler even though the oscillator is unchanged.
That makes the prescaler a voltage-driven decision as much as a power one, and it means the setting can legitimately differ between two products built on the same part.
Reading order
- Signature and fuses. The prescaler default comes from a fuse.
- Array read, verified.
- Initialisation: clock source selection, then prescaler.
- Compute the effective clock and record it.
- Only then interpret delay loops and bit periods.
Step 4 is where the analysis becomes quantitative. Without it, every timing constant is a number without units, and numbers without units are the most common reason a reproduction behaves differently from the original.
Related notes
- ATmega861P and hex containers — the same part from the file side.
- ATtiny44V and clock fuses — the fuse that picks the source.
- ATmega168PV and calibration — why the oscillator itself is trimmed.
FAQ
Does the prescaler affect the programming interface? Yes, indirectly: a divided clock slows the target’s response, which matters at high programming speeds.
Can it be changed at run time? Yes, and some firmware does so to save power between operations.
Why would a product run at a divided clock? Lower current and a wider usable voltage range at the cost of speed.
Do the constants survive a plan to run faster? No. Every timing constant has to be rescaled, which is why recording the effective clock matters.
Conclusion
One bit divides the clock and rescales every constant in the program. Reading the prescaler before interpreting timing turns a set of meaningless loop counts into measurements, and it explains why identical code can behave differently on two builds of the same part.
