PostHeaderIcon Recover Microcontroller MSP430F4361 Flash: The Two Segments Everyone Forgets

A flash recovery on a member of this family usually starts with a size estimate. Main memory is tens of kilobytes, the job is to read that, and the work looks proportional to the number. In practice the difficult part of the job occupies 256 bytes at a lower address, and it is the part most often left behind.

Those 256 bytes are the two information segments. They hold the calibration constants for the internal oscillator and a structured device descriptor written by the factory. Neither is in the main array. Neither can be reconstructed from the main array. And on a replacement device, one of them is required before the product will run at the right speed.

The memory map as the design actually is

It helps to draw the map in the order the silicon presents it, because the ordering is not intuitive to anyone who has not worked on this core.

Region Typical size Written by Erase granularity
information segment A 128 bytes factory test segment
information segment B 128 bytes factory test, sometimes the application segment
main memory, lower half the bulk of the array the firmware engineer segment-sized blocks
interrupt vector table the top of the address space the firmware engineer, relocated part of a segment
bootloader area, where present a reserved block factory protected separately

Two features of this map cause trouble. The first is that the information segments sit below main memory in address order rather than above it, so a tool that reads from a start address upward in one continuous pass may include them, exclude them, or include them and then discard them when the map is trimmed to the expected main-memory size.

The second is that the interrupt vector table lives at the top of the address space rather than at the bottom. A recovery that treats the array as code starting at a low address and running upward will miss the vectors entirely, and an image without vectors does not run.

What lives in segment A

Segment A carries the calibration data for the digitally controlled oscillator. The oscillator is trimmed at the factory for a small number of nominal frequencies, and for each frequency the calibration comes as a pair of values: one that sets the oscillator’s tuning word and one that sets its buffer and mode configuration.

The values belong to that specific die. They are not interchangeable between devices, and they are not derivable from the part number. A firmware that reads them at startup gets the correct clock for free. A firmware that reads them from a device where they are erased gets whatever the erase left, which is usually a pattern that produces a frequency far from nominal.

This is the single most consequential fact about recovering this family. The main array tells you the algorithm. Segment A tells the device how fast to think while running it. Any serial, timer, or sampling function calibrated against the clock will be wrong in proportion.

What lives in segment B

Segment B is nominally for the application, and on many factory-produced products it is left erased. Where it is used, it holds data that the bootloader or the production line wrote: a serial number, a hardware revision, a manufacturing date, a set of trim values for the analogue front end.

It is also where a second copy of some factory data sometimes sits, which turns out to be useful. Where both segments carry overlapping values, disagreement between them is a reliable indicator that one segment was erased at some point and rewritten from an incomplete source.

The descriptor table and why it matters to a recovery

Alongside the calibration values, the information area carries a set of tagged records in a length-prefixed format. Each record has a tag, a length and a payload, and the tags cover things like the die temperature sensor’s calibration, the reference voltage’s trim, and the list of peripherals the die actually contains.

For a recovery job these records are worth extracting even when the customer only asked for the program, because they answer questions the program cannot. A product behaving differently from an identical-looking unit is sometimes running on a die with a different peripheral set, and the descriptor is what proves it.

The parsing is mechanical: read the tag, read the length, step to the next record, stop at the terminator tag. Delivering the decoded form alongside the raw bytes costs little and is far more useful than a hex dump of the segment.

Reading without losing the segments

The read procedure has to be explicit about addresses rather than relying on a tool’s default range.

  1. Read the information area first, by explicit address, before touching main memory. It is small, it is usually unprotected, and it is the part that cannot be reconstructed.
  2. Verify the calibration values decode into a plausible range. A tuning word of all ones means the segment is erased, not that the oscillator is configured for a very low frequency.
  3. Read main memory upward from its base address, in segment-sized blocks, so that a failure part-way leaves a usable partial result.
  4. Read the vector table explicitly at its top-of-space address and confirm the reset vector points inside main memory.
  5. Compare the total against the expected size for the part, and report any gap rather than filling it.

Step two deserves emphasis. A calibration value that has been erased often reads as a uniform pattern, and a tool that reports it faithfully will hand over a file containing a value that looks like data. Checking that the value falls in the documented range is what turns a data transfer into a verification.

Protection and the pattern where it applies

Where the device is protected, the protection mechanism on this family operates through a password held in the interrupt vector table’s own area, and the access rules differ from the flash parts of other vendors: the protection is a lock on the debug interface rather than on the array in isolation.

That has a practical consequence for the recovery strategy. Where access is available, everything including the information area is available. Where it is not, nothing is, and the job moves to the behavioural end of the discipline. There is no useful middle state where main memory is readable and the information segments are not, which at least makes the decision simple.

Comparing two recovered devices

When two units of the same product are both available, comparing their information segments is one of the fastest ways to find where the per-unit data lives. The main arrays are usually identical. The information segments differ in a small number of bytes, and those bytes are the calibration, the identity, or the production record — the three things that make two products built to the same design behave differently.

That comparison also reveals whether the production line wrote segment B at all, which determines whether a replacement device needs that step performed.

The deliverable

For this family a recovery is complete when it contains the following.

  • the main array with its address range stated
  • information segments A and B as separate, explicitly labelled blocks
  • the calibration pairs decoded and checked against their documented ranges
  • the descriptor records decoded into named fields
  • the vector table, with the reset vector’s target highlighted
  • an explicit statement of any region that was erased, missing or inferred

The second item is what distinguishes a recovery from a dump. It is also the item a customer will ask about three months later, when the replacement unit runs and the timing is slightly off.

For the same class of device treated from the angle of what remains observable after the debug interface is closed, MSP430G2252 flash recovery covers the behavioural route. Devices with no information segments at all are handled in PIC16F506 binary recovery, where the whole array is uniform and simpler for it. And where the factory calibration lives in the last program word rather than in a separate segment, PIC16F627A binary copying describes the same trap in a different layout.

Comments are closed.