Posts Tagged ‘extract avr mcu code’

PostHeaderIcon Extract AVR Firmware Twice: What Refuses to Be Stable

An extraction has no ground truth. There is no second copy of the device to compare against, and the device itself cannot say whether the bytes it returned are the bytes it holds. The only available error estimate is repetition: read the device again and see whether the answer changes.

That estimate is crude and it is enormously better than nothing, because the errors it detects are exactly the errors that matter. A read with a handful of wrong bytes produces a firmware image that runs and fails in one mode, and no amount of staring at the file will reveal it.

What a repeat comparison tells you

Result Interpretation
Identical across three reads at one clock Strong evidence of correctness
Identical across three reads at three clocks Very strong evidence
A few bytes differ, non-repeating Timing margin, or contact
The same bytes differ every time A field that is genuinely dynamic
Whole regions differ Address decoding or contact fault

The fourth row is the one that requires thought. Some things on a device are not stable by design: an EEPROM region being written by a running application, a counter that increments, a status area the firmware updates. Reading such a field twice will legitimately produce two values.

The distinction matters because the response is opposite. A timing-margin error calls for a slower clock and a better fixture. A genuinely dynamic field calls for quiescing the device and reading at a defined moment.

Fields that are legitimately unstable

Field Why it changes How to capture it
EEPROM counters Application increments them Halt the device, or read quickly
EEPROM logs Written on events Capture, then accept that it is a snapshot
Fuse bytes Not dynamic, but some devices read them inconsistently Read several times and take the majority
Calibration Not dynamic Should be stable; instability means a fault
Program flash Never dynamic Any variation is an error

The third row is a real and slightly awkward case: on some devices the fuse read is less reliable than a flash read, because the fuse path is short and in-system conditions can affect it. Taking a majority vote across several reads is a legitimate practice.

Distinguishing fixture from device

The pattern of variation identifies the cause, and the patterns are quite distinct.

Pattern Cause
Errors concentrated in one bit position A data line with poor contact
Errors at regular address intervals An address line not connected
Errors that move with cable movement Mechanical contact
Errors that increase with clock Timing margin
Errors that appear only in the first read after power-up Warm-up or supply ramp

The second row is diagnostic in a satisfying way: an address line not making contact produces errors at every address where that bit is set, which is a regular pattern with a period equal to twice the bit’s weight.

The procedure

A read procedure that produces a defensible result has a fixed shape.

Step Purpose
Identify the device by signature Eliminate the largest class of error
Read at a conservative clock Establish a baseline
Read again at the same clock Detect nondeterminism
Read at a higher clock Find the margin limit
Reconcile differences Decide which value is correct
Report the confidence Make the result usable

The fourth step is the one that produces information rather than confirmation. A read that only ever runs at one clock tells you that the clock works, not where the boundary is.

Reconciling differences

When two reads disagree, the resolution is a decision that should be documented.

Situation Resolution
One bit differs in a region of code Take the value that disassembles plausibly
One bit differs in a region of data Take the majority across more reads
A whole word differs Suspect an address fault, re-read that word specifically
A region is unstable across all reads Report it as unrecovered

The first row uses structure as evidence, which is legitimate: an instruction that decodes validly is more likely correct than one that does not. It is not infallible, and it is much better than a coin flip.

What confidence to report

A report that states a percentage without explaining it is not useful. A report that states which regions were stable and which were not is.

Statement Meaning
Stable across three reads at two clocks High confidence
Stable at the conservative clock only High confidence, but note the clock
Stable except one region Regional exception, described
Unstable throughout The read failed, regardless of what it produced

The fourth row is the one that is hardest to write and most valuable. An unstable read is a failed read, and delivering the file anyway without saying so is the worst outcome available.

Where the adjacent problems are

The clock and fixture limits that produce marginal reads are treated in reading AVR firmware at speed, and the identity check that should precede any read is in reading Atmel AVR firmware. What the other five artefacts besides flash contribute is in extracting an AVR microcontroller.

Services at this boundary

Work covers multi-pass readout, clock characterisation, error pattern analysis, reconciliation with documented decisions, and confidence reporting per region. It does not cover establishing which of two differing bytes is correct when neither has structural support, and it does not cover reading a device whose supply or clock is unstable.

The practice worth adopting is simple: never deliver an AVR image that was read once, and never deliver one without saying how many times it was read.