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:
- Configuration words. Clock, watchdog, boot mode, and the security configuration all live outside the code image and all change behaviour.
- Trim values. Analog blocks on this family carry factory trim. A copy without it runs, and measures wrong.
- 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
- TMS320F2809 and the password read sequence — what a locked part will and will not hand over.
- TMS320F28234 and the OTP area — the region that sits outside the image and inside the behaviour.
- TMS320F28067 and the meaning of a locked read — why zeros are not evidence of an empty array.
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.