Posts Tagged ‘recover mcu embedded hex’

PostHeaderIcon ATtiny88A: Where the Program Starts and What That Fixes

An image has no index. There are no function names, no section headers, no entry in a table that says where anything is. There is one fixed point: address zero, where the processor begins after reset.

Everything else in the file is found by starting there and following. That makes the first instruction structurally the most important bytes in the dump, and it makes a wrong reading of it expensive — every conclusion downstream inherits the error.

What the first words contain

The reset vector is a jump, and on this architecture an absolute jump occupies two words: the opcode with low target bits, then the high bits. Decoding it gives two facts immediately:

  • The instruction is a jump, which confirms the image starts where it should.
  • The target is an address, which is where the program actually begins.

That second fact is the map. The target is typically just past the interrupt vector table, but not always: a build that places a large table or a constant block immediately after the vectors will have its first real instruction much further along. Either way, the target is where to start reading.

What the vector table contributes

Between address zero and the target sit the interrupt vectors, one slot each. They are jumps too, and their targets point at the handlers.

Reading them in order produces a compact description of how the firmware is organised:

What the vectors say What it implies
All point to one address Interrupts enabled but mostly unhandled
Each points somewhere distinct Event-driven design, handlers matter
Several point just past the table Handlers are inline, immediately after
All point into a single region A dispatcher reads a flag and branches

The fourth pattern is common in compact firmware and it means the real logic is in the dispatcher, not in the handlers. Knowing that saves reading each handler separately.

Why the entry point matters for a reconstruction

A reconstruction that starts reading at the wrong place produces code that is internally consistent and externally wrong. It compiles, it disassembles plausibly, and it omits whatever came before the starting point — usually the initialisation sequence, which is where the design’s assumptions are stated.

Initialisation is the most informative part of a small program. It sets the clock, the port directions, the peripheral enables, and the initial state of every output. A reconstruction that skips it produces a functional description with no context, and the context is what a customer usually needs.

What “program” means on a part with no boot section

There is no second container here. The whole array is the program: vectors, initialisation, application, and whatever constant data the build placed at the end.

That rules out two questions that arise on larger parts — whether a bootloader is present, and whether part of the logic lives in a protected region. Neither applies. The image is one thing, and if it is readable it is complete.

It also means there is no self-programming path. The device cannot rewrite itself, so any field update happens through the programming pins. That is a design constraint worth noting in a report, because it explains why the product has a header.

The reading sequence

  1. Signature, fuses, lock byte. Fuses first, because a clock that is not there produces silence.
  2. Array read, verified page by page.
  3. Decode the reset vector: confirm the jump and record the target.
  4. Walk the vector table at the documented spacing, recording each target.
  5. Begin the reconstruction at the target from step 3, not at address zero.

Step 5 is the discipline that keeps the work honest. Reading from zero means reading data as code, and data decoded as instructions is the most common source of confident nonsense in this work.

Related notes

FAQ

Is the program always at address zero? The vector is. The code it jumps to is usually a short distance later.

Can the vector be redirected? Not on this family. There is no boot section and no redirection fuse.

Why decode the vector before reading code? Because it is the only fixed reference in the image. Everything else is relative to it.

What if the first word is not a jump? Then the read is misaligned, or the image is not what it appears to be. Both are worth resolving before going further.

Conclusion

An image is a graph with one known node. Decoding the reset vector finds the second node, and the vector table describes the shape around it. Starting the reconstruction from that point rather than from address zero is what separates a description of the program from a description of the file.

PostHeaderIcon ATmega2561V: The Largest Member, and the Same One Fuse

Scale changes many things about a part. A quarter of a megabyte of flash needs a wider program counter, a different page count, and a read that takes long enough to expose supply behaviour that a small part hides. Scale does not change the arbitration that decides whether anything is recoverable.

That arbitration is a single fuse bit. On a part this large it is easy to imagine that the extra memory implies extra rules. It does not. The same erase, the same lock state machine, the same fuse, applied to a bigger array.

What is different at this size

Three engineering consequences, none of them about protection.

The read takes time. A quarter of a megabyte at a conservative clock is minutes, not seconds. Over that window the supply can sag, the part can warm, and a clip can lose contact. Any of those produces a file that is correct at the start and wrong later.

The address space is fully populated. Unlike a smaller member occupying a subset of the same map, this one uses all of it, so an all-FF region in the middle is meaningful rather than a marker of unimplemented memory.

The program counter is three bytes wide. Return addresses, jump targets, and table pointers all carry an extra byte, and code that manipulates the stack directly has to account for it.

What is not different

Rule Applies here exactly as elsewhere
Lock mode 2 or 3 blocks verification yes
Chip erase is the only way to clear locks yes
Chip erase erases the flash yes
EEPROM survives only if EESAVE allows yes
No interface bypasses the lock byte yes

That table is the whole protection story, and it is identical across the family from the smallest member to this one. Familiarity with a small part transfers directly, which is one of the genuine advantages of a family that shares an architecture.

The EEPROM on a part nobody expects to have one

This member has no external memory interface, so there is no external storage to look for. Its EEPROM holds the per-unit data: calibration, identity, counters. A few kilobytes, and usually the most device-specific content in the product.

Because the flash is large and the EEPROM is small, the natural focus is the code. That focus is correct for understanding the product and wrong for understanding the unit. A device that measures or controls something external almost always carries constants in EEPROM that the code reads at start-up; without them, a faithful reproduction still measures wrong.

The fuse that decides whether those constants survive an erase is the same fuse as on every other member. Set for operational reasons — so a firmware update does not wipe calibration — and set more often than not.

Reading a large array reliably

The risks scale with the read time, so the procedure has to as well:

  1. Supply at the design rail, measured at the socket, with local decoupling.
  2. Signature, fuses, lock byte — before anything else.
  3. One page read twice, compared. Establishes margin.
  4. Full read in passes, verifying each page as it arrives; log any page that fails.
  5. Re-read the first page at the end and compare with step 3.

Step 5 is the one that catches drift over the duration of the read. It costs one page and it is the only check that covers the whole session rather than one page.

A page that fails verification in step 4 is not a page to average or to accept. It is a page to re-read at lower clock, or at higher supply, until two consecutive reads agree. If they never agree, the die has a marginal region and that fact belongs in the report.

Working out what you have

An all-FF block in the middle of a full-map part is informative. Three explanations, in order of likelihood: the application does not fill its allowance, an update left a gap, or a page failed to program.

The distinction matters for reproduction. A gap from an incomplete build is reproducible as-is; a gap from a failed program will not be, because the device is running code that was never fully written and its behaviour may depend on what the missing page should have contained.

Comparing the gap boundaries against page alignment settles it. A gap that starts and ends on page boundaries is structural. A gap that starts partway through a page came from an interrupted operation.

Related notes

FAQ

Does a larger flash mean stronger protection? No. The lock bit mechanism is identical. Extra memory is not extra security.

How long does a full read take? Minutes at a conservative clock. Reducing the clock for reliability is almost always the right trade.

Can the EEPROM be read while the part is locked? No. The read commands are refused in lock mode 2 or 3, which is why the erase and its one surviving array matter.

Is a gap in the middle of the image a problem? It is information. Page-aligned gaps are structural; unaligned ones record a failure.

Conclusion

Size is an engineering detail; protection is an architectural constant. This part’s quarter megabyte changes the read time, the pointer width, and the interpretation of empty regions, and it changes nothing about how a locked device is opened or what survives. Reading the fuse byte first answers the only question that cannot be answered later.