PostHeaderIcon Attack IC PIC16C74B Binary: Reading a Charge Array, Not a Digital Array

Every discussion of reading a microcontroller image treats the result as a sequence of ones and zeros. On a modern flash part that is a fair approximation: the sense amplifier has a wide margin, the cell is refreshed by the read itself, and a read either succeeds or fails loudly. On a part of this generation the approximation breaks down, and understanding why is the difference between an image that can be trusted and one that merely looks complete.

This member of the C-series line stores its program in floating-gate cells programmed by hot-electron injection and erased by ultraviolet light through a quartz window. The stored value is a quantity of charge, and the sense amplifier compares the resulting threshold voltage against a reference. Stored charge leaks. References drift. What comes out of an old device is therefore a measurement with an error bar, not a byte.

The physical picture

Property Consequence for a read
data is stored as charge on a floating gate a cell near the decision threshold can read either way
erase is by ultraviolet light, not electrically an incompletely erased device is neither programmed nor blank
threshold shifts with temperature and with age a device read warm may differ from the same device read cold
no error correction anywhere in the path a single marginal cell is a wrong instruction word, silently

The last row is the one that matters most. Flash parts of later generations carry checksums and sometimes redundancy so that a marginal cell is caught. This generation carries nothing. A misread word is returned as confidently as a correct one, and unless the image is validated structurally, the error survives into the delivery.

What a leaked cell looks like from outside

Three symptoms recur on devices of this age, and each has a different meaning.

The first is a single wrong instruction in an otherwise coherent disassembly. A word that should be a register operation appears as a different operation on a different register. The surrounding code is right, the control flow is intact, and the product may even run — badly, in one specific mode. This is the classic marginal cell, and it is the case where a second read at a different temperature or a different supply voltage is genuinely informative: if the word changes between reads, the cell is marginal rather than programmed.

The second is a block of words that read as all ones in the middle of the code. That is not a marginal cell. It is an incompletely programmed region, or a region that was erased and never rewritten, and it usually corresponds to a jump target that no longer contains anything.

The third is a gradual degradation across a run of addresses rather than a single point. That pattern appears on devices that were stored in conditions that allowed charge to redistribute, and it argues for reading the whole array more than once and taking a per-word majority rather than trusting a single pass.

Why a second pass is not redundant

On a part with no error correction, repetition is the only error detection available. Two reads of the same cell that agree are much more likely to be correct than one; a cell that disagrees with itself has announced its unreliability.

The practical procedure is to read the array at least twice, at ordinary supply voltage, and compare word by word. Words that agree are accepted. Words that disagree are read again at a modestly different supply voltage — the threshold comparison shifts with the reference, so a marginal cell often resolves consistently at a different operating point even though it is unstable at the nominal one. Where three reads still disagree, the word is reported as uncertain rather than guessed.

Reporting uncertainty is uncomfortable and it is correct. Filling a marginal word with the value that makes the disassembly look tidier produces a document that reads well and misleads.

The ultraviolet window changes the failure modes

Devices in this line came in two packages: one-time programmable in an opaque moulding, and erasable in a package with a quartz window. The windowed parts introduce a failure mode that does not exist on flash.

An erase is a timed exposure to short-wave ultraviolet light. Under-erase leaves cells partially discharged, so that a device which should be blank reads as a mixture of correct and incorrect values. Over-erase is not usually a problem on this technology, but a device erased and then left in room light for months accumulates enough charge redistribution that the erased pattern is no longer uniform.

That matters when the array is being read after an erase — for example when a previous owner attempted to clear the part before sending it for work. The image then contains real code, erased regions, and partially erased regions, and they are distinguishable only by their statistics, not by any marker in the data.

Structural validation instead of assumption

Because the data cannot validate itself, the validation has to come from the structure of the content. Four checks catch most bad reads.

  1. The reset vector at address zero must contain a valid jump into the code. A blank or nonsensical word there means the image is not a working program.
  2. The interrupt vector must also be a valid instruction, usually a jump, and it must land inside the implemented address range.
  3. Every call and goto target must point inside the range, and every page-crossing sequence must be consistent with the paging rules of the instruction set.
  4. The configuration word at the top of the map must decode to a combination the silicon accepts — an oscillator mode that exists, a watchdog setting that is meaningful.

An image that passes all four is very likely correct. An image that fails any of them has a specific defect at a specific address, which is far more useful than a checksum that merely says something is wrong.

When the array is protected

The code protection bit on this generation prevents the programming interface from returning the array. It does not prevent the device from executing. That asymmetry is what makes the visible-window packages interesting, because an optical route exists to the stored charge that does not go through the programming interface at all. That work belongs to the physical end of the discipline, and it is worth being clear that it is not a software technique with a nicer tool.

For the cases where protection is not set, the read path is ordinary and the work is entirely in the validation and interpretation described above. For a sibling in the same line where the emphasis is on the algorithm rather than the silicon, PIC16C73A program recovery covers the paging and addressing structure. The 18-pin member of the family with a smaller array is treated in PIC16C556A software recovery, and the same charge-storage reasoning applied to a larger C-series device appears in PIC16C74 code recovery.

What the customer should receive

For a charge-storage device the delivery has to carry its own confidence statement.

  • the image, with the number of independent read passes stated
  • a list of any words that remained unstable across passes, by address
  • the supply voltage and temperature at which the accepted read was taken
  • the structural checks performed and their results
  • a note on the package type, because a windowed part has a different history than a moulded one

That third item reads oddly in a software-oriented delivery and belongs there anyway. On a device whose stored value is analogue, the conditions of the measurement are part of the result, and a customer who later reads the same device under different conditions and gets a different answer should be able to see why.

Comments are closed.