PostHeaderIcon ATtiny85V: What EESAVE Decides Before Anyone Erases Anything

Every AVR recovery that involves clearing protection runs into the same physical fact: the operation that removes the lock bits also erases the array. There is no separate unlock command. The erase is the unlock.

That fact is usually stated as bad news and left there. On this family it is more interesting than that, because the erase is not a single action covering a single memory. It covers three, and one bit in the fuse configuration decides whether the smallest of them is included. That bit is read without disturbing anything, it takes a second to obtain, and it determines which of two quite different procedures is safe.

Three memories, two erase behaviours

The device holds flash for code, SRAM for working state, and EEPROM for data that has to survive a power cycle. Of these, two are non-volatile and both are affected by a chip erase — but not identically.

memory contents survives chip erase endurance
flash program and constants no about 10,000 cycles
EEPROM calibration, counters, settings depends on one fuse bit about 100,000 cycles
SRAM working state irrelevant, gone at power-off unlimited

The fuse is called EESAVE and it is programmed rather than cleared to preserve. In the state where it is programmed, a chip erase clears the flash and the lock bits and leaves the EEPROM contents untouched. In the other state, the EEPROM is erased along with everything else.

Why this changes the order of work

Consider a part whose lock bits prevent reading the flash but whose EEPROM is the thing the customer actually needs — a unit counter, a calibration table, a serial number that was never written down. Two procedures exist and they lead to different places:

  • If EESAVE is programmed, running the erase clears protection and flash, and the EEPROM can then be read through the ordinary interface. The code is gone, the data is not. That is often an acceptable trade, and it costs nothing but a reflash of an image that probably exists in the customer’s source control anyway.
  • If EESAVE is not programmed, the same erase destroys both memories. The job then has to go to the silicon, which is a different service at a different price.

The entire decision rests on one bit that can be read before anything is touched. Skipping that read is the single most expensive shortcut available on this part, and it is taken routinely by operators who have learned that «chip erase unlocks the chip» and stopped there.

Reading the fuse state first

The fuse bytes are readable through the interface on a part whose lock bits are set, as long as verification has not been disabled entirely. That is the first operation, before any erase, before any attempt at the flash array:

  1. Read the signature. If it does not answer, stop; the problem is electrical and no fuse will help.
  2. Read the lock bytes. They say which operations the part will accept.
  3. Read the fuse bytes. They say what an erase will destroy.
  4. Only now decide whether an erase is part of the plan.

Steps 1 to 3 are non-destructive and take under a minute. Their output is the entire basis for the choice in step 4, and it also documents what state the part was in when it arrived — which matters when a customer later claims the part was working.

What the EEPROM contents reveal

When the EEPROM does survive, its contents are worth more than a data dump. The endurance figures are the reason: flash in this class is rated around ten thousand write cycles and EEPROM around a hundred thousand, an order of magnitude apart. A page that has been rewritten on every power-up shows a different wear signature from one written once at the factory.

In practice that shows up as data that is still valid but sits in a page whose neighbours are inconsistent, or as a structure that looks like a rotating log — a sequence of records walking through the address space, each with a sequence number that only ever increases. Recovering such a structure is a matter of ordering records, not of reading bytes, and the last valid record is the answer the customer wants.

When the fuse says the data is gone

If EESAVE was left in its erase-inclusive state, the data page is not recoverable by any interface operation, and the honest answer is that the erase that would unlock the flash will also clear the EEPROM. The work then proceeds at die level, where the EEPROM array is read directly out of the silicon before any electrical erase is applied.

That path is slower and more expensive, but it is not speculative. The EEPROM array on this family is a distinct physical structure with its own row address decoder, and reading it does not depend on the flash lock bits in any way. What it does depend on is the package: an eight-pin plastic part is a straightforward decapsulation, and the array is small enough that the read is quick once access exists.

The deliverable, and the note that matters

The return set is the flash image, the EEPROM contents as a separate file because it is a separate address space, the fuse and lock bytes exactly as read on arrival, and a statement of which of the two paths was taken and why. That last item is not administrative. A customer who is told «the EEPROM was preserved because EESAVE was set» learns something about their own production programming that they did not know, and the same customer who is told the opposite learns that the setting needs changing in the fixture.

Protection semantics on this variant are otherwise identical to the rest of the family, and what the same die looks like when the firmware turns out to be a software USB stack is covered in ATtiny85 flash reverse engineering. The low-voltage electrical constraints are covered in ATtiny45V program recovery, and the identification of the three pin-compatible members in ATtiny45 heximal extraction. For images where the EEPROM is used as a rotating log rather than a settings page, the same reasoning appears in ATmega1280 EEPROM recovery.

FAQ

Can the EEPROM be read while the flash is still locked? Not through the array read, which the lock bits cover. The fuse bytes are readable, and they decide whether a later erase will spare the data.

Is EESAVE programmed by default? It is not, which is the reason an unplanned chip erase so often takes the data page with it.

Does preserving the EEPROM mean the code can be recovered afterwards? No. The erase that clears the lock bits clears the flash regardless of EESAVE. Only the data survives.

Conclusion

«Chip erase unlocks the part» is true and incomplete. It is one operation with two possible scopes, and a single fuse bit selects between them. Reading the fuse bytes before touching anything costs a minute and decides whether the customer gets a data page back or a quotation for decapsulation.

Comments are closed.