Archive for the ‘Recover Chip’ Category

PostHeaderIcon TMS320F2806: What a “Binary” of a 16-Bit Flash Actually Contains

Ask for “the binary” of an ARM part and the meaning is unambiguous: bytes at addresses, little-endian, one file. Ask the same of a C2000 part and the question is under-specified, because the core addresses 16-bit words while every file format in common use carries 8-bit bytes. Somewhere between the array and the file, somebody chose a mapping. If that choice is not recorded, the file is not a copy of anything — it is a sequence of bytes with no address meaning.

This is the single most common reason a replicated F2806 fails to boot. The code is present, byte for byte. It is simply at the wrong addresses, or interleaved the wrong way.

Word addressing versus byte addressing

The core sees memory as words. An instruction occupies one or two words. A pointer increment moves by one word, not by two bytes. The flash array is organised the same way.

A file, however, is bytes. So a tool that exports flash must decide whether to:

  • write the low byte then the high byte of each word, producing a file twice the size of the array;
  • write only the low bytes, discarding half the content;
  • write each word as two bytes but adjust the addresses so that the file’s offsets look like word addresses.

Each of these appears in the wild. The third is the most dangerous, because the file looks plausible at a glance — the first instruction is where you expect it — and is wrong by a factor of two in every address beyond the first.

Representation File size vs array Address in file means
Two bytes per word, byte addresses 2× byte address
Two bytes per word, word addresses 2× word address (ambiguous)
Low bytes only 1× word address, half the data lost

Why a flat binary cannot rescue you

A raw binary, by definition, carries no addresses. It is a stream. Placing it requires an assumption about the start address, and for a part whose flash begins at a known base, that assumption is usually made silently by whoever wrote the tool.

The problem is holes. Real C2000 images are rarely one contiguous run. Code sits in the main sectors, constants may sit in a different sector, and the password and OTP areas sit at the top of the address map. A flat binary cannot express “skip from here to there”, so it either fills the gap with zeros — which then get programmed as data — or it concatenates, which shifts everything after the gap.

A file that was produced by concatenation is detectable: the total length will match the sum of the populated regions, and the disassembly will go wrong at exactly one point, the first gap.

Hex files carry the addresses

An Intel HEX or TI-TXT file carries address records, so it can express the gaps. That makes it a far better intermediate for replication: the addresses are explicit, the word/byte mapping is stated by the tool’s convention, and a checksum guards each line.

When a hex file is available, replication becomes mechanical: erase the destination, program records in address order, skip the protected regions, verify by re-reading and comparing. When only a binary is available, the first task is to reconstruct the address map — and the only reliable sources for that are the linker map from the original build, the device’s memory table, and the behaviour of the code itself.

Reconstructing an address map from a binary

Three techniques, in increasing cost:

Look for the vector table. On C2000 the reset vector and the interrupt vectors sit at a known base with a known layout. Finding a plausible run of code addresses at that base fixes the offset of the whole file.

Look for the entry point pattern. Boot code initialises the watchdog, the clock and the PLL in a recognisable order. The first few dozen words are a signature that can be matched against a known build.

Disassemble and look for coherence. Branches that land on instruction boundaries, calls that return, table lookups that index within the file — all of these fail loudly at the wrong offset. A disassembly that is subtly wrong in a way that produces consistent garbage usually means the endianness is swapped or the word size is off by a factor of two.

The interleave question, concretely

If the export wrote each word as two bytes little-endian, the file begins with the low byte of the first instruction. Reassembling words as low | high << 8 restores the instruction. If the export wrote the high byte first, the same operation produces swapped opcodes — and C2000 opcodes are dense enough that swapped bytes usually still form a legal instruction, which is why this error survives a casual check.

The test that catches it: disassemble a few hundred words and look at the branch targets. Swapped bytes produce branches to addresses that are never instruction-aligned. That single check distinguishes the two byte orders reliably.

Fidelity of a replicated image

Once the mapping is right, three things still determine whether the replica behaves like the original:

  1. Configuration words. Clock, watchdog, boot mode, and the security configuration all live outside the code image and all change behaviour.
  2. Trim values. Analog blocks on this family carry factory trim. A copy without it runs, and measures wrong.
  3. The password region. If the source part was locked, that region cannot be read — so a “complete” binary is complete in the sense that it contains everything readable, which is not the same thing.

Item three is worth stating plainly: a binary from a locked part is not a copy of the part. It is a copy of whatever the part was willing to show, and the willingness is decided by the same security module that the file is supposed to circumvent.

A replication checklist that works

  • Obtain the file in a format that carries addresses, or reconstruct the map before programming anything.
  • Confirm the word/byte convention on a small known region before writing the whole array.
  • Verify the reset vector points at code that begins with an initialisation sequence.
  • Program configuration and trim explicitly; do not assume they came along.
  • Verify by reading back and comparing words, not bytes.
  • Boot a destination part and check a measurable output against the original.

The last step is the only one that proves the job. Everything before it proves the file is well-formed.

Related reading

FAQ

Is a hex file always better than a binary? For replication, yes — it carries addresses and checksums. A binary is only usable once its address map is known from another source.

Can a binary be twice the size of the flash? Yes, if each 16-bit word was exported as two bytes. Halving it produces a file that looks like the array but has word-sized offsets.

How do I tell the byte order of an unknown export? Disassemble and check branch targets for alignment. Swapped bytes produce unaligned targets.

Does the password region appear in a binary? Only if the part was unlocked when the read was taken. On a locked part it reads as zeros and is indistinguishable from erased flash.

Why does a replicated part boot but measure incorrectly? Almost always missing analog trim, which lives outside the code image.

Conclusion

A C2000 “binary” is a representation decision, not a fact. Word addressing, byte order and gap handling each introduce a way for the file to be wrong while looking right. Replication succeeds when the mapping is established before programming, configuration and trim are handled as separate items, and verification happens by reading words back rather than by trusting file size.

PostHeaderIcon TMS320F28075: Two Security Zones and the Pointer That Joins Them

Duplicating a microcontroller normally means one operation repeated: read the array, write it elsewhere. On a part with a single security module, that is close to accurate. The F28075 breaks the assumption, because its memory and its security configuration are divided into two independent zones, and the two can be configured to behave as one, as two, or as two where one is subordinate to the other.

The result is that a “full copy” of an F28075 is not one image. It is two images, two OTP configurations, and a relationship between them — and the relationship is stored in the same OTP that most other parts use only for the password.

Two zones, not one

The array is partitioned into zone one and zone two. Each has a password, each has a per-zone OTP block that controls how the password may be used, and each governs access to whichever flash sectors and RAM blocks were assigned to it. Code in zone one cannot read zone two and vice versa, unless a link is established.

That arrangement exists for a real product reason. A design that ships with a manufacturer-supplied bootloader in one zone and the customer’s application in the other wants the two to be mutually invisible: the bootloader vendor cannot read the application, and the customer cannot read the bootloader.

Configuration What it means for a read
Two zones, no link Each needs its own password; neither can see the other
Two zones, linked Presenting zone two’s password also releases zone one
One zone effectively unused Only the populated zone matters
Zone locked with password unknown That zone is unreadable; the other may still be open

The OTP block is the real configuration

Most of the parts discussed on this site keep their security state in a handful of flash bits. Here, each zone has an OTP region holding several independent lock fields, and each field answers a different question:

  • whether the password may be changed at all;
  • whether the CRC of the zone’s protected region is enforced;
  • whether RAM assigned to the zone may be allocated by code outside it;
  • whether code in the zone may be executed but not read.

That last field is the one most often missed. A zone configured for execute-only is not unreadable in the ordinary sense; it is readable by the instruction fetch path and not by the data path. Code runs from it normally, and any attempt to copy it as data returns something other than the code. A device in this state behaves exactly like a working product and yields nothing to a data copy.

Why duplication is a per-zone decision

Given the above, “duplicate this F28075” decomposes into a question per zone: is this zone read-protected, and if so, with what configuration? The answers can differ. A common shape is one zone open — the bootloader, deliberately left readable so the customer’s production line can verify it — and one zone locked.

Attempting a single pass over the whole array and then deciding what is missing is the wrong order. Read the OTP area first. It is small, it is outside the protected region, and it tells you which of the four configurations you are dealing with before any large transfer is attempted.

What a duplicate must reproduce besides code

A duplicated part that runs but does not behave identically has usually been copied at the array level and not at the configuration level. On this family, the items that must match are:

  1. The code image of each zone, at its original addresses.
  2. The password of each zone, or the decision to leave each zone open.
  3. The OTP lock fields, which govern what the next reader is allowed to do.
  4. The boot configuration, which decides which zone runs first.
  5. The calibration values the device reads at startup, if the design uses factory trim.

Item five is specific to parts with analog blocks that carry trim from the factory. Copy the code without the trim and the ADC reads with a systematic offset — a difference that looks like a firmware bug and is not one.

The link pointer, and why it matters at copy time

When zone one is linked to zone two, unlocking zone two unlocks both. This is convenient during development and a trap during duplication, because it means a device can appear to be fully open when only one password has been supplied. A technician who unlocks zone two, copies everything visible, and reports success has copied whatever zone one exposes through the link — which may be everything, or may be only the parts not individually restricted.

The check is straightforward: after unlocking, read a known code address in each zone and confirm the result is not zero. Zero on a part that should be populated means the zone is still closed, whatever the unlock sequence reported.

Execute-only zones and the limits of copying

If a zone is configured execute-only, the data path will not return its contents and no amount of re-reading changes that. What remains available is behavioural: the zone runs, so its code can be observed through its effects — which peripherals it touches, what it writes to shared RAM, what it sends on a bus.

For duplication purposes that is often enough. A bootloader’s job is well-defined, and a replacement that performs the same job at the same interface is functionally a duplicate even if it is not byte-identical. For an application zone, behavioural reconstruction is a much larger undertaking and the honest answer is that the copy will be an equivalent rather than a replica.

Ordering the work

The sequence that avoids wasted effort on this family:

  1. Read the OTP configuration for both zones.
  2. Determine which zones are populated, which are open, and which are execute-only.
  3. Unlock what can be unlocked; confirm by reading a known address.
  4. Copy open zones by ordinary read.
  5. For closed zones, decide between password recovery and behavioural reconstruction — these are different projects with different costs.
  6. On the destination part, program zones, then OTP, then boot configuration, then verify by running.

Step six is where copies fail. Programming the OTP before the code means the destination part locks itself out of its own array halfway through the process, and the part must be mass-erased and started again.

Related reading

FAQ

Can both zones be unlocked with one password? Only if the zones are linked. Without the link, each needs its own.

Is the OTP area readable on a locked part? The configuration fields are, which is why reading them first is the right opening move.

Does an execute-only zone defeat duplication entirely? It defeats copying as data. It does not prevent reconstructing behaviour from observation.

What happens if the destination’s OTP is programmed first? The part locks itself against the remainder of the write. It has to be mass-erased and redone.

Can a zone’s password be changed later? Only if the corresponding lock field in OTP permits it. Once that field is set, the password is fixed for the life of the die.

Conclusion

Duplication on the F28075 is a per-zone exercise governed by OTP rather than by the array. Read the configuration first, unlock per zone, confirm by reading known addresses, and treat execute-only zones as a behavioural problem rather than a data problem. The array is the easy part; the OTP is where the decisions are.

PostHeaderIcon PIC18F66K22: Reading the Protection Pattern as a Design Statement

A protection configuration is a decision made by a person, usually at the end of a production process, usually with a reason. The combination of bits that results is therefore a record — not of intent in the abstract, but of what that person expected to happen to the product afterwards.

On a 64K part with four blocks, a boot region and two kinds of bit, the number of realistic patterns is small, and each corresponds to a recognisable product lifecycle.

The patterns

Boot region Application blocks Reading
Open Open Development unit, or production oversight
Open Closed Vendor loader is public, application is the asset
Closed Open Loader is the secret, application is field-serviceable
Closed Closed Opaque product; service by replacement

The second row describes products whose loader is documented — often because a distributor or a contract manufacturer needed to program blank devices, and publishing the loader was simpler than distributing it under agreement.

The third describes the opposite trade: the loader is the vendor’s differentiated asset and the application is ordinary. It is less common but appears in products where the loader contains a proprietary protocol or an authentication scheme.

What each pattern predicts

Open and open. No service constraint, so an update image is probably obtainable, and the production record probably still exists. This is the easiest case and the one people fail to check for.

Open loader, closed application. A field update path almost certainly exists. The loader will describe the image format and the application’s extent. Start there.

Closed loader, open application. The application can be read; the loading protocol cannot. The device is analysable and not updatable, which suggests service by replacement rather than by reflash.

Closed and closed. The device is opaque and the product was designed to be replaced. The remaining evidence is behavioural, plus whatever exists outside the device — schematics, sibling units, vendor documentation.

The bits that are not about protection

Two settings in the same configuration word are frequently mistaken for security and are not:

Low-voltage programming disable. It changes how the device is entered, not what may be read. Its presence in a locked device is common and its practical effect is to require a high-voltage entry.

Write protection. It freezes a region. A boot region that is write-protected and readable is a design that prevents field modification of the loader while allowing a technician to verify it.

Both appear alongside genuine protection bits and both change what is possible on a bench, which is why reading the configuration as a whole matters more than looking for one field.

Using the pattern before touching the device

The pattern is readable without attempting anything else, and it should be read first. Three consequences follow immediately:

  • whether a read attempt is worth starting at all;
  • which regions, if any, will respond;
  • whether an update path is likely and therefore whether the behavioural route is the productive one.

That last is the practical payoff. A device whose configuration indicates a field-updatable product can be analysed almost entirely from its update traffic, without ever needing the array.

When the pattern contradicts the product

Occasionally the configuration says one thing and the product does another: an open loader with no update interface implemented on the board, or a closed device with a documented service procedure that requires reading it.

Both occur, and both are informative. The first indicates a design that was planned for updates and shipped without them — often because the interface was cut late. The second indicates that the vendor’s service procedure relied on something other than reading the device, usually a replacement part.

The limits of inference

A pattern is evidence, not proof. Configuration can be rewritten, including by a bootloader at runtime, so a device read after an update may carry settings the factory did not apply.

Reading the configuration twice — immediately after reset and after the application has run — resolves this, and the difference between the two readings is itself a statement about the design: a device whose configuration changes at runtime has a loader that manages it.

Related reading

FAQ

Can the pattern be read without unlocking anything? Yes. Configuration is readable through the programmer on this family.

Does a closed boot region mean the loader is valuable? Often. It is the one region whose protection implies a deliberate decision.

Is write protection part of the security design? It restricts modification, not reading. It is a separate decision that often accompanies protection.

Why read configuration twice? Because a bootloader can rewrite it, so the value after reset may differ from the value in operation.

What if the pattern contradicts the product’s behaviour? That contradiction is information: a planned feature that was not shipped, or a service procedure that did not rely on reading the device.

Conclusion

The protection pattern is a design statement written at the end of a production line. Reading it before doing anything else predicts the device’s lifecycle, indicates whether an update path exists, and decides whether the expensive techniques are needed at all. That is a lot of information from a handful of bytes.

PostHeaderIcon PIC18F46K22: Working With Three Quarters of an Image

Sixty-four kilobytes divided into four blocks, three of them readable. The arithmetic suggests seventy-five percent of the work is done, and the arithmetic is wrong in both directions: the readable portion is more useful than its share, and the missing portion matters more than its size.

The reason is that the missing block is usually the one containing the entry points, and entry points are what turn a byte sequence into a program.

What the missing quarter typically contains

On a device configured by a vendor who understood protection, the first block holds:

  • the reset vector;
  • the interrupt vectors;
  • start-up code, including the clock configuration;
  • whatever small routines the linker placed early.

Losing those removes the anchors and the initialisation, and keeps the application’s body — which is the bulk of the code and the part that is hardest to interpret without the rest.

Missing Present Consequences
Vectors, start-up, small routines Application body, tables No anchors; clock unknown
Application body Vectors, start-up Anchors present; behaviour unclear
Application body, tables Vectors, start-up, small routines Structure known; logic missing
Everything Nothing Behavioural work only

The first row is the common case and, awkwardly, the worst of the three partial outcomes.

Reconstructing the anchors

Four techniques, all usable on the readable three quarters:

Call target histogram. Every call carries its destination. Destinations that appear many times are library-like utilities; destinations that appear once, from a single site, are usually application functions. The histogram gives a provisional function list.

Handler recognition. A handler saves the working registers, does something short, restores and returns. The prologue and epilogue are distinctive, and their absence in the missing block tells you the vectors pointed into the readable region.

Table and dispatcher pairs. A jump table is a run of addresses followed by the dispatcher that indexes it. Finding one gives a set of entry points without needing vectors.

Entry-sequence matching. Start-up code initialises the clock in a fixed order. If any fragment of it survives, it identifies the reset path and gives the clock.

The clock is the first thing to establish

Without the start-up code, the clock configuration is unknown, and every timing constant in the readable code becomes uninterpretable. A delay loop of two hundred iterations is meaningless until you know the instruction rate.

Three ways to recover it, in order of preference:

  1. Measure it — an oscillator output pin, or a timed output.
  2. Infer it from a protocol — a serial rate is exact and derives from the clock.
  3. Constrain it from behaviour — a control loop period bounds the clock from below.

The second is usually available and usually ignored. A UART or CAN rate observed on a bus fixes the oscillator within a small tolerance, and that is enough.

Handling the image honestly

A partial image must be stored and passed on as partial. Practical measures:

  • record the block map with the image;
  • store the missing region as absent rather than filled, so that any use of it fails visibly;
  • note the configuration and the revision;
  • state which of the anchors were reconstructed rather than read.

Without those, a partial image is indistinguishable from a complete one, and the eventual failure will be attributed to the device rather than to the file.

When the missing quarter is fatal

Three situations where three quarters is not enough:

  • The application’s behaviour depends on start-up ordering that cannot be observed.
  • The clock cannot be measured or inferred.
  • The missing block contains tables rather than code, and the tables are the domain knowledge.

The third is the one that surprises people. A block chosen for protection is sometimes chosen because it holds constants rather than because it holds vectors, and constants cannot be inferred from behaviour the way control flow can.

Related reading

FAQ

Is three quarters of an image useful? Yes, and less than it appears: the missing block usually holds the anchors and the clock configuration.

Can entry points be found without vectors? Yes, from call targets, handler shapes and jump tables.

How is the clock recovered? By measurement, by inference from a serial rate, or by bounding it from a control loop period.

Should the missing region be filled? No. Leave it absent so that any use of it fails visibly.

When is a partial image not worth completing? When the missing block holds the domain constants rather than the control flow.

Conclusion

A three-quarter image is a workable position and a misleading one. The readable bulk is the application, the missing quarter is the frame that makes it readable, and the recovery of the frame — clock, entry points, handlers — is what determines whether the partial image becomes a program.

PostHeaderIcon PIC18F43K22: Duplication Is a Matching Problem, Not a Copying One

Copying is a transfer. Duplication is a correspondence, and the correspondence has four dimensions: the program, the configuration, the data array, and the physical device. A copy addresses one of them. Most duplication failures are the other three.

The 43K22, with eight kilobytes of program memory in a 40-pin package, is a good case to reason about because the array is small enough that everything else is proportionally larger.

The four dimensions

Dimension Reproduced by Fails as
Program array Programming the image Code runs but behaves differently
Configuration Writing config explicitly Wrong clock, watchdog, or boot behaviour
Data array Copying, or leaving blank deliberately Measurement offset, wrong settings
Silicon Nothing — it is a property of the part Small consistent differences

The fourth is the one that cannot be closed, and pretending otherwise wastes time. Analog trim and silicon revision belong to the die. A duplicate is therefore an approximation whose error is bounded by those two factors, and the practical question is whether the bound is acceptable for the application.

Configuration: the dimension that is usually skipped

Programmers treat configuration as a setting rather than as content, and tools reinforce this by offering it as a separate operation. A hex file exported from the array may or may not include it.

The result is a device that boots, runs the code, and differs in ways that are hard to attribute:

  • Watchdog enabled on one and not the other, which shows up as a device that resets under load.
  • Different oscillator source, which shifts every timing relationship.
  • Different brown-out threshold, which changes behaviour at low supply.
  • Different low-voltage programming setting, which changes how the device can be entered later.

Each of these is a field in the configuration word, each is comparable, and none is in the code.

Data array: decide, do not default

The small data array on this family holds whatever the application decided to keep: settings, offsets, counters, sometimes a copy of the serial number.

Three choices, and the honest one depends on purpose:

  • Copy the original’s array. The duplicate behaves like the original, including its accumulated state.
  • Leave it blank. The firmware writes defaults; whether that is correct depends on the design.
  • Write a known set. Correct when the values are documented and reproducible.

Choosing by default — that is, leaving it blank because nothing was decided — is the most common of the three and the least defensible.

What a duplicate cannot fix

Two differences survive any amount of care:

Trim. Analog blocks carry per-die trim. A duplicate that measures a small offset from the original is showing trim, not a code error. The fix is recalibration, not reprogramming.

Revision. Errata differ between revisions, and firmware written to avoid a specific erratum may behave differently on a die where the erratum does not exist — or vice versa. On a device this size the effect is usually small and occasionally decisive.

Recording the revision at duplication time is cheap and answers the question later.

Verifying a duplicate

The verification that matters compares behaviour, not files:

  1. Program the image and the configuration; write or deliberately omit the data array.
  2. Read everything back and compare against the record.
  3. Run both devices on the same inputs and compare outputs at every accessible point.
  4. Compare timing, not just values — a duplicate that produces the right answer late is not a duplicate.
  5. Run the fault cases the original was known to handle.

Step four catches configuration differences that step three misses, because a wrong oscillator often changes timing before it changes logic.

When duplication is the wrong tool

If the firmware depends on a per-die value — a unique identifier used in a key, a trim value baked into a calculation — copying produces a device that runs and computes differently. In that case the work is to understand the dependence, which is a reconstruction problem rather than a duplication one.

Deciding this before starting requires reading the program. On a device where that is impossible, the dependence can often be detected from behaviour: a duplicate that works in every mode except one is usually hitting a per-die assumption in that mode.

Related reading

FAQ

Does copying the array duplicate the device? It duplicates one of four dimensions. Configuration, data and silicon remain.

Why does a duplicate reset under load? Usually a watchdog setting that differs from the original’s.

Should the data array be copied? Only if the duplicate must reproduce the original’s accumulated state.

Can trim be transferred? It can be written, but it belongs to the die, so the result measures like the source silicon.

How is a duplicate verified? By comparing outputs and timing on identical inputs, and by exercising the fault cases.

Conclusion

Duplication on this part is a four-dimensional matching problem in which the easiest dimension is the one everyone does. Configuration, data array and silicon decide whether the second device is a duplicate or merely a device with the same program — and only behavioural verification distinguishes the two.

PostHeaderIcon PIC18F23K22: Write Protection Is Not Read Protection

Two bits sit next to each other in the configuration word, both named for protection, both applied per block. One stops you reading the array; the other stops you writing it. They are independent, and the independence is the source of an expensive mistake that happens on benches regularly: a device that could have been read is erased, on the assumption that removing write protection would expose it.

Getting these straight is a five-minute exercise that saves devices.

What each one does

Code protection gates reads. With it set, the array cannot be read from outside the device — through the programmer, or through table reads from unprotected code. The device still runs.

Write protection gates modification. With it set, the block cannot be erased or programmed. The array remains fully readable if code protection is clear.

Read-protected Write-protected Read Modify What it implies
No No Yes Yes Development, or unlocked production
No Yes Yes No Fixed content, readable — the useful case
Yes No No Yes Locked but recoverable by erase
Yes Yes No No Fully closed

The second row is the one people fail to look for. A device with write protection and no read protection is a device whose content is available right now, and it is also the configuration a vendor chooses for a boot block that must never change.

Why a vendor protects writes without protecting reads

Because it is the configuration that makes a fixed region safe without making it secret. A bootloader in the boot block should never be modified by field activity; it does not necessarily need to be hidden.

There is a second motive, less flattering: some production processes set write protection because the tooling offers it in the same dialog as code protection, and nobody separated the two. Those devices are readable, and the fact that they are readable is discovered only by trying.

The mistake, in full

The sequence that destroys images:

  1. A device will not respond to a read. The reader concludes “protected”.
  2. The reader decides to remove protection by erasing.
  3. The erase clears the array, and with it the program.
  4. The device is now readable and empty.

Step one is where the error occurs, and it usually comes from treating a failed read as evidence of code protection. A failed read has several causes: wrong part selected in the tool, wrong programming entry voltage, low-voltage programming disabled so the entry method is wrong, or a device whose configuration is genuinely protective.

Only the last of those justifies an erase, and it is distinguishable from the others by reading the configuration word — which is exactly the read that remains available when everything else is closed.

Order of tests that avoids the mistake

Before any modifying operation:

  1. Read the configuration word. It states both protection settings.
  2. Attempt to read a known-populated address. The vector table at the bottom of the array is the standard target, since every program has one.
  3. If that read returns zeros while the configuration says code protection is clear, the problem is the interface, not the device. Fix the interface.
  4. Only if the configuration states code protection is set, consider whether an erase is acceptable — which requires knowing that the content is expendable.

Step four is the point where a decision has to be made honestly. Erasing to unprotect is a valid technique for a device whose program exists elsewhere. It is a total loss for a device whose program does not.

Write protection’s own complications

A write-protected block is protected against the ordinary programming sequence, and removing the protection requires an erase — of the whole device on this family, since configuration is erased with the array.

There is a further wrinkle: some write-protect bits are applied by a bootloader at runtime, so a device can be writable when read immediately after reset and write-protected once the application is running. Reading the configuration twice catches this, and it is a useful signal that the device has a bootloader at all.

What survives a partial attempt

If an erase was performed and the program was expendable, the device is restored and the story ends well. If it was not expendable, what remains is:

  • the behaviour recorded before the erase, if anyone recorded it;
  • sibling units with the same build, if any exist;
  • the vendor’s update package, if the product had one.

Nothing in the array. This is why the checklist above is worth more than the technique it protects: the technique recovers a device, and the checklist decides whether the device should be touched at all.

Related reading

FAQ

Does write protection stop a read? No. Write protection gates modification; read protection gates reads.

Can write protection be removed without an erase? Not on this family. Configuration is cleared by the erase that removes the protection.

Why would a device be writable but unreadable? That is a locked part. It can be erased and rewritten, which recovers the device and loses the program.

Is a failed read proof of code protection? No. Wrong part selection, wrong entry voltage and disabled low-voltage programming all produce a failed read.

Can a bootloader change these settings? Yes, which is why the configuration should be read both after reset and during operation.

Conclusion

Two adjacent bits, two different questions, and a habit of treating them as one. Code protection hides the array; write protection freezes it. Reading the configuration word before touching anything tells you which applies, and that single read is what stands between a recoverable device and an erased one.

PostHeaderIcon PIC18F46K20: Where a 64K Copy Diverges From the Original

At sixty-four kilobytes the array is large enough that a copy is a serious operation and small enough that every byte is meaningful. Reading it and writing it elsewhere is mechanical. Making the second device behave like the first is not, and the divergences are all in places that a file comparison will show as differences with no obvious cause.

Four of them account for most failed replications.

One: padding between sections

Linkers align sections, and the space between them is filled with the erased value or with a defined padding byte depending on the toolchain’s settings. A copy that reproduces the code but not the padding differs in the gaps.

Does the padding matter? Sometimes. A routine that reads past the end of its table, or a checksum that covers an aligned range, will see the difference. On a part where a verification routine checksums a range rather than a section, padding is part of the verified content.

The rule: copy the array as read, gaps included, rather than reconstructing it from sections.

Two: regions that were never written

Not every address in a 64K array holds content. A device using 40K has 24K of erased flash, and a copy that fills those regions with anything else differs.

This is usually harmless, and it becomes visible when something reads the erased region deliberately — a version scan, a memory dump command, a self-test. A device that reports “unused space is zeros” on the original and “unused space is FF” on the copy is a device whose copy is detectable.

Region Original value Copy risk
Programmed sections Content None if copied exactly
Section padding Toolchain-defined fill Differs if reconstructed
Unused flash Erased value Differs if filled
Configuration Set at production Differs if not copied
Data array Per-unit Differs by design

Three: table encoding

Constant tables are where a copy is most likely to be subtly wrong, because the representation is a convention rather than a specification. A 16-bit constant in a table might appear as two words, as one word per byte, or as a single word if the values fit.

A copy taken byte for byte is correct by construction. A copy reconstructed from a disassembly is not, and the resulting errors are small — a filter coefficient that is slightly wrong produces a device that works and sounds different.

The rule is the same as for padding: copy the array, do not rebuild it.

Four: configuration

Configuration is not in the array and decides the oscillator, watchdog, brown-out and protection. It is discussed in detail elsewhere; here it belongs in the list because it is the divergence that produces the largest behavioural difference with the smallest file difference — often zero bytes of code difference.

The verification that catches all four

Compare four things, in this order:

  1. The array, byte for byte, including gaps and unused regions.
  2. The configuration, byte for byte, against the recorded source values.
  3. The data array, by decision — copied, or deliberately blank.
  4. Behaviour, on a bench, against recorded behaviour of the original.

Steps one and two catch everything mechanical. Step four catches what the files cannot: timing, start-up order, response to faults.

What a copy cannot reproduce

  • Analog trim, which belongs to the die.
  • Silicon revision, which decides errata.
  • The unique identifier on parts that carry one.
  • The device’s history, if the firmware records usage in the data array.

Each of those produces small, consistent differences that are properties of the device rather than defects in the copy. Recognising them prevents a long search for a bug that is not there.

The larger point

Replication is a matching problem with four dimensions, and the easiest one — the code — is the one that a file comparison addresses. The other three are configuration, data and silicon, and a replication that succeeds at the first and ignores the rest produces a device that runs and is not the same device.

Related reading

FAQ

Does padding matter in a copy? Sometimes. If anything checksums an aligned range, it is part of the verified content.

Should unused flash be filled? No. Copy it as read, or leave it untouched.

Why do tables cause trouble? Because their encoding is a convention. A byte copy is correct; a reconstruction may not be.

What is the costliest divergence? Configuration, because it changes behaviour with no difference in the code.

Can a copy be exact? Only at the array level. Trim, revision and identifier belong to the die.

Conclusion

A 64K copy diverges in four places: padding, unused regions, table encoding and configuration. Three are solved by copying the array rather than rebuilding it, and the fourth by treating configuration as content. The remainder — trim, revision, identifier — cannot be copied, and knowing that saves the search for a bug that is a property of silicon.

PostHeaderIcon PIC18F23K20: Reading the Configuration Word Before Anything Else

There is a strong instinct, when confronted with a device that will not give up its program, to attack the program directly. That instinct is usually wrong on this family, because the most informative thing on the device is not the array — it is a short run of registers in a separate address space that says what the device is configured to do.

Those registers are readable when the array is not, they are small, and they answer the questions that otherwise become guesswork: is the array protected, is the watchdog running, what clock does the board have to provide, can the device be entered through a low-voltage interface.

Where the configuration lives

The configuration registers sit in their own region of the address map, outside the program array. Each is a byte, they are consecutive, and together they decide the device’s operating envelope.

Because they are byte-wide while the core is word-oriented, tools present them inconsistently: some show eight bytes, some show a merged word, some show a single hex value with fields labelled. The inconsistency is a nuisance rather than a problem, as long as the field positions are taken from the programming specification rather than inferred from a tool’s display.

Group Decides Why it matters for analysis
Oscillator Clock source, PLL, fail-safe What the board must supply
Reset and watchdog Watchdog, brown-out, power-up timer Whether timing measurements are stable
Memory protection Code protect, table-read protect Whether a read can succeed at all
Write protection Per-block write protect Whether the array can be modified
Programming Low-voltage programming How the device can be entered

Protection bits are not one bit

On this family the protection fields are several, and they answer different questions:

  • Code protection, per block, gates reads from outside.
  • Table-read protection, per block, gates reads from running code.
  • Data EEPROM protection, a separate bit for the data array.
  • Boot block protection, which applies to the small region holding the reset vectors.

Reading the configuration tells you which of these are set. It does not tell you the password, because there is no password on this family — the bits are the whole mechanism.

That is worth stating explicitly, because it is a common misconception carried over from parts that do have a password. Here, protection is a set of configuration bits and nothing else. There is no value to guess.

Why the configuration is readable when the array is not

The programmer needs it. Before it can read or write anything, it must know the device’s programming voltage, its oscillator setting and its code-protect state, and it obtains those from the configuration registers.

This is a deliberate design choice and it costs the protection scheme very little: knowing that a device is protected does not help you read it. What it does is make analysis possible, because the state of the device is knowable in advance.

What the oscillator setting tells you

An unexpected amount of diagnostic value sits in the oscillator field.

A device configured for an external crystal needs a crystal on the board, and a board whose crystal has failed presents a device that does not run — indistinguishable, from the outside, from a device with a corrupted program. A device configured for the internal oscillator runs with nothing on the board at all.

The failure modes are opposite and the configuration distinguishes them in one read. That single fact resolves a category of “dead device” reports that would otherwise consume a bench session.

Write protection as evidence of intent

Write-protect bits record decisions made at production time, and they persist. A device whose boot block is write-protected and whose application block is not was designed to be field-updated. A device with everything write-protected was not.

That history is often more useful than the code. It tells you whether an update path exists, whether the vendor expected units to be reprogrammed, and therefore whether an update image is likely to be obtainable from the vendor’s own distribution.

The order of operations

  1. Read the configuration registers and record them verbatim.
  2. Interpret the oscillator and programming fields; they decide how to connect.
  3. Interpret the protection fields; they decide what is possible.
  4. Attempt an array read only after the first three are established.
  5. If the array is protected, decide between erase-and-restore, behavioural reconstruction, and stopping.

Step five is a real option and is chosen less often than it should be. On a part with 8K of program memory and no unique behaviour, the cost of reconstruction can exceed the value of the result, and the configuration read has already told you everything the device was configured to reveal.

Limits

  • The configuration registers say nothing about what the array contains.
  • They say nothing about whether the device is the part its marking claims; a remarked device can carry different configuration behaviour.
  • They are writable, so a device that has been through an update may carry configuration set by the bootloader rather than by the factory.

That last point argues for reading the configuration twice: once immediately after reset, and once after the application has had time to run.

Related reading

FAQ

Is there a password on this family? No. Protection is a set of configuration bits; there is no value to supply.

Can the configuration be read when the array is protected? Yes. The programmer needs it to operate, so it remains accessible.

Does a protected device still run? Yes. Protection gates reads, not execution.

Why read the configuration twice? A bootloader can rewrite it at runtime, so the value after reset and the value during operation may differ.

Does write protection hide contents? No. It prevents modification only.

Conclusion

The configuration registers are the cheapest and most informative read on this part: they say whether the array is protected, what the board must provide, how the device can be entered, and what the vendor intended at production time. Starting there converts a speculative job into a planned one — and sometimes into the conclusion that no further work is warranted.

PostHeaderIcon PIC18F14K50: What a USB Device Tells You Before You Read a Byte

A code-protection bit stops a programmer reading the array. It does not stop the device from doing its job, and for a USB peripheral the job begins with describing itself. Before any application-level exchange, the host asks for a device descriptor and the firmware answers with a structure that it must have been built to produce.

That answer is a statement about the firmware, made by the firmware, in a format defined by a standard. It is not protected, it cannot be protected, and on a locked device it is the first real evidence available.

The descriptor set, and what each part says

Enumeration proceeds in stages, and each stage yields something different:

Descriptor Contains What it narrows
Device Vendor and product ID, class, version Product family, vendor, firmware generation
Configuration Power, interfaces, endpoints Communication shape
String Manufacturer, product, serial Naming conventions, sometimes a build identifier
Endpoint Transfer type, size, interval Timing budget of the protocol

The vendor and product identifiers are usually the most specific. They are allocated, they appear in the vendor’s driver, and on a product that reused a development ID they can identify the design house rather than the product.

String descriptors are the ones people forget to look at. A product name string frequently contains a version, and a version identifies a build — which is the single most useful fact when the goal is to find the corresponding update package.

Why the protocol is recoverable

USB’s lower layers are fixed by the specification, so the only unknowns are the application protocol and the vendor-specific requests. Both are observable from the host side:

  1. Capture the bus during normal operation with the vendor’s own software running.
  2. Separate control transfers from bulk or interrupt traffic.
  3. Identify the vendor-specific requests by their request codes.
  4. Map each request to the response length and content.

The result is a protocol description, and a protocol description plus the descriptor set is most of a specification. What remains is the internal logic that produces the responses, which is precisely what the protection was for.

The 16K question

The array on this part is 16K, which is enough for a USB stack and a small application. That has a practical effect on reconstruction: a USB stack is largely boilerplate, and boilerplate is predictable. What is not boilerplate is the vendor’s logic between the endpoints.

An experienced reader can therefore estimate the proportion of the image that is stack and the proportion that is application, and the second proportion is small. On a part this size, the non-standard code is often a few kilobytes, and a few kilobytes of behaviour is characterisable.

What the protection configuration can still tell you

The configuration words are usually readable through the programmer even when the array is not, and on this family they answer specific questions:

  • whether code protection is on for the whole array or one block;
  • whether the boot block is separately table-read protected;
  • whether low-voltage programming is enabled, which decides how the device can be entered;
  • the oscillator selection, which tells you whether the board provides a crystal.

The third item is operationally important. A device with low-voltage programming disabled requires a high-voltage entry, which changes the hardware needed to talk to it at all. Discovering that after building a fixture is a waste of a week.

The bootloader, if there is one

Microchip’s USB stack includes a bootloader, and many products ship with it. A device with a working bootloader accepts an update over USB, which means:

  • a known-good image can be loaded without any programmer;
  • the bootloader’s existence is confirmed by its response to the entry sequence;
  • the update format reveals the memory layout the vendor used.

That last point is subtle and valuable. A bootloader that accepts records with addresses tells you the address map of the application it expects, and the map constrains where the application’s code and constants sit.

When the answer is “not this device”

Not every locked USB device is worth pursuing. Three conditions make it a poor use of effort:

  • The vendor’s driver is available and the protocol is documented, in which case a rebuild is straightforward and an extraction is not needed.
  • The product is one of many and a working unit exists, in which case duplication is the answer.
  • The proprietary logic is small and the value is in the hardware, in which case the firmware is not the asset.

Conversely, a device is worth pursuing when it is the only unit, its protocol is undocumented, and its function cannot be reproduced from behaviour. Those three together are the case where reading the array actually matters.

A short procedure

  1. Enumerate the device and record every descriptor verbatim.
  2. Capture traffic during normal operation and during a firmware update, if one is possible.
  3. Read the configuration words.
  4. Determine whether a bootloader is present and what format it accepts.
  5. Decide, on the evidence, whether the remaining unknown is worth the cost of extraction.

Step five is the one that gets skipped, usually because steps one to four are interesting enough to continue past the point where the decision should have been made.

Related reading

FAQ

Can descriptors be suppressed on a locked device? No. Enumeration is required for the device to function as a USB peripheral.

Are string descriptors always present? No, but when they are they frequently carry a product name and a version.

Is the USB protocol enough to rebuild the firmware? It is enough to rebuild a device that behaves identically at the interface. The internal logic remains unknown.

Does code protection affect the bootloader? It can, depending on configuration. The boot block is often left writable so that updates remain possible.

How do I know low-voltage programming is enabled? From the configuration word. It determines which entry method the device accepts.

Conclusion

A USB peripheral describes itself as a condition of working, and on a protected device that description is the cheapest information available. Descriptors, strings, endpoints and captured traffic together constrain the firmware to a small space — often small enough that the remaining question is whether extraction is worth doing at all.

PostHeaderIcon Microcontroller with Wide Data Bus Memory Content Extraction

The microprobing experiments showed how easily a Microcontroller with Wide Data Bus Memory Content Extraction can accomplished. The fact that only a single bit in the instruction set could defeat branch instructions could pose some security implications. Also, the presence of a weak pull-up in the data bus results in the cut bus lines to stuck at logic.

Microcontroller with Wide Data Bus Memory Content Extraction

Microcontroller with Wide Data Bus Memory Content Extraction

However, if a memory encryption was used this would require more sophisticated approach, for example, by injecting random data and observing the response from the CPU [12]. Nevertheless, high orthogonality of instruction sets in most RISC CPUs could help the attacker in finding the right combination to influence the MCU code execution.

Live Microcontroller decapsulation experiments proved the possibility of opening up battery powered devices without interrupting their constant power supply. This might have some consequences for highly secure applications where such devices are used. This could be medical devices or hardware security modules (HSM) used in banking or industrial applications.

Once the surface of the chip with battery-backed SRAM is accessed, the contents of the memory could be microprobed either by microprobing exposed data bus lines [12] or by exploiting test points. Both approaches though would require the use of a laser cutter to cut through passivation layer [2]. For devices fabricated with deep submicron process a Focused Ion Beam (FIB) machine will be required to establish a connection with internal data bus. However, such machines are available in many places for rent at a price below $100 per hour.