Archive for the ‘Reverse Engineer Microcontroller’ Category
Reverse ATmega324 secured flash memory
A request to reverse ATmega324 secured flash memory begins with the fact that ATmega324 carries 32 KB of in-system programmable flash and 2 KB of SRAM and runs at 20 MHz in a 40-pin PDIP / 44-lead TQFP body. The work starts with the lock byte and the fuse bytes, because a megaAVR guards its arrays with lock bits rather than a numeric readout level.
reverse ATmega324 secured flash memory: reading the protection before the array
A classic megaAVR protects its memory with a lock-bit byte rather than a graded level. LB1 and LB2 are the memory lock bits: with both unprogrammed the flash, EEPROM and fuse bytes are readable over the programming interface, programming either one blocks further writes and verification, and programming both closes read-back so an external tool sees only blank words for the arrays. BLB0 and BLB1 are separate boot lock bits that govern what the boot section and the application section may do with SPM writes and LPM reads, so a firmware-assisted dump is either enabled or walled off independently of the main lock bits. The fuse bytes sit beside the lock byte: CKSEL and SUT choose the clock, BOOTSZ and BOOTRST size and place the boot section, EESAVE decides whether a chip erase keeps the EEPROM, SPIEN enables serial programming and RSTDISBL repurposes the reset pin. The lock and fuse bytes stay readable while the arrays do not, which is why the first move on the bench is always a read of those bytes and never an erase.
how the ATmega324 memory is laid out
On the ATmega324 the 32 KB program array is written a page at a time and erased as a whole, with a boot section whose size is set by the BOOTSZ fuses. Beside it sits 2 KB of SRAM and 1 KB of data EEPROM, the latter being an independent array that a chip erase clears unless EESAVE was programmed. The only operation that clears the lock bits is a chip erase, and that same operation wipes the flash and, unless EESAVE is set, the EEPROM. The protection therefore comes down only at the exact moment the firmware disappears, and the 40-pin PDIP / 44-lead TQFP body changes nothing about that arithmetic because the array size is fixed by the ordering code rather than by the lead frame.
| ATmega324 recovery geometry | Value |
|---|---|
| Program flash | 32 KB, page-programmable, boot section by BOOTSZ |
| Data EEPROM | 1 KB, cleared by chip erase unless EESAVE |
| SRAM | 2 KB |
| Core and clock | AVR RISC at 20 MHz |
| Protection | lock bits LB1/LB2 and BLB0/BLB1, fuse bytes |
| Package | 40-pin PDIP / 44-lead TQFP, 40 pins |
the ATmega324 interface once protection is set
The part is reached over the in-system serial programming interface driven by the reset, clock and data pins, and the same wires carry the read of the fuse and lock bytes. What fails under a set lock byte is the array read: a programmer asking for flash or EEPROM receives blank words while the part still runs its firmware normally and returns its configuration bytes cleanly. The practical routes are a clean read while the lock byte is open, a firmware-assisted dump where the boot lock bits allow it, or a chip erase the customer must approve in writing.
choosing the route for reverse ATmega324 secured flash memory
Read the fuse and lock bytes first, then decide, because that result settles whether any firmware can be recovered at all. An open lock byte means a clean read over the programming interface and the heximal can be pulled directly, while a part with LB1 and LB2 both programmed leaves only the destructive erase as a route to a blank device. The ATmega324 is the 32 KB of flash device in a 40-pin PDIP / 44-lead TQFP body, so the capacity marking and the package settle the array size before anything is priced. The 40-pin body and the JTAG interface place it in the picoPower group. What survives the lock: the fuse and lock bytes themselves, the device signature and the calibration byte, the peripheral registers while the part runs, and the EEPROM if EESAVE was programmed before any erase.
comparing ATmega324 with its family
When a board arrives marked only with a partial code, the megaAVR family is the place to look, because its members share the same lock byte, the same fuse layout and the same erase coupling while differing in flash, SRAM, EEPROM, pin count and on-chip peripherals. Neighbouring members span 16 KB to 256 KB of flash with SRAM from 1 KB to 16 KB, and the low-voltage V grades trade clock speed for a wider supply range without changing the lock byte.
Our notes on break ic atmega128v heximal, break ic atmega169p code, break ic atmega169pv program and break ic atmega2561 program use the same bench sequence, and break ic atmega261p flash records the variant with the wider supply range.
what the customer receives from a reverse ATmega324 secured flash memory job
For a board that arrived as a reverse ATmega324 secured flash memory request, the deliverable is a confirmed capacity, a lock-byte state and a priced route agreed in writing before any destructive step, and our engineers read the fuse and lock bytes first.
Decode Secured STM32G473RCT6 Data: LQFP64 256 KB Read
The STM32G473RCT6 carries 256 KB of flash in a 10×10 mm LQFP64 body, and on this part the interesting content is often not the code but the data sitting alongside it. The G4 has one of the richest analog front ends anywhere: five 12-bit ADCs, seven comparators, six operational amplifiers with programmable gain, seven DAC channels and a voltage reference buffer. Any product built on that front end carries calibration tables, gain settings, offset values and sensor mapping in the same array as the control code. To decode secured STM32G473RCT6 data therefore means two distinct jobs: getting the bytes out of a sealed part, and then working out what each region of those bytes actually means.
Why the G4 makes data worth reading
Calibration data on a G4-based product is not a nicety. The op-amps and comparators have their own offsets and gains that shift with temperature and supply, and a controller that ignores the stored corrections produces a stable but wrong measurement. Vendors therefore store the correction tables at build time and often protect them. The same array also holds production data such as serial numbers, hardware revisions and customer configuration, which is why “data” recovery is a normal request here.
Getting the bytes out
At readout protection level 1 the debug port and the ROM bootloader both refuse the array, and the physical routes are the only ones left. A fault injected during boot, targeting the security check, is the usual first attempt; where the check resists, the LQFP64 body is opened chemically and the die addressed while the board keeps running. The power glitch and clock glitch methods are documented separately. The flash is the ECC-protected dual-bank type, so the capture records the live bank and corrects marginal cells as it reads.
The 10×10 mm body gives the die enough room that the compound can be taken back to the silicon without touching the lead frame, and the part is kept soldered and powered through the work. That last point is what makes the fault possible: the check that gates the array is evaluated in the first instants after reset, and on a 170 MHz part that window is only microseconds wide.
The alternative of perturbing the supply or the clock widens the same comparison window without opening anything, and because a failed attempt leaves the part locked rather than harming it, those attempts are tried first whenever the leads are still accessible. Our power glitch and clock glitch notes cover both.
Mapping the regions
Once the image exists, the work is to separate code from configuration from calibration. The regions usually follow the layout below.
| Region | Typical location | Content | Use |
|---|---|---|---|
| Vector table | Start of flash | Handler addresses | Confirms the image is real |
| Bootloader | Low addresses | Update and validation logic | Protocol recovery |
| Application | Main body | Control loops, drivers | Source reconstruction |
| Calibration tables | Upper region | ADC and op-amp coefficients | Measurement accuracy |
| One-time programmable | Separate 1 KB | Serial and licence data | Identity |
A flash recovery pass confirms the file is whole before this mapping begins, since a short capture would produce regions that look plausible but are not.
Turning tables back into settings
The calibration data is rarely stored in a form that can be read directly. It appears as a table of coefficients referenced by index, or as a polynomial whose coefficients are packed into bytes that also carry a range flag. Reconstructing it means finding the lookup structure, identifying the field layout, and checking the values against what the hardware should produce. Some fields are double-precision and some are integer scaled, and mixing them up is the common failure. Where the vendor stored the values in a protected sub-region, the physical read step is what makes them available in the first place.
The check that the decode is right is made against the hardware rather than against the file. With the recovered coefficients programmed back, the same measurement is taken and compared with the reading the original board produced, so a table that has been misread or mis-scaled shows up as a number that does not agree. The same pass confirms that the image belongs to this particular unit rather than to a similar model.
What you receive
You receive the 256 KB flash binary image of the STM32G473RCT6, the option bytes, a region map showing where code, configuration and calibration tables sit, and the decoded calibration values with their scales and units identified. The same bench handles the STM32G473RET6 program recovery and the STM32G474RCT6 data decap.
Reverse Engineering Microprocessor ATmega1284PV Embedded Firmware
We can reverse engineering Microprocessor ATMEGA1284PV embedded firmware, please view the Microprocessor ATMEGA1284PV features for your reference:
These bits select the voltage reference for the ADC, as shown in Table 19. If these bits are changed during a conversion, the change will not go into effect until this conversion is complete (ADIF in ADCSR is set).
Whenever these bits are changed, the next conversion will take 25 ADC clock cycles. If active channels are used, using AVCC or an external AREF higher than (AVCC – 1V) is not recommended, as this will affect ADC accuracy.
The internal voltage reference options may not be used if an external reference voltage is being applied to the AREF pin. The ADLAR bit affects the presentation of the ADC conversion result in the ADC Data Register.
If ADLAR is cleared, the result is right-adjusted. If ADLAR is set, the result is left-adjusted. Changing the ADLAR bit will affect the ADC Data Register immediately, regardless of any ongoing conversions after reverse engineering Microprocessor ATMEGA1284PV embedded firmware.
For a complete description of this bit, see “The ADC Data Register. The value of these bits selects which analog input is connected to the ADC. In case of differential input (PB3 – PB4), gain selection is also made with these bits. Selecting PB3 as both inputs to the differential gain stage enables offset measurements.
Refer to Table 20 for details. If these bits are changed during a conversion, the change will not go into effect until this conversion is complete (ADIF in ADCSR is set). Writing a logical “1” to this bit enables the ADC. By clearing this bit to zero, the ADC is turned off if reverse engineering Microprocessor ATMEGA1284PV embedded firmware.
Turning the ADC off while a conversion is in progress will terminate this conversion. In Single Conversion mode, a logical “1” must be written to this bit to start each conversion. In Free Running mode, a logical “1” must be written to this bit to start the first conversion.
When the conversion completes, ADSC returns to zero in Single Conversion mode and stays high in Free Running mode. Writing a “0” to this bit has no effect. When this bit is set (one), the ADC operates in Free Running mode. In this mode, the ADC samples and updates the data registers continuously after reverse engineering Microprocessor ATMEGA1284PV embedded firmware.
Clearing this bit (zero) will terminate Free Running mode. If active channels are used (MUX2 in ADMUX set), the channel must be selected before entering Free Running mode. Selecting an active channel after entering Free Running mode may result in undefined operation from the ADC when reverse engineering Microcontroller.
Decrypt IC ATmega640P Secured Code
We can decrypt IC ATMEGA640P secured code, please view the IC ATMEGA640P features for your reference:
Digital circuitry inside and outside the ATmega640P generates EMI, which might affect the accuracy of analog measurements. If conversion accuracy is critical, the noise level can be reduced by applying the following techniques:
1. The analog part of the ATmega640P and all analog components in the application should have a separate analog ground plane on the PCB. This ground plane is connected to the digital ground plane via a single point on the PCB.
2. Keep analog signal paths as short as possible. Make sure analog tracks run over the analog ground plane, and keep them well away from high-speed switching digital tracks before Decrypt IC ATmega640P Secured Code.
3. Use the ADC noise canceler function to reduce induced noise from the CPU.
4. If some Port B pins are used as digital outputs, it is essential that these do not switch while a conversion is in progress.
All AVR ports have true read-modify-write functionality when used as general digital I/O ports. This means that the direction of one port pin can be changed without unintentionally changing the direction of any other pin with the SBI and CBI instructions.
The same applies for changing drive value (if configured as output) or enabling/disabling of pull-up resistors (if configured as input). Port B is a 6-bit bi-directional I/O port when Decrypt IC ATmega640P Secured Code.
Three data memory address locations are allocated for Port B, one each for the Data Register – PORTB, $18, Data Direction Register – DDRB, $17, and the Port B Input Pins – PINB, $16. The Port B Input Pins address is read-only, while the Data Register and the Data Direction Register are read/write.
Ports PB5..0 have special functions as described in the section “Pin Descriptions” on page 4. If PB5 is not configured as external reset, it is input with no pull-up or as an open-drain output.
All I/O pins have individually selectable pull-ups, which can be over- ridden with pull-up disable. The Port B output buffers on PB0 to PB4 can sink 20 mA and thus drive LED displays directly before decrypt IC secured code.
PB5 can sink 12 mA. When pins PB0 to PB4 are used as inputs and are externally pulled low, they will source current (IIL) if the internal pull-ups are activated after BREAK IC.
Assess PIC24FJ16GA002 protected firmware
A request to assess PIC24FJ16GA002 protected firmware begins with the fact that PIC24FJ16GA002 carries 16 KB (5.5K x 24 instruction words) of flash, 4 KB of SRAM and no data EEPROM in an 28-pin SPDIP / SOIC / QFN body. The work starts with the FGS configuration register, because the PIC24FJ64GA004 family treats the whole program array as one block controlled by a single GCP bit.
the first read in a assess PIC24FJ16GA002 protected firmware job
The PIC24FJ16GA002 is described by the PIC24FJ64GA004 Family Data Sheet DS39881. Unlike the later segmented families, this generation treats the on-chip program memory space as a single block. Code protection for that block is controlled by one configuration bit, GCP, in the FGS register: when GCP is programmed to zero it inhibits external reads and writes of program memory, while normal execution continues unaffected because the CPU fetches its own instructions internally. Write protection is controlled separately by the GWRP bit, which blocks internal write and erase operations. The configuration words and the device identification registers remain readable, which is why a protected sample can still be identified. Clearing GCP is not non-destructive: the programming specification states that a bulk erase in ICSP mode is the only way to return a code-protect bit from zero to one, and that same operation removes the entire user program.
PIC24FJ16GA002 flash array and the configuration bit coupling
On the PIC24FJ16GA002 the 16 KB (5.5K x 24 instruction words) of flash sit beside 4 KB of SRAM and no data EEPROM in an 28-pin SPDIP / SOIC / QFN body with 28 pins. Program memory uses 24-bit instruction words, so a heximal export has to preserve the word width rather than a byte-for-byte image of the quoted kilobyte capacity. The 16-bit PIC24 core at 32 MHz and 16 MIPS with PPS and PMP sets instruction timing, and the 28-pin package fixes how many port pins reach the board.
| PIC24FJ16GA002 recovery geometry | Value |
|---|---|
| Program memory | 16 KB (5.5K x 24 instruction words) of flash |
| Data memory | 4 KB of SRAM, no data EEPROM |
| Core and clock | 16-bit PIC24 core at 32 MHz and 16 MIPS with PPS and PMP |
| Protection | GCP code-protect bit and GWRP write-protect bit in the FGS configuration register |
| Programming path | ICSP over PGC and PGD with VPP on MCLR, plus JTAG boundary scan |
| Package | 28-pin SPDIP / SOIC / QFN, 28 pins |
the PIC24FJ16GA002 programming interface once protection is set
In-circuit serial programming enters the device through the PGC and PGD pins with VPP on MCLR, and the family also implements a JTAG boundary-scan interface. A programmer can always read the configuration words and the device identification registers, and can report the device marking from the package. With GCP active an external program read returns no usable instructions, while GWRP blocks internal writes and erases; neither the programming interface nor the boundary-scan port becomes a path to the firmware. The legitimate routes are a clean read when both bits are open, a documented comparison against the customer’s archived build output, and a bulk erase authorised in writing by the owner because the program is lost in the same step.
a decision tree for assess PIC24FJ16GA002 protected firmware
Read the FGS configuration register first and record GCP and GWRP, because those two bits settle whether the array can be returned and whether it can be rewritten. An unprotected sample yields a complete program heximal plus the configuration words; a protected sample yields identification data only unless an archived build exists. The PIC24FJ16GA002 carries 16 KB (5.5K x 24 instruction words) of flash in an 28-pin SPDIP / SOIC / QFN body, so the device number and the package settle the array before anything is priced. Treating the request as a firmware assessment keeps the deliverable honest: the returned artifact is a documented device state, not a promise to alter the protection bits. What survives the protection: the configuration words, the device identification registers, the SRAM and peripheral registers while the part runs, the package marking and the customer’s archived programming file.
sibling parts of the PIC24FJ16GA002
When a board carries only a partial marking, the PIC24FJ64GA004 family is the place to look, because its members share the DS39881 data sheet, the single-block program memory, the FGS GCP and GWRP fields and the same bulk-erase coupling while differing in flash capacity, pin count, SRAM depth and the parallel port. Sibling PIC24FJ64GA004 family members span 16 KB to 64 KB of flash in 28-pin and 44-pin bodies, all sharing the DS39881 data sheet, the single-block map and the FGS GCP and GWRP fields. The configuration words plus the package marking settle which member is on the board before any protection work begins.
Comparable recoveries are documented in attack microchip mcu pic18f46k80 protective flash, attack microchip microcontroller pic18f26k80 protection, attack microchip pic18f13k22 microcontroller flash memory, attack microchip pic18f2525 processor memory and attack microchip pic18f45k20 mcu memory protection, each starting from the configuration read.
closing out a assess PIC24FJ16GA002 protected firmware request
For a board that arrived as a assess PIC24FJ16GA002 protected firmware request, the deliverable is a confirmed memory size, a recorded GCP and GWRP state and a priced route agreed in writing before any destructive step, and our engineers read the FGS configuration register first.
Decapsulate Locked STM32G473CCT6 Firmware: LQFP48 256 KB Recovery
The STM32G473CCT6 packs 256 KB of flash into a 7×7 mm LQFP48 body, so the silicon sits in the middle of a small package with a dense, regular pin ring around it. That geometry is the reason it appears so often on control boards with no second storage device fitted: the design fits around the MCU and the firmware stays resident. When that image is the only surviving copy and the readout port is closed, the productive answer is to decapsulate locked STM32G473CCT6 firmware and read the array off the exposed die.
Why the 48-lead body suits decap work
An LQFP48 package is large relative to the die it carries. The mould compound comes off a body roughly seven millimetres across, with the die a small fraction of that footprint, so the work is controlled removal of a large volume with a small target at the centre. On the STM32G473CCT6 the flash is a single die rather than a stack, so one careful etch exposes the whole array. The pin ring stays intact and the chip remains testable while the package is opened. This is the same principle behind our decapsulation service, applied where the goal is the flash contents rather than the algorithm.
What protection is actually in place
Protection on this part is layered, and knowing the layers tells you what a read attempt will produce. The table below lists the main gates a field unit may present.
| Gate | Effect on a read attempt | Recoverable without mass erase |
|---|---|---|
| RDP level 0 | Debug port and bootloader read freely | not applicable |
| RDP level 1 | Both SWD and system bootloader refuse the main array | yes |
| PCROP block | A code region is invisible to ordinary reads | yes |
| Write protection | Programming is blocked, reading is not | yes |
| RDP level 2 | Debug is permanently disabled | yes, by physical route |
None of these gates removes the data. They hide it from a software path, and every one is a decision made by hardware during boot that a physical attack can outrun. Regressing level 1 to level 0 would mass erase the array, which is why the image is taken out of the running part instead. A flash protection primer sets out why that trade is never worth making.
Reaching a live die under the check
Decapsulation on the STM32G473CCT6 is done while the board keeps running, which is what makes the later fault step possible. Chemical attack on the mould compound opens a window over the die, the package is still soldered, and the part still executes its boot sequence. The security decision happens early in that sequence, in the window between reset and the first call into user code. An optical fault injected into that window, precisely timed against a reference clock, can make the verification return a result the logic did not intend, and the debug window opens for the instants needed. Power and clock glitching attack the same decision from the supply side, and our notes on power glitches and clock glitch attacks describe both approaches.
Streaming the array out
Once the port answers, the 256 KB image of the STM32G473CCT6 reads out in one pass, and the option bytes come with it so the original lock state is documented rather than guessed. On the G4 the flash carries ECC, so a marginal cell is corrected during the read instead of copied with a silent error. The capture is taken twice and the passes compared; a read that closed halfway is caught and repeated rather than handed over as a short file. Because the G473 offers dual-bank flash with read-while-write, the tool records which bank was active at capture, which matters when the image later seeds a replacement part.
Verifying what came out
A recovered image is only useful if it is provably the firmware that ran. Vector table sanity, the reset vector address, the peripheral entries expected on this family, and the consistency of the option bytes against the observed lock behaviour all form the check. Where a bank swap was involved, the banks are reconciled so the delivered file matches the state the board actually ran. Our flash recovery workflow covers the same verification discipline, and the restore steps outline how a confirmed image is put back into working order.
What you receive
You receive the complete 256 KB flash binary image of the STM32G473CCT6, the option bytes recording the original protection state, and a verification report describing the route used and the checks applied. Where the goal is a spare part, the same confirmed image feeds a firmware clone for the STM32G473RCT6 data read and the STM32G473RET6 program recovery.
Decode Locked STM32G030K6T6 Memory: LQFP32 32 KB Read
The STM32G030K6T6 fills the middle of the G0 value line in a 32-lead LQFP32 body: an Arm Cortex-M0+ at 64 MHz with 32 KB of flash and 8 KB of SRAM, more pins than the TSSOP20 but fewer than the LQFP48. That footprint is common on control boards needing a few more peripherals without a bigger package, and it ships with read protection enabled and no archive kept. To decode locked STM32G030K6T6 memory you have to account for both the readout protection and the write protection, because they decide what the bootloader gives up.
The middle footprint and what it exposes
The LQFP32 carries the SWD debug pair, the USART bootloader pins and a reasonable set of GPIO, so the part looks reachable. The debug port links at the physical layer and then refuses the flash window, because the flash controller enforces the lock, not the wiring. There is no USB on the STM32G030K6T6, so no DFU entrance. Pin count changes nothing about the lock, which is why our flash protection methods notes treat the G0 family as one consistent scheme.
Option bytes and write protection together
The readout protection on the STM32G030K6T6 is only half of the option-byte story. The same bytes hold write-protection sectors that stop regions of flash being altered, and a decoded map has to record both. Reducing level 1 to level 0 triggers a mass erase, so the image is never traded for the unlock. Our lock-bit primer describes the same AVR fuse model, and our flash recovery never relies on a software unlock.
The USART bootloader decision
Because the system bootloader is ROM, it honours the RDP level before any user code runs, and on the STM32G030K6T6 the read-memory command declines where SWD does. Two interfaces, one verdict, so programmers get only error codes from a healthy, locked part. When the electrical route is closed we open the LQFP32 by chemical etch, keep the die live, and use an optical fault at the boot security check to hold the port open for the capture. The decapsulation service handles this body as readily as the STM32G030C6T6.
An LQFP32 at 7×7 mm leaves the die centred inside a generous body, so the compound can be taken back to the silicon without cutting between leads. The part stays soldered and powered throughout, which allows the fault to be aimed at a live boot sequence rather than a device that only answers a debugger. The security check is evaluated in the first instants after reset, so the fault has to land inside that window.
Where the sample resists the optical route, the bus can be probed directly. A perturbation of the supply or the clock can widen the comparison window without opening the package, and because a failed attempt leaves the part locked rather than damaging it, those are tried first whenever the leads are accessible. Our power glitch and clock glitch notes cover both.
What the protection state allows
| State | RDP level | WRP set | Readable path |
|---|---|---|---|
| Open | 0 | no | direct SWD |
| Locked | 1 | maybe | decap plus fault |
| Sealed | 2 | yes | probing only |
Reconstructing the decoded memory
After the 32 KB array is streamed out we lift it into a disassembly and map it against the G0 peripheral table, so vectors and registers read as structure rather than raw bytes. The vector table comes first, because on a 32 KB part the interrupt list is the clearest description of what the firmware does, and routines are separated using the call graph and literal pools. Peripheral registers sit at fixed addresses, so routines touching the two ADCs, the USART or the timers are identified by register footprint rather than by name.
The write-protection map matters as much as the code. A region that cannot be written on the original will also refuse a programming attempt on the replacement, a confusing failure if the map is not delivered. Recording which sectors were locked turns the recovery from a raw dump into something reproducible. Where power or clock glitching is the cleaner attack, our power glitch and clock glitch notes describe the timing windows. The neighbouring STM32G030C8T6 program clone follows the same decode.
What the decoded result contains
You receive the complete 32 KB binary, the option-byte record covering both RDP and write protection, and a verification report confirming both read passes matched. A disassembly-based source reconstruction is included where understanding the logic was the aim. Where the goal is reproduction, the verified image is written to a blank part through our firmware cloning process, and the STM32G030K8T6 binary duplicate carries the same discipline into the 64 KB density.
Reverse Engineering Microcomputer ATMEGA2560L Eeprom
We can reverse engineering Microcomputer ATMEGA2560L eeprom, please view the Microcomputer ATMEGA2560L features for your reference:
Timer 2 can be programmed to count up or down when configured in its 16 bit auto-reload mode. This feature is invoked by the DCEN (Down Counter Enable) bit located in the SFR T2MOD.
Upon reset, the DCEN bit is set to 0 so that timer 2 will default to count up. When DCEN is set, Timer 2 can count up or down, depending on the value of the T2EX pin if reverse engineering Microcomputer ATMEGA2560L eeprom.
Figure 2 shows Timer 2 automatically counting up when DCEN = 0. In this mode, two options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 counts up to 0FFFFH and then sets the TF2 bit upon overflow.
The overflow also causes the timer registers to be reloaded with the 16 bit value in RCAP2H and RCAP2L. The values in RCAP2H and RCAP2L are preset by software. If EXEN2 = 1, a 16 bit reload can be triggered either by an overflow or by a 1-to-0 transition at external input T2EX after reverse engineering Microcomputer ATMEGA2560L eeprom.
This transition also sets the EXF2 bit. Both the TF2 and EXF2 bits can generate an interrupt if enabled. Setting the DCEN bit enables Timer 2 to count up or down, as shown in Figure 3. In this mode, the T2EX pin controls the direction of the count. A logic 1 at T2EX makes Timer 2 count up when reverse engineering Microcomputer eeprom.
The timer will overflow at 0FFFFH and set the TF2 bit. This overflow also causes the 16 bit value in RCAP2H and RCAP2L to be reloaded into the timer registers, TH2 and TL2, respectively if reverse engineering Microcomputer ATMEGA2560L eeprom.
A logic 0 at T2EX makes Timer 2 count down. The timer underflows when TH2 and TL2 equal the values stored in RCAP2H and RCAP2L. The underflow sets the TF2 bit and causes 0FFFFH to be reloaded into the timer registers.
The EXF2 bit toggles whenever Timer 2 overflows or underflows and can be used as a 17th bit of resolution. In this operating mode, EXF2 does not flag an interrupt.
Reverse ATmega640 locked flash memory
A request to reverse ATmega640 locked flash memory begins with the fact that ATmega640 carries 64 KB of in-system programmable flash and 8 KB of SRAM and runs at 16 MHz in a 100-lead TQFP body. The work starts with the lock byte and the fuse bytes, because a megaAVR guards its arrays with lock bits rather than a numeric readout level.
reading the protection state before you reverse ATmega640 locked flash memory
A classic megaAVR protects its memory with a lock-bit byte rather than a graded level. LB1 and LB2 are the memory lock bits: with both unprogrammed the flash, EEPROM and fuse bytes are readable over the programming interface, programming either one blocks further writes and verification, and programming both closes read-back so an external tool sees only blank words for the arrays. The fuse bytes sit beside the lock byte: CKSEL and SUT choose the clock, BOOTSZ and BOOTRST size and place the boot section, EESAVE decides whether a chip erase keeps the EEPROM, SPIEN enables serial programming and RSTDISBL repurposes the reset pin. The lock and fuse bytes stay readable while the arrays do not, which is why the first move on the bench is always a read of those bytes and never an erase.
what the ATmega640 array and erase cost mean
On the ATmega640 the 64 KB program array is written a page at a time and erased as a whole, with a boot section whose size is set by the BOOTSZ fuses. Beside it sits 8 KB of SRAM and 4 KB of data EEPROM, the latter being an independent array that a chip erase clears unless EESAVE was programmed. The only operation that clears the lock bits is a chip erase, and that same operation wipes the flash and, unless EESAVE is set, the EEPROM. The protection therefore comes down only at the exact moment the firmware disappears, and the 100-lead TQFP body changes nothing about that arithmetic because the array size is fixed by the ordering code rather than by the lead frame.
| ATmega640 recovery geometry | Value |
|---|---|
| Program flash | 64 KB, page-programmable, boot section by BOOTSZ |
| Data EEPROM | 4 KB, cleared by chip erase unless EESAVE |
| SRAM | 8 KB |
| Core and clock | AVR RISC at 16 MHz |
| Protection | lock bits LB1/LB2 and BLB0/BLB1, fuse bytes |
| Package | 100-lead TQFP, 100 pins |
the ATmega640 programming interface under protection
The part is reached over the in-system serial programming interface driven by the reset, clock and data pins, and the same wires carry the read of the fuse and lock bytes. What fails under a set lock byte is the array read: a programmer asking for flash or EEPROM receives blank words while the part still runs its firmware normally and returns its configuration bytes cleanly. The practical routes are a clean read while the lock byte is open, a firmware-assisted dump where the boot lock bits allow it, or a chip erase the customer must approve in writing.
the decision tree for a reverse ATmega640 locked flash memory job
Read the fuse and lock bytes first, then decide, because that result settles whether any firmware can be recovered at all. An open lock byte means a clean read over the programming interface and the heximal can be pulled directly, while a part with LB1 and LB2 both programmed leaves only the destructive erase as a route to a blank device. The ATmega640 is the 64 KB of flash device in a 100-lead TQFP body, so the capacity marking and the package settle the array size before anything is priced. The 100-pin body and the external memory interface are the traits that separate this member from the 64-pin siblings. What survives the lock: the fuse and lock bytes themselves, the device signature and the calibration byte, the peripheral registers while the part runs, and the EEPROM if EESAVE was programmed before any erase.
what the neighbouring parts tell you about ATmega640
When a board arrives marked only with a partial code, the megaAVR family is the place to look, because its members share the same lock byte, the same fuse layout and the same erase coupling while differing in flash, SRAM, EEPROM, pin count and on-chip peripherals. Neighbouring members span 16 KB to 256 KB of flash with SRAM from 1 KB to 16 KB, and the low-voltage V grades trade clock speed for a wider supply range without changing the lock byte.
Related work on break avr mcu attiny84 protected source code, break chip atmega1280 flash, break chip atmega162l firmware follows the same order of operations, while break chip atmega48pa firmware covers the next capacity step and break chip atmega48pa heximal the larger package.
what to hand back for a reverse ATmega640 locked flash memory request
For a board that arrived as a reverse ATmega640 locked flash memory request, the deliverable is a confirmed capacity, a lock-byte state and a priced route agreed in writing before any destructive step, and our engineers read the fuse and lock bytes first.
Bus Encryption: Why a Removed Flash Chip Reads as Noise
An external flash device is the easiest target on any board. Eight pins, a standard command set, and a reader that costs less than the coffee machine. Engineers assume that a device with external memory is therefore unprotected, and on a growing number of products that assumption is wrong in a specific and expensive way.
The protection is not a lock on the flash. It is encryption applied in the SoC’s fetch path, so that the flash holds ciphertext and the core sees plaintext.
Where the decryption happens
The decryptor sits between the external memory interface and the instruction fetch unit. Every read from the external bus passes through it, and the output is what the core executes.
The flash device is unaware of any of this. It receives ordinary read commands at ordinary addresses and returns whatever bytes are stored there. If those bytes were written by a programmer that also encrypted them, the flash contains ciphertext, and it contains it faithfully.
| Location | Sees | Holds |
|---|---|---|
| Flash array | Read commands and addresses | Ciphertext |
| External bus | Ciphertext in transit | Nothing |
| SoC fetch path | Ciphertext in, plaintext out | The key |
| Core | Plaintext | Nothing persistent |
The third row is the whole point. The key never leaves the SoC, and on most implementations it is not readable from anywhere inside the SoC either.
What the bus actually carries
Two architectures are common, and they differ in how much a bus capture is worth.
The first is address-based tweak encryption. The key is fixed and the address is mixed in, so the same plaintext at two different addresses produces two different ciphertexts, and moving a block to another address makes it undecryptable. The advantage is that the cipher can be a simple block cipher in counter mode with the address as the counter, which is fast enough for execute-in-place.
| Architecture | Granularity | Address bound | Cost |
|---|---|---|---|
| Counter mode with address | 16 bytes | Yes | Low, pipelined |
| Block cipher, whole image | 4 KB or larger | No | Moderate |
| Stream cipher, sequential | Byte | No, order bound | Lowest |
| Full image with header | Whole array | No | Requires load step |
The second architecture encrypts whole images with a header that carries a nonce and a key index. Here the SoC copies the image into RAM before running it, which rules out execute-in-place and limits the approach to devices with enough internal RAM.
The distinction matters for the attacker because address-bound ciphers cannot be relocated. A captured ciphertext block replayed at a different address decrypts to garbage, which closes the simplest attack on a naive scheme.
The test for encryption
The test costs one measurement and should be the first thing anyone does with a chip-off dump.
Read the image and compute entropy per erase block. A plaintext image built from compiled code has a characteristic entropy — high but not maximal, with visible structure where constant tables and string pools sit. An encrypted image sits flat at the maximum for the block size, block after block, with no structure at all.
| Entropy pattern | Interpretation |
|---|---|
| Variable, dips at string pools | Plaintext code |
| Flat maximum across the whole array | Encrypted, or compressed |
| Flat maximum on some regions only | Partial encryption |
| Flat zero or 0xFF | Erased, or never programmed |
The second row is ambiguous, and the way to resolve it is a known-plaintext check. Every image built for a Cortex-M or a similar core starts with a vector table whose first word is a stack pointer inside RAM. If the first sixteen bytes of the dump do not look like a vector table and the entropy is maximal, the image is encrypted rather than compressed, because compression leaves the first bytes intact — the loader needs them to know where to decompress to.
| Check | Plaintext | Compressed | Encrypted |
|---|---|---|---|
| First word is a RAM address | Yes | Yes | No |
| Entropy flat throughout | No | Yes | Yes |
| Recognisable strings present | Yes | Few | None |
| Decompressor code present | No | Yes | No |
Why the key is not in the flash
The obvious countermeasure against all of this would be to store the key with the data, and no competent design does it. The key lives in one of three places.
The first is one-time-programmable memory inside the SoC, programmed at the factory or during provisioning. It is readable by the decryptor and by nothing else, and the read path from the CPU is disabled.
The second is derived from a device-unique secret plus a stored identifier, so that the key differs per unit and a single leak compromises one device.
The third is supplied at boot by an external secure element, which is a separate chip with its own protections and its own attack surface.
| Key location | Readable from CPU | Per-unit | Consequence for the attacker |
|---|---|---|---|
| OTP in the SoC | No | Optional | SoC must be attacked, not flash |
| Derived from device secret | No | Yes | One dump is one device |
| External secure element | No | Yes | Second chip to attack |
| In the flash, obfuscated | Yes, eventually | No | Recoverable by analysis |
The fourth row exists in real products, usually in low-volume designs where the cost of proper key storage was judged too high. It is worth checking for, because a key stored in the flash with any kind of obfuscation is recoverable by static analysis of the image itself, and the whole encryption scheme then collapses.
What a chip-off read does and does not give
It gives a perfect, bit-exact copy of the ciphertext. That is not nothing. The ciphertext supports differential analysis if two versions of the firmware can be obtained, and it supports replay if the device accepts an image from the flash without further authentication.
It does not give code, strings, or a layout. Every technique in five flash layouts depends on structure that encryption removes, and the analysis has nothing to work with until the encryption is dealt with.
Routes that still work
When the array is encrypted, the useful attack surface moves.
Reading through the SoC is the first option, because the SoC decrypts. Any path that lets code run — a debug port, a DMA transfer, a loader uploaded through a boot mode — reads plaintext, and the encryption is bypassed without being broken. This is the route described in three physical routes into flash, and it is the reason encryption raises cost rather than closing the door.
The second option is to attack the decryptor’s control rather than its key. A glitch that suppresses the decrypt step, or that forces the fetch path into a bypass mode used for debugging, yields plaintext from an encrypted array. The search problem is the one in glitch attacks as a search problem, and the target is a single branch rather than a comparison loop.
The third option is to attack the key where it lives, which means the SoC rather than the flash, and which brings in everything in MCU source code decryption.
| Route | What it bypasses | Device survives |
|---|---|---|
| Read through the SoC | The encryption entirely | Yes |
| Glitch the decrypt control | The decrypt step | Usually |
| Attack the key store | The key | Usually |
| Static analysis of the image | Nothing, unless the key is in the image | Yes |
The boot header tell
One practical observation shortens the diagnosis. Encrypted-image designs usually leave a small plaintext region at address zero, because the boot ROM has to find the image, check its length, and locate the key slot before it can decrypt anything.
That header is twenty to sixty bytes of structured data followed by a hard transition into maximum entropy. The transition point is the size of the header, and the header fields are a length, a version, a nonce, and sometimes a checksum of the ciphertext.
| Field | Width | Purpose |
|---|---|---|
| Magic | 4 bytes | Identifies a valid image |
| Length | 4 bytes | Ciphertext size |
| Version | 2 to 4 bytes | Rollback control |
| Nonce or IV | 8 to 16 bytes | Per-image uniqueness |
Finding that header confirms the architecture in a few minutes and tells the analysis where the plaintext ends.
What the service does
We classify the protection from a chip-off dump and a boot capture, and report which route remains open.
| Deliverable | Content |
|---|---|
| Encryption classification | None, address-tweaked, whole-image, or partial |
| Entropy report | Per-block plot with the header boundary marked |
| Key location assessment | Which of the four storage options is in use |
| Viable route | Read-through-SoC, glitch, or key attack, with cost |
Where the answer is that the array is encrypted and the SoC is the only path in, we say so before any decapsulation is booked, because a perfect image of an encrypted array is one of the few outcomes in this field that is genuinely worthless.