Posts Tagged ‘cypress ic flash break’

PostHeaderIcon Interrupted Erase: Why Half-Erased Is Usually Recoverable

A device that lost power during a firmware update is the most common recovery case we receive, and the most commonly misdiagnosed. The owner reports a dead unit and assumes the flash is empty. In most cases the flash is not empty; it is a mixture, and the mixture is what makes recovery possible.

The reason is that erase is a physical process with duration, not a command with an instantaneous effect.

What an erase does over time

Erasing a block means removing charge from every floating gate in it, and the mechanism is a high field applied across the tunnel oxide for a period measured in milliseconds. During that period the threshold voltages of the cells fall together from the programmed distribution toward the erased distribution.

The fall is not instantaneous and it is not simultaneous across the block. Cells differ slightly in geometry and coupling, so the threshold distribution widens before it moves. If the field is removed halfway through, the block is left with a distribution that is neither programmed nor erased, and the width of that distribution is the reason the block is still readable in principle.

Elapsed fraction Cell state Readable
0 Programmed, intact Yes, normally
0.3 Distribution widened, means shifted Yes, with margin
0.6 Means between states Ambiguous per cell
0.9 Near erased, residual charge Usually reads as erased
1.0 Erased Nothing left

Why block granularity helps

The more important protection is that erase commands operate on blocks, and a firmware update erases many blocks in sequence.

The erase pointer moves monotonically through the address space. Blocks below the interruption point are fully erased and hold nothing. Blocks above it were never touched and hold everything, bit for bit, exactly as they were before the update started. Only the block being erased at the moment of the interruption is in the intermediate state.

Region State Contents
Below the erase pointer Erased Gone
The block at the pointer Partial Ambiguous, often partly readable
Above the erase pointer Untouched Intact

This is why the recoverable fraction is usually large. A boot loader that erases the application region from the bottom upward and loses power at thirty percent has erased thirty percent of the application and destroyed nothing else. The boot loader itself, the parameter block, and the file system above the application are all intact.

Reading a partially erased block

The block at the pointer needs a different read strategy from the rest of the array. A normal read compares each cell’s threshold to a fixed reference and returns a bit. Applied to a partially erased block, that comparison is a coin toss for cells sitting between the two distributions.

The useful technique is to sweep the reference. Read the block at the nominal reference, then at references offset above and below it, and compare the three results. Cells whose value is stable across the sweep are decided; cells that flip are the ambiguous ones, and their count is a measure of how far the erase progressed.

Sweep result Interpretation Action
Stable at all references Cell is decided Accept the value
Flips at one reference Marginal cell Flag, use context
Flips at every reference Deeply ambiguous Treat as unknown

The third category is usually small. Even a sixty-percent-complete erase leaves most cells clearly on one side, and error-correcting codes elsewhere in the image absorb the remainder, provided the block has any.

The failures that are not recoverable

Three scenarios destroy the data, and they are worth separating from the recoverable ones.

The first is interruption during the erase of a metadata block that the rest of the image depends on. If the block holding the file system superblock is erased, the data blocks above it are intact but unaddressed, and reconstruction becomes a forensic exercise rather than a read.

The second is a boot loader that retries the erase on the next power-up. The device comes back, sees an update in progress, and erases again from the beginning, this time over blocks that were previously untouched. Each retry destroys more, and a device that is power-cycled repeatedly during a failed update can end up genuinely empty.

Scenario Recoverable fraction Method
Single interruption, no retry Most of the array Straight read plus sweep
Repeated power cycles Boot region and above only Region-wise read
Interrupted metadata erase Data present, structure lost Reconstruction
Erase completed, then programming failed Nothing Rebuild from another source

The third is a programming failure rather than an erase failure, and it is common on devices that lost power during the write phase. Here the blocks are erased and partially rewritten, which means the image is a mixture of new data in the first blocks and 0xFF in the rest. Nothing can be recovered from the erased part, and the case moves to three sources for rebuilding flash.

The order of operations

Recovery has a fixed order, and reversing it costs data.

The first action is to read the whole array and keep the raw dump. Not a parsed image, not a partial read of the interesting region — the entire array, byte for byte, with the read parameters recorded. Every later step works from that dump and never from the device, because the device can be lost and the dump cannot.

The second action is to identify the layout, which determines what the fragments belong to. The method is the one in five flash layouts, and it applies to a damaged image exactly as it applies to an intact one, because the fingerprints survive a partial erase.

The third action is the reference sweep on the boundary block, performed on a copy of the dump rather than the dump itself, so that the original measurement remains available for a second interpretation.

When recovery is not the goal

A frequent mismatch in expectations is a customer who asks for recovery when what they need is a working device. Those are different objectives with different costs.

If the goal is a working device, the fastest route is usually to erase the remainder and program a known image, provided one exists. If the goal is the data — calibration values, a production log, a key that only exists on this unit — then recovery is the only route and the effort is justified.

Goal Route Data outcome
Working device Erase and reprogram Replaced
Per-unit data Extract the parameter block Preserved
Code for analysis Read the untouched regions Partial
Both device and data Extract, then reprogram Preserved, then extended

The parameter block is the region most often worth recovering on its own. It is small, it survives interruption more often than the code does because it usually sits at the top of the array, and it cannot be obtained from any other unit.

What the service does

We read the array first and report what is actually there, before quoting any recovery work.

Deliverable Content
Raw dump Full array, with read parameters recorded
Region map Which regions are intact, erased, or partial
Recoverable estimate Percentage and which parts
Sweep analysis Decided versus ambiguous cells in the boundary block

The estimate is delivered before the work rather than after, because a device that is eighty percent intact and a device that is five percent intact look identical from the outside, and the customer deserves to know which one they have. Where the answer is that the untouched regions are enough, the remaining work overlaps with extraction margins on aged cells, since a device that has just survived an interrupted erase is not a device in its first cycle.

PostHeaderIcon Unlocking a Block Erases It: The Binding You Cannot Break

The most common request we receive about a locked flash is a contradiction, and it arrives in good faith. The customer wants the block protection removed and the contents kept. On the majority of devices that have block protection at all, these two things cannot both happen, because removing the protection is the erase.

That is not a policy or a licensing decision. It is how the cell array is wired.

Why the lock cannot be changed in place

A protection bit has to live somewhere, and on a flash device the only memory that survives a power cycle is the flash itself. So the lock state is stored in the array, in a location the programming interface treats specially.

Changing a bit inside a flash array requires an erase first. A program operation can only move a cell from the erased state to the programmed state; it cannot move it back. To take a programmed lock bit and clear it, the containing block must be erased, and the block that contains the lock bits is by design either the same block that holds the code or a dedicated configuration block that the erase command reaches through the same path.

Implementation Where the lock lives What clearing it costs
Security fuse plus chip erase A dedicated fuse row Full chip erase by definition
Protection register in a config block The config block itself Erase of the config block, and often of everything
Debug-level field A one-way counter Descending a level triggers mass erase
Per-sector lock bits Sector headers Erase of each sector whose bit changes

Every row ends in an erase. The variation is only in how much is lost.

Three implementations of the same binding

The first implementation is the oldest and the bluntest. A security fuse is programmed once the firmware is final, and the only documented way to clear it is a full chip erase, which the vendor’s programming tool performs as a single command. The fuse does not get cleared separately; the erase clears it as a side effect, then the erase clears everything else.

The second is the debug level. A device ships with a debug port open at level zero. Setting level one closes the port but leaves the flash readable through the core. Setting level two closes both. Returning from level two to level one is documented as triggering a mass erase, on the reasoning that a party who could close the port must be the same party who can afford to lose the contents.

Transition Erase triggered Data kept
Level 0 to 1 No Yes
Level 1 to 2 No Yes
Level 2 to 1 Yes, mass No
Level 2 to 0 Yes, mass No

The third is per-sector locking on parallel NOR devices. Here the lock bits genuinely are per sector, and in a few families they can be set and cleared with a command sequence rather than an erase. But those parts are the exception, they are usually the older ones, and even they require the device to be in a state where the command sequence is accepted — which on a production board means the write-protect pin is already asserted and cannot be released without the same authority the lock was meant to deny.

What the datasheets say, and where

The binding is always documented, and it is always in a footnote rather than in the feature list. Search the datasheet for the word “erase” inside the section on protection, not the section on memory organisation.

Typical wording is that clearing the protection “requires a device erase” or that the operation “will erase all memory contents”. Both phrases mean the same thing, and both are easy to miss because the feature list on page one says only that the device offers block protection.

Document location Phrase to look for Meaning
Protection register description “erased to clear” The bits are cells; erase is the only clear
Debug chapter “mass erase is performed” Level change destroys contents
Programming manual “chip erase before unlock” Order is fixed, not a recommendation
Errata “unexpected erase” The binding bit them in silicon

The errata entry is the one that surprises people. A small number of parts trigger the erase on a path the datasheet did not describe, usually a reset during a protection command, and the result is a device that was unlocked and empty when the engineer expected it to be unlocked and full.

Why the request keeps arriving

The request is reasonable from the customer’s point of view, because the marketing material describes protection as a lock rather than as a fuse. A lock implies a key. A fuse implies destruction. The distinction matters enormously when the goal is to read a device in order to repair it rather than to copy it.

We spend a disproportionate amount of the first conversation on this point, because a customer who expects data preservation will authorise a procedure that cannot deliver it, and then judge the result as a failure of technique. The honest framing is that the block protection worked exactly as designed.

The narrow cases where data does survive

There are three, and none of them is common.

The first is a device with two independent protection layers, where the outer layer is a register that resets on power cycle and the inner layer is the fuse. Clearing the register costs nothing, and if the code was only protected by the register, the data is intact. This is a design mistake rather than a feature, and it is worth testing for, because it costs one power cycle to check.

The second is a device where the locked region is a small parameter block and the code sits in unlocked sectors. Erasing the parameter block to clear its lock leaves the code readable. The customer loses calibration and keeps the program.

The third is a device whose lock is enforced by the boot loader rather than by the array. The array has no protection at all; the loader simply refuses to expose it. That is not a block lock in the hardware sense and it falls to the routes described in three physical routes into flash rather than to an unlock procedure.

What to do instead

When the binding is real, the planning question becomes which of three outcomes is acceptable.

If the contents are still wanted, the only route is to read them while the lock is in place, which means attacking the read path rather than the lock. That is the block-level protection question: which blocks the design left open, and whether the open ones are enough.

If the contents are not wanted and the goal is a working device, the unlock is trivial: perform the erase, accept the loss, and program a known image, which is the rebuild problem covered in three sources for rebuilding flash.

If neither is acceptable, the device is a candidate for destructive reading, where the lock is irrelevant because the array is imaged directly rather than read through the interface.

Goal Route Contents after
Read the code Attack the read path Intact
Working device Erase, then program Replaced
Code from a dead unit Image the array Intact, device lost

Half-erased states

One final note, because it changes the arithmetic. An erase that is interrupted does not always complete. A device that lost power midway through a mass erase can end up with some blocks cleared and others untouched, and the untouched ones may still be readable — a state examined in interrupted erase.

This is not a reliable unlock method. It is, however, a reason to attempt a read before declaring a device empty, because “the erase ran” and “the erase finished” are different statements and only the second one guarantees that nothing is left.

What the service does

We identify which of the four lock implementations the device uses, and state plainly what clearing it will cost before any work begins.

Deliverable Content
Lock classification Which of the four mechanisms is present
Data consequence What the documented unlock destroys
Alternative route Whether the read path can be attacked instead
Recommendation Read-in-place, rebuild, or destructive imaging

The classification is usually answerable from the datasheet and a bench measurement, and it takes less time than the conversation about expectations. Where the answer is that the data cannot survive an unlock, we say so at that point rather than after the device has been erased.