PostHeaderIcon MSP430G2131: Three Layers of Software in One Array

A customer asks for the software from a device and expects one program. What the array usually contains is three, written by different people at different times for different purposes, occupying contiguous addresses with no boundary marker between them.

Recognising the layering is not an academic exercise. It determines what has to be recovered, what can be ignored, and what will break if it is omitted.

The three layers

The vendor layer is the loader that the silicon ships with: a small program in a reserved region that accepts code over a serial interface. It is not part of the product and it is identical across every device of the same type.

The product layer is whatever boot mechanism the design added. Many products on this family include a bootloader of their own, either because the vendor loader’s transport was inconvenient or because field updates needed authentication the vendor loader does not provide.

The application layer is the product itself: the code that does the work.

Layer Origin Recoverable Needed for a copy
Vendor loader Silicon vendor, in a reserved region Present on every device No, except its configuration state
Product bootloader The product’s designers Part of the image Yes
Application The product’s designers Part of the image Yes

The third column and the fourth column are different questions, and confusing them is common. The vendor loader is recoverable but does not need to be copied, because the destination device already has it.

How the boundaries show up

The vendor loader occupies a reserved region and is protected from erasure by the same mechanism that protects the array — which means that in the image it appears as a block of code at an address the linker did not place anything at.

The product bootloader is harder to spot, because it lives wherever the designer put it. Its signature is a second entry point: a routine that is called early, that does not touch the product’s peripherals, and that communicates on one interface only.

Three observations locate it:

  1. The reset vector points at code that initialises almost nothing before making a decision.
  2. That decision is a comparison against a flag in a non-volatile location, or a value received on an interface within a timeout.
  3. One branch leads to the application’s initialisation, the other to a loop that receives and writes memory.

That shape — decide, then either run or update — is a bootloader, and once seen it is unmistakable.

Why the layers must be kept together

Recovering only the application produces a file that does not run on a blank device, because the application expects to have been entered by the bootloader, with the stack and the clock in a state the bootloader established.

Recovering only the bootloader produces a device that updates correctly and does nothing else.

The pairing matters in a subtler way as well: the two layers share a contract. The bootloader decides where the application starts, what state it leaves the hardware in, and how the application signals that it is valid. That contract is rarely documented, and it is the thing that has to be reconstructed from the code when a customer wants to modify either layer.

The flag that decides everything

Somewhere in the non-volatile memory there is a value that tells the bootloader whether to run the application. It may be a magic number, a checksum, a version, or a simple flag byte.

This value is the most important single object in the recovery, because it explains a class of behaviour that otherwise looks like a fault: a device that sits in its bootloader forever, refusing to run an intact application, because the flag says the application is invalid.

When recovering, read the flag and record its meaning. When duplicating, program it last, after the application is verified — the same ordering discipline that applies to protection, for the same reason.

Interaction with the protection mechanism

A device whose array is protected does not distinguish between its layers. The protection covers the main array, and the product bootloader sits inside it.

Which means the loader cannot be used to bypass the protection on the application, because the loader is itself part of what is protected. That closes an idea that sounds promising and is not: writing a new bootloader to read the old application requires writing to a protected array.

What to deliver

For a product with this structure the deliverable has three parts: the full image with the layers marked, a description of the contract between the bootloader and the application, and the location and meaning of the validity flag.

Without the second, the image is a binary that nobody can safely modify. Without the third, the first attempted modification produces a device that will not start, and the natural conclusion is that the modification broke the program rather than the flag.

Related reading

FAQ

Is the vendor loader always in the image? It is in the device. Whether your read includes it depends on the address range covered.

Does the product bootloader need to be copied? Yes, unless the destination is intended to run the application without update support.

Why does a device sit in its bootloader? Because the validity flag says the application is not valid.

Can a new bootloader read a protected application? No. It would have to be written into the protected array.

Conclusion

One array, three programs, no boundaries drawn. Locate the reserved region, find the decide-then-run shape that identifies the product bootloader, and record the flag that selects between updating and running. The layers are only useful together, and the contract between them is the part that has to be written down.

Comments are closed.