Attack ATmega AVR Program: Flash, EEPROM and Fuses Are Three Devices
A microcontroller that presents three separate non-volatile memories inside one package is a convenience for the designer and a trap for anyone recovering it. The three areas have different access commands, different lifetimes, different failure mechanisms, and different relationships to the protection bits. Treating them as one storage area produces a deliverable that is complete by one measure and missing the point by another.
The three are program flash, data EEPROM, and the configuration bytes that hold fuses, lock bits and calibration. Each is addressed differently, each can be locked differently, and each carries something the others do not.
The three areas
| Area | Typical size | Written by | Lifetime |
|---|---|---|---|
| Program flash | Tens to hundreds of kilobytes | Programmer, or bootloader | Around ten thousand cycles |
| Data EEPROM | Hundreds of bytes to a few kilobytes | Application, at run time | Around a hundred thousand cycles |
| Configuration bytes | A handful of bytes | Programmer only | Hundreds of cycles, if that |
The second row is the one that matters for recovery. The EEPROM is written by the application during normal operation, which means it contains state: serial numbers, calibration results, usage counters, user settings, and sometimes a copy of a key. None of that is in the flash image.
What lives in the EEPROM
| Content | Why it is there rather than in flash |
|---|---|
| Serial number or MAC address | Written once at production, read at boot |
| Calibration offsets | Measured per unit on the production line |
| Usage counters | Must survive firmware updates |
| User settings | Changed at run time |
| Crash or state logs | Written during operation |
| Key material | Occasionally, stored where the firmware can reach it |
The second row is the most consequential on a clone. A device whose firmware is perfectly copied and whose calibration offsets are missing will run and produce wrong measurements, and the error will look like a hardware fault.
Why the areas lock independently
The lock bits on these devices do not protect all three areas identically, and the difference is a real feature rather than an oversight.
| Lock state | Flash | EEPROM | Configuration |
|---|---|---|---|
| Unlocked | Readable | Readable | Readable |
| Read protected | Not readable | Readable | Readable |
| Read and write protected | Not readable | Not readable | Readable |
| Bootloader locked | Readable via bootloader | Depending on bits | Depending on bits |
The second row is the important one, and it is why EEPROM data is frequently recoverable from a device whose program memory is not. That inverts the usual assumption that the smaller memory is less accessible.
The calibration byte
Some AVR devices store a factory calibration value in a dedicated location, programmed during test and used to trim an internal oscillator. It is not part of the program and not part of the user EEPROM.
| Location | Content | Consequence of losing it |
|---|---|---|
| Signature row | Device identification | Cannot confirm identity |
| Calibration row | Oscillator trim | Internal oscillator runs off-frequency |
| User signature | Sometimes a serial | Traceability lost |
| Fuse bytes | Configuration | Device may not start |
The second row produces a specific and confusing symptom: a device with a copied program that communicates at the wrong baud rate. The UART is fine, the clock is slightly wrong, and the firmware is doing exactly what it was told with a clock that is not what it assumes.
Reading all three
The complete read is a sequence, and the order is chosen so that a failure partway through still leaves something usable.
| Order | Area | Reason for the order |
|---|---|---|
| 1 | Signature | Confirms the device before anything else |
| 2 | Configuration bytes | Records the state that governs access |
| 3 | Program flash | The largest area and the most likely to be blocked |
| 4 | EEPROM | Often readable even when flash is not |
| 5 | Calibration | Small, and decisive for behaviour |
The fourth row is the one worth remembering when a device is protected: attempt it anyway, because the protection may not extend that far.
Reconstructing a device from three parts
A working clone needs all three, and the assembly is not a concatenation.
| Component | Where it goes | If omitted |
|---|---|---|
| Program image | Flash | Nothing runs |
| Configuration | Fuse and lock bytes | Device may not start, or starts wrong |
| EEPROM contents | Data area | Runs, produces wrong results |
| Calibration | Its own row | Timing and measurement errors |
The third row is the one that gets omitted in practice, because the flash read is the visible part of the job and the EEPROM read is a separate command that somebody has to remember to issue.
When an area cannot be read
Each area has its own obstacle, and each obstacle has its own answer.
| Area blocked | Obstacle | Route |
|---|---|---|
| Flash | Read lock | Physical readout |
| EEPROM | Read and write lock | Physical, or infer from the application |
| Configuration | Not readable on some devices | Infer from behaviour |
| Calibration | Not user accessible | Measure the oscillator, or accept a default |
The fourth row has a pragmatic answer that is worth knowing: the calibration value can be replaced by measuring the actual oscillator frequency and computing a suitable trim, which is what a production line does. It is a recalibration rather than a recovery.
Where this connects
The distinction between the two configuration blocks, and which of them is a lock, is in attacking ATmega embedded firmware. The byte and word addressing difference that affects the flash image is in attacking ATmega firmware. Where the EEPROM is the specific target, extracting AVR software data treats it as the separate device it is.
Services at this boundary
Work covers all three areas plus calibration, signature confirmation, assembly of the areas into a reprogrammable set, and recalibration where the factory value is unavailable. It does not cover reading an area that is locked with no physical route, and it does not cover reconstructing EEPROM contents that were written at run time and have since changed.
The framing worth using is that an AVR is three memories in one package, and a request to “read the chip” should always be answered with a question about which ones.