Posts Tagged ‘extract avr chip heximal content’
Extract AVR Software Data: EEPROM Is a Separate Device
The data EEPROM inside an AVR is easy to overlook because it is small. A few hundred bytes, sometimes a couple of kilobytes, against tens or hundreds of kilobytes of flash. It is also the only area that the application writes during normal operation, which makes it the only area that contains state rather than code.
That distinction determines what a recovery is worth. A flash image tells you what the device does. The EEPROM tells you what this particular device has been doing, and on many products it carries the identity that makes the device work at all.
Its own address space and its own commands
EEPROM is not a region of flash. It has separate address space, separate read and write commands, and separate timing.
| Property | Program flash | Data EEPROM |
|---|---|---|
| Address space | Word-addressed for the CPU | Byte-addressed |
| Write granularity | Page | Byte |
| Write time | Milliseconds per page | Milliseconds per byte, slower per unit |
| Endurance | Around ten thousand cycles | Around a hundred thousand cycles |
| Access during execution | Read while executing, not write | Read and write, with timing rules |
The third row explains a design pattern: writing a single EEPROM byte is slow enough that applications buffer changes and write them in batches, often at power-down. That means the EEPROM contents at any moment may lag the application’s logical state.
What lives there
| Content | Typical writer | Recovery value |
|---|---|---|
| Serial or MAC address | Production line | High; identity |
| Calibration constants | Production line | High; affects measurement |
| User settings | Application | Medium |
| Usage counters | Application | Medium; establishes age |
| Event logs | Application | Variable |
| Encryption key or seed | Application, rarely | High when present |
The sixth row is worth checking on any device where the firmware appears to contain no key. A key stored in EEPROM and read at boot is a reasonable design, and it means the flash image alone will not decrypt anything.
The endurance asymmetry
The lifetime numbers are not trivia; they constrain what can be inferred.
| Observation | Inference |
|---|---|
| Counters with values near the endurance limit | The device is old, or the firmware writes too often |
| Counters reset to zero with old hardware | Firmware was updated, or EEPROM was replaced |
| A region that reads as all ones | Never written, or worn out |
| A region that reads inconsistently | Cells at end of life |
The fourth row is a real failure mode: EEPROM cells that have been written many times lose their margin, and the values read back become unreliable before they become wrong. A read that returns different values on successive passes is evidence of wear, not of a bad connection.
Protection and the EEPROM
Lock bits on these devices can cover EEPROM as well as flash, but the combinations are not uniform.
| Lock configuration | Flash | EEPROM |
|---|---|---|
| Read protection only | Blocked | Usually readable |
| Read and write protection | Blocked | Blocked |
| Bootloader-oriented locks | Depends on the mode | Depends on the mode |
The first row is the common production configuration and it is the reason EEPROM recovery is often possible on a device whose code is not. It is worth attempting before concluding that a device is closed.
Reading it correctly
The read itself is simple and has two traps.
| Trap | Effect |
|---|---|
| Reading with the wrong address size | Upper bytes wrap, lower bytes repeated |
| Ignoring the write-in-progress flag | A read during a write returns the old value |
| Assuming the size from the part number | Some devices have less than the family maximum |
| Treating uninitialised bytes as data | 0xFF means “never written”, not “value 255” |
The second row is subtle and occasionally decisive: an application that writes a value at power-down and the read happening before the write completes will capture the previous value. On a device read after being powered down normally, this is not an issue; on one read mid-operation, it is.
Reconstructing state from data
The EEPROM contents are not self-describing. Recovering them means recovering meaning, and meaning comes from the firmware.
| Step | Method |
|---|---|
| Read the EEPROM | Raw bytes |
| Find EEPROM accesses in the flash image | Address constants |
| Map each access to a variable | Context of use |
| Identify structure | Repeated access patterns, strides |
| Validate | Change a value, observe behaviour |
The fifth row is the only real confirmation, and it requires a working device. Where the device does not run, the structure has to be inferred from the access patterns alone, and the confidence is lower.
The checksum problem
Many applications store a checksum over their settings and refuse to boot if it does not match. A recovered EEPROM whose contents were captured mid-update will fail that check, and the device will fall back to defaults.
| Situation | Symptom |
|---|---|
| Checksum region captured before the update | Device boots with defaults |
| Checksum region captured after, data before | Checksum mismatch |
| Data and checksum captured consistently | Normal boot |
| Checksum field identified but not recomputed | Can be recomputed offline |
The fourth row is the practical fix, and it requires having identified the checksum field, which is a small reverse engineering task in itself.
Where the surrounding work is
The three independent areas on the device are compared in attacking ATmega AVR programs. The complete set needed to reproduce a device is in extracting an AVR microcontroller, and the reasons a read may not be repeatable are in extracting AVR firmware repeatedly.
Services at this boundary
Work covers EEPROM readout on locked and unlocked devices, wear assessment, structure recovery from firmware cross-reference, checksum recomputation, and reconstruction of state where the original values are ambiguous. It does not cover recovering cells that have reached end of life, and it does not cover inventing settings that were never written.
The reframing is that the EEPROM is not a small appendix to the flash image. It is the part of the device that distinguishes one unit from another, and on a clone it is usually the difference between working and nearly working.