Posts Tagged ‘copiar datos de firmware integrados de microordenador stm32f103c4’

PostHeaderIcon STM32F103CB: How to Tell a Real Dump From a Confident One

The failure mode that costs the most time in this work is not a device that refuses to respond. It is a device that responds with the wrong thing, and a tool that reports success.

Read protection on this family returns zeros for a blocked read. It does not raise an error, it does not time out, and it does not tell the transfer layer that anything is wrong. A naive tool saves sixteen thousand zeros, closes the file, and prints a green message. The operator has an image, a checksum, and no idea that nothing was read.

Four states a region can be in

Everything below follows from being able to tell these apart.

What you read What it means Is it a failure
All zeros Blocked read, or a genuinely zeroed region Usually yes
All ones Erased flash Not a failure, but not content
Repeating pattern Bus stuck, or a mirrored address Yes
Mixed, structured Real content Probably not

The check is to read the same address three times and compare, and to read a known-populated address and a known-blank address and confirm they differ. Two reads that differ mean the transfer is unreliable. Two reads that agree and are all zeros mean the read is blocked.

Structural checks on a candidate image

An ARM Cortex-M image has properties that a correct program cannot avoid, and checking them costs seconds.

  1. The first word is the initial stack pointer. It must be a RAM address, word aligned, and near the top of RAM rather than at the bottom.
  2. The second word is the reset vector. It must lie inside the flash region, and the low bit must be set, because this core executes Thumb code.
  3. Every entry in the vector table must point inside the flash region or be zero, and none may point into RAM except where the design deliberately relocates a handler.
  4. The bytes immediately after the vector table should disassemble as plausible instructions rather than as random data.

A file that fails any one of those is not a program. A file that passes all four is a candidate, not yet a confirmation.

Entropy as a sanity check

A compiled program is not random. It has regions of high entropy, which are the instruction streams and the compressed constants, and regions of low entropy, which are tables, padding and repeated structures. A real image shows that variation across its length.

An image that is uniformly random is usually a read of a floating bus. An image that is uniformly low entropy is usually a blocked read with a repeating value. An image whose first half is plausible and whose second half is all ones is usually a transfer that stopped.

Plotting the byte distribution by page, rather than computing a single figure for the whole file, is what makes this useful. A single figure hides exactly the failures that matter.

The half-word problem

Programming on this family is done in half words, and an interrupted programming cycle leaves a location in an intermediate state: the low half written, the high half still erased, or a value that is neither the old nor the new content.

That state is not visible in a checksum of the whole image, and it does not stop the program from loading. It shows up later as a single corrupted constant, usually in a table, producing a behaviour that makes no sense from the code.

When a recovered image produces plausible but subtly wrong behaviour, the thing to check is not the algorithm but the data tables, and the way to check them is to compare a second, independent read of the same addresses against the first.

Using the program to verify itself

Where the design includes any checksum or CRC routine, the recovered image carries a verifier that was written by the original author. Running it against the image is the strongest available evidence that the image is intact — stronger than any external check, because it tests the same property the product tested at startup.

The obstacle is that it usually runs on the device, not on the host. Two ways around that: run it on a development board with the same core, or extract the polynomial and the covered range and implement the same check on the host.

The second option is less work than it sounds. A CRC routine in a small embedded program is a dozen instructions with a known polynomial, and finding it in the disassembly is a matter of looking for the table or the shift-xor loop.

Comparing two units

Two units of the same product from the same production run should differ in a small, identifiable set of bytes: identity fields, serial numbers, calibration values written per unit. Everything else should match.

Comparing two images and classifying the differences is therefore a powerful check on both. A large scattered difference across the code region means at least one of the two reads is corrupt. A small cluster of differences at a few addresses is the expected signature of a real image pair, and it also identifies where the unit-specific data lives — which is exactly what a duplication job needs to know.

What to record with the image

An image without context becomes unusable six months later. The minimum record:

  • the device marking and the die identifier read from the part,
  • the protection state and how it was determined,
  • the read path used, and its error checking,
  • the vector table values, written out in full,
  • the SHA-256 of the image, and of the second independent read if one was made,
  • the map of unit-specific fields identified by comparison,
  • the disassembly of the first hundred instructions, with the tool and version named.

That record turns a file into evidence, and evidence is what makes the result reproducible when a customer comes back with a device that does not behave.

Related reading

FAQ

Why does a blocked read return zeros instead of an error? Because the protection is implemented in the memory path, not in the protocol layer.

Is an all-ones image a successful read? It is a successful read of erased flash. Whether that is the content is a separate question.

Can a corrupted image still run? Yes, if the corruption lands in a data table rather than in code. That is the hardest case.

What is the single best check? The program’s own startup checksum, if it has one.

Conclusion

A dump is a claim, and claims need evidence. Check the vector table, look at entropy page by page, read twice, compare against a second unit, and let the program verify itself where it can. The tools will report success either way; only these checks distinguish a recovered program from a file full of zeros.