MSP430G2212: Reading an Image From the Top Down
The address order of a memory read is normally inherited from the tool rather than chosen. Tools read from the base of the array upward, because that is how the hex file is laid out and how the programmer writes it. For extraction the direction is not a formatting detail; it decides what you have when the session ends early.
Sessions end early often. A supply glitch, a watchdog, a thermal shutdown, a protocol timeout, a cable moved — any of these stops the transfer somewhere in the middle. What you hold afterwards depends entirely on which end you started from.
What lives at the top
On this device the highest addresses hold the part of the program that describes the rest of it.
The interrupt vector table sits at the top of the address space. It contains the reset vector, which is the entry point, and one entry per interrupt source, which is a list of the peripherals the program uses. Reading it first tells you where execution starts and which modules matter.
The protection state is established by a location the module compares against, and that location is in the same high region. Knowing it early means knowing whether the transfer is going to work at all.
Below the vectors is the code that the vectors point into: the startup routine, the interrupt handlers, the main loop. This is the part of the program that a person reads first anyway, so reading it first means the analysis can begin before the extraction has finished.
| Region | Position | Why read it first |
|---|---|---|
| Vector table | Top of the address space | Gives the entry point and the peripheral list |
| Protection state | High addresses | Decides whether the session can succeed |
| Startup code | Just below the vectors | The first thing an analyst needs |
| Application and tables | Lower addresses | The bulk, and the least structurally informative |
The argument for top-down
Three benefits follow, and they compound.
A partial image is still useful. A read that stops after the top region yields a complete vector table and the startup code, which is enough to identify the compiler, the peripheral set, the main loop structure and the entry point. A read that stops after the bottom region yields a fragment of an unknown function with no entry point.
The failure is diagnosed sooner. If the protection is engaged, a top-down read discovers it in the first block rather than after transferring everything readable below it. On a device with partial protection — rare but not unknown — that difference is the whole session.
The transfer can be prioritised. When the link is slow and unreliable, the valuable part can be fetched first, verified, and stored, and the rest fetched afterwards with a different strategy if necessary.
How to implement it
The routine is the same one used for any block transfer with three changes.
- Start the address counter at the top of the implemented array rather than at its base.
- Align the first block so that it ends exactly at the top, rather than starting at a round number below it.
- Descend in blocks that stop at bank boundaries rather than crossing them, so that a failure is confined to one bank.
Step two matters more than it appears. A block that is aligned to its end rather than its start keeps the vector table inside one transfer unit, which means the transfer succeeds or fails as a whole rather than arriving with its last few entries missing.
Reading the vectors as a map
The vector table is worth more than its content. Its shape is a description of the program.
A vector that points into the middle of the array with the low bit set is an interrupt handler. A vector that points to the same address as another is a shared handler, which means the design groups several sources into one routine. A vector that points at erased flash is an unused source. A vector that points outside the array is either a bug or a signal that the image is not what it appears to be.
Recording that classification takes minutes and produces the peripheral list without disassembling a single instruction. On a device whose program cannot be read but whose behaviour can be observed, the same classification can be reconstructed from which interrupts the hardware actually takes — which is the only route available on a fully locked part.
What the down direction costs
There is one real disadvantage: the linker’s map is organised from the bottom, so section boundaries, tables and constant pools appear in the image in an order that no longer matches the order in which you read them.
The mitigation is to keep an address-indexed store rather than an append-only file. Write each block to its offset in a sparse image, and the order of arrival becomes irrelevant. A sparse image that is half full is a legitimate intermediate state and can be inspected, which an append-only dump cannot.
Verifying a partial read
A top-down session that was interrupted leaves a specific shape: vectors present, code present to some depth, and erased or missing data below. That shape is easy to verify.
- Confirm the reset vector points inside the region that was actually read.
- Confirm the first instructions at that vector disassemble into plausible startup code.
- Confirm the vector entries point into the read region, not into the missing part.
- Confirm the read region ends on a block boundary, which shows where the session stopped.
Step three is the useful one. If the vectors point below the deepest address read, the remaining region is not optional: it contains the handlers, and the image is incomplete in a way that matters.
When the whole array is unreadable
The top-down discipline has a second use in the case where nothing can be read at all. The same map can be built from behaviour: which pins respond, which interrupts occur, which peripherals are initialised in what order. On a part this small that reconstruction is realistic, and it produces the same document — entry point, peripheral list, module structure — from observation rather than from memory.
That is the fallback, and it is worth keeping in mind while reading the vectors of an open device: the classification you are doing is the same one you would have to do from the outside if the array were closed.
Related reading
- MSP430G2101 and reading a whole image by hand — what to do with the vectors once you have them.
- MSP430G2211 and the electrical failures that end sessions early — why the direction matters in practice.
- MSP430G2513 and the different meanings of unlocking — what to do when the top region says the array is closed.
FAQ
Does the tool support reading downward? Usually not directly, but block reads at chosen addresses can be issued in any order.
Why align a block to its end? So that the vector table is not split across two transfers.
Is a partial image worth keeping? A top-down partial image usually is. A bottom-up one usually is not.
Can vectors point outside the array? Not in a correct program. If they do, the image or the read is wrong.
Conclusion
Read from the top. The vectors, the protection state and the startup code are what make an image interpretable, and having them first means that a session which ends early still produces something an analyst can use. The direction costs nothing and changes what a failure leaves behind.