ATtiny861: Three Address Spaces and Where Tables End Up
An AVR has three memories and three addressing schemes. Flash is word-addressed through the program counter and byte-addressed through a load instruction. SRAM is byte-addressed in a flat data space. EEPROM is byte-addressed through a separate index register and its own control block.
A constant table can be placed in any of the three, and the choice is a compiler and linker decision that leaves a distinctive trace. Knowing which space a table went to tells you whether a recovered image is complete or whether part of the data lives somewhere you have not read.
The three placements and their signatures
| Placement | How the code reads it | Survives power loss | In a flash dump |
|---|---|---|---|
| Flash | Load from program space | yes | present |
| SRAM, initialised at boot | Load from data space | no, copied at start-up | present once, as the copy source |
| EEPROM | Separate index register and control | yes | absent |
The second row is the subtle one. An initialised array in SRAM has to come from somewhere at start-up — either a copy loop that reads from flash, or a set of immediate stores. Both appear in the start-up path, and both mean the data is in the flash image twice: once as content, once as the code that installs it.
The third row is the one that catches people. A table placed in EEPROM is not in the flash image at all. A program that appears to be missing its calibration data may simply have it stored in the other array.
Reading the start-up path
The first few hundred instructions after the vector table are worth reading in full, because they establish how the device is wired:
- Stack pointer initialisation, which reveals how much SRAM the build expects.
- A copy loop from flash to SRAM, if initialised arrays exist. Its source and destination addresses describe the layout.
- Peripheral configuration, in the order the firmware enables things.
- Any read from EEPROM, which means the device depends on values that were written at the factory.
The fourth item is the important one. A start-up read from EEPROM means the firmware will not behave correctly on a blank part, and it means a recovered flash image alone cannot reproduce the product.
Why this matters for a reconstruction
A reconstruction that produces compilable code from a flash image will silently omit everything that lived in EEPROM. The code will compile, run, and read zeros from the EEPROM array, which for a calibration constant means a scale factor of zero and a product that reports nothing.
That failure looks like a bug in the reconstruction. It is actually a missing input, and it is resolved by reading the EEPROM as a separate step rather than by re-examining the disassembly.
The same logic applies to the fuse bytes: a reconstruction that omits them produces a device that does not start. Both omissions come from treating the flash image as the whole device.
The small-part advantage
On a part of this size, the three memories fit in a mental model. A few kilobytes of flash, a few hundred bytes of SRAM, a few hundred bytes of EEPROM. The copy loops are short, the register maps are short, and the whole program can be read rather than sampled.
That matters because manual reading catches things that automated analysis misses — an unusual constant, a table with a recognisable stride, a delay loop sized for a specific sensor. On a larger part, that kind of reading is impractical and the analysis has to be statistical.
The order that produces a complete picture
- Signature, fuses, lock byte.
- Flash array, verified page by page.
- EEPROM array, read separately, and recorded as its own artefact.
- Start-up path disassembly: stack, copy loops, peripheral order, EEPROM reads.
- Reconstruction of tables, noting for each whether it came from flash, SRAM initialisation, or EEPROM.
Step 5 is the deliverable that avoids the silent-zero failure, because it records provenance. A table with no recorded provenance is a table whose absence will not be noticed until the product is built.
Related notes
- ATtiny461V and the serial interface — the peripheral whose register map usually sits in one of these tables.
- ATtiny84 and complete images — completeness on a fully populated array.
- ATmega32PA and EESAVE — what happens to the third space during an erase.
FAQ
Is the EEPROM included in a flash dump? No. It is a separate array with separate addressing, and it must be read explicitly.
How do I tell a flash table from an SRAM one? By the access instruction and by the copy loop in the start-up path.
Does a start-up copy loop mean the data is duplicated? Yes. The initial values exist in flash and are copied to SRAM, so both copies are present in the image.
Can a reconstruction work without the EEPROM? It compiles and runs, and it will be wrong wherever a table came from EEPROM.
Conclusion
Three memories, three addressing schemes, and one common mistake: treating the flash image as the device. Recording where each table lives converts a reconstruction from something that compiles into something that reproduces behaviour — and it takes one extra read at the start rather than one painful discovery at the end.