Posts Tagged ‘recuperar a memória flash do Texas Instrument TMS320F28068FP MCU’

PostHeaderIcon TMS320F28068F: When Part of the Program Is Not in the Flash

A flash read is normally a complete description of a device’s firmware. On the F28068F that is not true, and the exception is not a corner case — it is a design feature that the part exists to provide. Alongside the C28x core sits a second processor with a separate program memory, and firmware that uses it puts real logic there.

The consequence for anyone reading this device is specific and easy to miss: the image obtained from flash is complete in the sense that it is everything in the array, and incomplete in the sense that it is not everything the product does. A copy made from that image boots, initialises, and then computes the wrong numbers.

Two processors, two address spaces

The control law accelerator is not a co-processor bolted onto the C28x pipeline. It has its own program counter, its own registers, its own instruction set — a small floating-point-oriented one — and its own memory. Its program is loaded into a dedicated RAM block, and it executes from there.

That last property is the important one. The accelerator does not execute from flash. Its code has to be copied into its RAM at startup, normally by the C28x during initialisation, and then the accelerator is started.

So the flash image contains the source of the accelerator’s code as data, and the accelerator’s code as executed exists in RAM. Both are needed for a faithful copy, and they are in different places.

Where the code is How it gets there Does a flash read capture it
C28x program Programmed into flash Yes
Accelerator program Copied from flash to accelerator RAM at boot Yes, as data
Accelerator program written at runtime Computed or received, then loaded No
Accelerator data tables Copied from flash Yes, as data

Why the third row exists

The pattern that defeats a flash read is firmware that generates or receives accelerator code rather than storing it. It is less exotic than it sounds: a control loop whose coefficients are computed from a calibration step, or a field-updatable algorithm delivered over CAN, both produce accelerator code that never exists in the flash array at all.

On such a device the flash image contains the loader and the coefficients, not the loop. A copy runs fine and controls nothing.

What the accelerator changes about protection

The security module protects the main array and the RAM blocks assigned to it. The accelerator’s memory is RAM, and RAM protection on this family is a separate question from flash protection — the same module governs it, but the configuration bits differ, and the RAM allocation is per zone rather than per sector.

This produces an asymmetry worth knowing: a device can be configured so that the flash is readable and the accelerator’s RAM is not. In that state, a straightforward read returns the array and misses the running code entirely — and nothing in the read reports a gap.

Detecting that a device uses the accelerator

Before worrying about copying it, establish whether it is there. Several signals, any of which is sufficient:

  • The initialisation sequence writes to the accelerator’s control registers. Their addresses are fixed and recognisable in a disassembly of the boot code.
  • The boot code contains a block copy to a RAM range that is not used for data — a memcpy whose destination is executed from shortly afterwards.
  • The interrupt map routes a task to the accelerator rather than to a C28x interrupt service routine.
  • Behaviour: a control loop whose period is far shorter than the C28x could sustain alone.

The third signal is the most reliable from behaviour alone, and it is visible without any read at all — a device whose fastest control loop runs at a period the main core could not meet is using the accelerator, whatever its flash says.

Reading order that accounts for both

The sequence that produces a complete picture:

  1. Read the flash array. This gives the C28x image and, as data, the accelerator’s program if it is stored as a blob.
  2. Read the accelerator’s RAM if the memory protection configuration permits it. This gives the code as it exists at runtime, which is authoritative.
  3. Compare the two. If they match, the blob is the code and the copy is straightforward. If they differ, the runtime version is generated and the generation logic is the thing to understand.
  4. Capture the accelerator’s initial data as well — its coefficient tables are usually in its own RAM and are as important as its instructions.

Step two is the one people skip. It requires the memory protection state to permit a read, and on a locked part it will not. But on a part where the flash is open and the RAM is not, the flash read alone is a trap: it produces a plausible, complete-looking image that reproduces nothing.

Configuration that is separate from code

Beyond the two programs, three items decide whether the copy behaves identically:

  • The accelerator’s start-up sequence. The order of “load, configure, release from reset” is not optional, and altering it produces a device that starts the loop before its coefficients are in place.
  • The interrupt mapping. Moving a task between cores changes the timing and the shared-data protocol.
  • The shared RAM convention. The two cores communicate through a defined region; a copy that puts the region elsewhere works until the first handshake.

None of these live in the program image in a form that a disassembly hands you. They live in the initialisation code, which is why initialisation deserves to be read first when the goal is a working replica rather than a faithful file.

Limits

If the accelerator’s memory is read-protected and the flash is not, the missing piece is the running code and there is no register sequence that produces it. What remains is the flash blob — which may be the code, or may be the recipe for the code.

Determining which of those two you have is a short experiment: load the blob into a known-good part, run it, and compare the output against the original device. If the outputs match, the blob was the code. If the copy runs and produces a constant, the blob was a recipe and the calibration steps that complete it were never in the array.

Related reading

FAQ

Does the accelerator execute from flash? No. Its program is copied into its own RAM and runs from there.

Can a flash read capture accelerator code? Only if that code is stored in flash as data and copied at boot. Generated or downloaded code is not in the array.

Is the accelerator’s memory covered by flash protection? It is RAM, governed by the same security module but configured separately. The two states can differ.

How can I tell the accelerator is in use without reading memory? From timing. A control loop faster than the main core could service indicates offloaded code.

What breaks first in a copy made from flash alone? The control loop: it starts and produces output that does not match the original.

Conclusion

On the F28068F, “the firmware” is distributed across two processors with two memories and two loading mechanisms. A flash read captures one of them and the recipe for the other. Recognising that split before starting the copy is the difference between a replica that controls a motor and one that reports zero.