PostHeaderIcon Break MCU ATxmega64A1 Heximal: The Boot Section Has Its Own Lock Bits

Most descriptions of device protection treat the flash as a single object with a single lock. On an AVR XMEGA that model is wrong in a way that changes the engagement. The array is divided into an application section and a boot section, each with its own pair of lock bits, and the interesting cases are the ones where the two halves disagree.

The ATxmega64A1 is the mid-sized member of the family: 65536 bytes of flash, 4 KB of SRAM, 2 KB of EEPROM in its own address space, 78 I/O pins in a hundred-pin body, and the same generous peripheral set as its larger sibling — eight USARTs, twelve-bit converters, an AES engine, a DMA controller and the event system. It is the part chosen by designs that need the peripherals but not the memory, which in practice means instrumentation and industrial communication gateways.

The part in numbers

item ATxmega64A1
program memory 65536 bytes, 32768 words
boot section a reserved region at the top, size set by fuse
SRAM 4 KB
EEPROM 2 KB, separate address space
I/O 78 pins, 100-pin body
programming PDI, three pins
lock bits one for the whole device, plus boot lock pairs
erase unit chip erase, or application section erase

The boot section size is a fuse setting rather than a fixed number, which matters because a customer’s memory map depends on how the production line set that fuse. A bootloader written for a 4 KB section will not start correctly on a part whose fuse reserves 8 KB.

Two lock pairs and one device lock

bit pair protects what it stops what it does not stop
boot lock, application side the application section writes and reads from the boot code reads from the PDI
boot lock, boot side the boot section writes from the application code reads from the application code
device lock everything, from outside the PDI interface entirely code already running on the part

The third row is the one that surprises people, and it is the single most useful fact on this page. The device lock is an interface lock. It disables the external programming and debug interface. It does not disable the core, it does not disable LPM, and it does not disable a routine that has already been written into the part.

So a locked device is locked against a programmer, not against itself.

What that means in practice

If the design shipped with a bootloader that accepts commands over a serial port, the bootloader is code running on the part with the ability to read flash. Whether it can be made to hand that flash out depends on the protocol and on whether the boot lock pair permits the boot section to read the application section.

Many factory bootloaders have a read command for firmware update verification. Some have a full memory-read command used in production test and never removed. Finding one is a matter of reading the bootloader’s own code, which is itself recoverable if the boot section is not locked against the programmer — and on a device that is locked, the boot section may still be readable through the same route that made the bootloader interesting in the first place.

The honest summary: when a bootloader is present, the recovery may not need a probe at all. When it is absent, or when both boot lock pairs are set to forbid the reads, the route closes and the die becomes the only path.

Why the boundary is worth checking first

Before any of this, three reads cost almost nothing and decide the shape of the job.

Read the device signature. It names the part exactly, which distinguishes the A1 from its siblings that share the package, and therefore tells you the memory map you are working against.

Read the fuse bytes. The boot section size, the reset vector source, the brown-out level and the watchdog configuration all live there, and they describe how the design was built rather than what it computes. A design that resets into a bootloader and a design that resets into the application are different products with different failure modes.

Read the boot section’s first words. If the boot reset vector decodes to a jump into plausible code, there is a bootloader and the route described above is worth exploring. If it reads as erased, the design never used one and the fuse that reserves the space is simply wasted.

What a 64 KB image looks like when it comes back

Sixty-four kilobytes is 32768 instruction words, comfortably inside a sixteen-bit word address, so the pointer arithmetic problems that plague the 128 KB sibling do not arise here. What remains is the byte-versus-word distinction: the hex file is byte addressed, the jump mechanisms are word addressed, and a computed jump built from a table entry needs a shift before it will land correctly.

The boot boundary is the second hazard. A disassembly that sweeps linearly from zero through the whole file will run straight through the application section into the boot section and continue as if it were one program. It is not. The boot section is entered by a reset vector at a fuse-determined offset, and analysing it requires starting there rather than arriving by fall-through.

The third hazard is the EEPROM. Two kilobytes in a separate address space, read by a different command, and often holding exactly the values a customer asked for when they said “the data”. Delivering the flash alone and calling the job complete is a common and avoidable mistake.

For the larger sibling where the address arithmetic rather than the boot section is the difficulty, ATxmega128A1 heximal reversal covers that ground. For the eight-bit megaAVR part with an external bus, ATmega162A heximal recovery is the nearest comparison. And for a PIC part where the protection is a single fuse and no software can reach around it, PIC16C56 code copying shows the other extreme.

FAQ

Does a chip erase remove the bootloader? Yes, along with the application, the EEPROM and the lock bits. On a part where the bootloader was the route to the image, erasing is the end of the recovery rather than the beginning.

Can the boot section be read by the application? Only if the boot lock pair permits it. That pair exists precisely to let a design hide a bootloader from the application code it is loading.

Is PDI the only external interface? On this family, yes, and it is the one the device lock disables. There is no second path through a debug protocol.

The short version

Two sections, two lock pairs, one device lock, and a lock that blocks the programmer rather than the code. Read the signature, the fuses and the boot vector before deciding anything, treat the boot section as a separate program with its own entry point, and do not forget the EEPROM in its own address space. When a bootloader is present the job may be a conversation over a serial port; when it is not, it is a die and a probe.

Comments are closed.