Posts Tagged ‘read avr mcu binary file’
Read Atmel AVR Firmware: Record the Signature, Not the Filename
Files arrive named after what somebody believed the device was. Markings on the package say what the assembler was told to place. Neither is evidence. The evidence is three bytes that the device itself reports when asked, and they are readable in almost every state, including the state where the program memory is locked.
This matters because the AVR family is large, the members differ in ways that affect how an image must be interpreted, and the labels attached to files are frequently wrong by the time a project reaches the bench.
What the signature bytes contain
Three bytes identify the device: a manufacturer byte and two device bytes. The combination is unique within the family, and the vendor publishes the values.
| Byte | Meaning | Notes |
|---|---|---|
| Byte 0 | Manufacturer or family code | Often the same across a whole family |
| Byte 1 | Device code, high | Part of the specific device number |
| Byte 2 | Device code, low | Completes the identification |
The values are stable across revisions of the same device, which is what makes them useful: a signature match confirms the family member, not the batch.
Why the signature survives locking
The lock bits protect program memory and, on some devices, EEPROM. They do not hide the signature, because the signature is part of the device’s identity and the programming interface needs it to select the correct algorithm.
| State | Signature readable | Program readable |
|---|---|---|
| Unlocked | Yes | Yes |
| Read protected | Yes | No |
| Read and write protected | Yes | No |
| Blank | Yes | Yes, and empty |
The second and third rows are the practically important ones. A locked device still answers the identity question, which means an assessment can begin with confirmation rather than assumption.
Why identity matters before anything else
The same instruction stream can be interpreted differently depending on which member of the family produced it, and the differences are not cosmetic.
| Difference | Consequence of a wrong assumption |
|---|---|
| Memory size | Image truncated, or padded wrongly |
| Boot section size | Bootloader boundary in the wrong place |
| Vector count | Interrupt table misread |
| Peripheral set | Addresses in code point at nothing |
| Instruction variant | Disassembly contains invalid opcodes |
The fifth row is the sharpest: a device from a different sub-family may use an extension to the instruction set, and a disassembler configured for the base set will produce nonsense in exactly the routines that use it.
Markings versus signatures
The package marking and the signature should agree. When they do not, the part is remarked or the marking has been misread.
| Situation | Likely cause |
|---|---|
| Signature matches a smaller device than the marking | Remarked part |
| Signature matches a different family entirely | Wrong part fitted, or a clone |
| Signature reads as all zeros or all ones | Interface problem, not identity |
| Signature correct, program blank | Erased, or protection with an empty array |
The first row is common enough in repair work to be worth checking every time. A board built with a remarked part will behave in ways the schematic does not explain, and the explanation is in the signature.
The calibration and user rows
Some devices provide additional rows beyond the signature, and they carry information that affects behaviour.
| Row | Content | Readable when locked |
|---|---|---|
| Signature | Identity | Yes |
| Calibration | Factory oscillator trim | Sometimes |
| User signature | A designer-supplied identifier | No, if in locked flash |
| Lock and fuse | Configuration | Yes, on most devices |
The second row is the one that matters for cloning. A device whose calibration value cannot be read will need recalibration, and recalibration requires measuring the oscillator against a reference.
Recording identity in the deliverable
The identity should travel with the image, because an image separated from its identity is a file of bytes with a confident name.
| Field | Value |
|---|---|
| Signature bytes | As read |
| Inferred part | Across the family table |
| Marking observed | As printed on the package |
| Agreement | Yes, or the discrepancy stated |
| Read method | Interface and clock |
| Date and fixture | For reproducibility |
The fourth row is the one that makes a report useful when something goes wrong later. A report that records a discrepancy is a report that anticipated the problem.
The naming history
There is a further source of confusion that has nothing to do with silicon. The AVR family was designed by Atmel, which was acquired by Microchip, and the documentation, the part numbering and the tooling have been reorganised since.
| Era | Naming convention | Note |
|---|---|---|
| Atmel era | ATmega, ATtiny, AT90 | The classic names |
| Transition | Both names in circulation | Same silicon, two document sets |
| Microchip era | Same device names, new document numbers | Packaging and ordering codes changed |
The consequence for this work is that the same device can appear under two documentation sets with slightly different electrical specifications and identical silicon. A signature match settles the identity; the document number does not.
Where the adjacent steps are
The two programming interfaces and their different behaviours on a locked device are in reading AVR chip firmware. The clock and fixture limits that determine whether a read is reliable are in reading AVR firmware at speed. The full set of areas that must be captured to reproduce a device is in extracting an AVR microcontroller.
Services at this boundary
Work covers signature readout on locked and unlocked devices, part identification across the family, marking verification, calibration row recovery where available, and identity recording in the deliverable. It does not cover reading a program array that is locked, and it does not cover establishing a part number from a package marking alone.
The habit worth adopting is to read the signature before reading anything else, and to put it in the report whether or not it agrees with the filename.