Extract Firmware - Landis+Gyr (ARM)
The Generation 5 Landis+Gyr residential meter (board PCB 24-2411 rev AC, FCC ID R7PEG1R1S6) runs its radio and network stack on a Microchip (Atmel) ATSAM4C32: two ARM Cortex-M4 cores and 2 MB of internal flash in two 1 MB planes. On a field meter the chip's security bit is set, so a debugger cannot read the flash. The firmware was extracted by bypassing that lock with voltage fault injection and then reading the flash over JTAG. The full write-up of the attack is on the ATSAM4C32 page.
Why the debug port is locked
- The SAM4C has a security bit (GPNVM bit 0). When it is set, JTAG/SWD and the fast flash programming interface cannot reach the flash, RAM or registers. Only a full chip erase (the ERASE pin) clears it, and that erases the firmware too.
- The meter firmware sets the security bit itself: within the first 61 s after power-up, if the meter is configured for network operation (config byte
0x2ECbit 0) and the bit is still clear, the application sets GPNVM0 (security) and GPNVM1 (boot from flash) through the ROM's flash programming routine. A meter that has been in service therefore has a locked debug port even if it left the factory unlocked. - A locked chip with no LAN ID refuses to start its radio ("Incomplete configuration - RF disabled. Return to factory").
- The Landis+Gyr boot loader never touches the GPNVM bits; only the application sets them.
- The board has a JTAG header, but on our board it is not connected until several missing 0 Ω resistors are bridged (photo below).
-
Red circled spots are missing 0 Ω resistors that need a solder bridge before the JTAG header works.
-
SAM4C32 glitch window: VDDCORE (yellow) and the chip's own reset pulse (purple).
How the firmware was extracted
In short (details, scope captures and the video are on the ATSAM4C32 page):
- The glitch is injected on the chip's VDDCORE supply, so that rail needs to be reachable and its decoupling capacitors removed.
- Power-cycle the chip (a reset alone is not enough). About 17 ms after power-up the SAM4C briefly drives its own reset pin low, and the VDDCORE activity during that pulse is where a glitch skips the security check. The reset pulse makes a convenient trigger.
- Inject a short VDDCORE glitch (about 2 µs worked) in that window. When it lands, JTAG comes up with the security bit reading as clear.
- Connect over JTAG (OpenOCD with an Atmel-ICE) and read the flash. The unlock lasts only until the next reset, so read everything in the same session.
What we can state about the dump itself:
- The glitch was driven from a ChipWhisperer setup (the trigger was the rising edge of the 3.3 V supply, through a ChipWhisperer breakout board).
- After a successful glitch OpenOCD's
at91sam4 infoidentifies the part as a SAM4CxxC (100-pin) with 2048 KB flash and 256 KB SRAM, andat91sam4 gpnvmreports GPNVM0 = 0, GPNVM1 = 1, GPNVM2 = 1. GPNVM0 reads as 1 again after the next reset. - The chip in that session was running Landis+Gyr code: the "UniqueId" words OpenOCD printed (
0x20000c00 0x01006df3…) are the boot loader's initial stack pointer and reset vector from the dump. - The result is three images of the same meter: plane 0 (
0x01000000, 1 MB), plane 1 (0x01100000, 1 MB) and both planes together (2 MB). Plane 1 is erased. - The image's own CRC (below) checks, so the read is complete.
What the dump contains
The image below is from one meter (firmware S5GS2D-13.54, built 2019/04/18).
| Address | Size | Contents |
|---|---|---|
0x01000000-0x0101FFFF |
128 KB | Landis+Gyr boot loader (vector table at 0x01000000)
|
0x01000200 |
512 B | Inside the boot loader area: the meter's own DataFlash storage key, generated on its first boot (see Landis+Gyr EEPROM Storage Map) |
0x01020000 |
256 B | Application image header, starting with UTILINET
|
0x01020200 |
Application vector table; the application runs to the end of plane 0 (0x010FFFFF)
| |
0x01100000-0x011FFFFF |
1 MB | Flash plane 1: all 0xFF (unused) on our meter
|
0x02000000 |
SAM-BA boot ROM (Microchip). Not dumped. |
- The boot loader checks the application at every start: the
UTILINETmagic plus a CRC-32 over the code range given in the header (start at+0x25, length at+0x29, CRC at+0x11). The same check confirms a good dump. - Because the storage key is in internal flash, an internal-flash dump is what makes the meter's encrypted external DataFlash readable. The page is not lock-protected: the application unlocks every flash lock region at boot, so any code on the chip can read it.
What the dump makes possible
- No signature on the installed application. At every start the boot loader checks the internal application only by the
UTILINETmagic and its CRC-32. Images that arrive over the air are ECDSA P-256 signed and checked, but once programmed into internal flash only the CRC is checked again. - The boot loader's trust anchor is in the DataFlash. The boot loader has no public keys of its own. Before installing a staged image it verifies the signature against two keys stored in the encrypted factory-constants record of the external DataFlash (the application writes its two Landis+Gyr keys there), and it ignores the signature's expiry and signer class. Whoever holds a meter's storage key can therefore replace the keys that meter's boot loader trusts.
- Install clears all flash lock bits, including those over the boot loader, and erases
0x01020000-0x011FFFFFbefore writing.
Loading it into Ghidra
- Import the 1 MB plane-0 image as Raw Binary, language ARM:LE:32:Cortex (little-endian Cortex-M), base address
0x01000000. - The boot loader and the application are separate programs with separate vector tables. We import the image twice: once with the vector table at
0x01000000(boot loader) and once at0x01020200(application). - Add the peripheral registers from the ATSAM4C32C SVD file (Core 0 view) with SVD-Loader-Ghidra. We used the SVD from the Keil
SAM4_DFP1.6.2 pack; Microchip's own pack server no longer carries a SAM4C pack.
External DataFlash
The external AT45DB321E DataFlash (528-byte pages) holds the configuration, keys and staged firmware updates. On Generation 5 it is encrypted at rest with the per-meter key from internal flash. Read the chip as on Dump EEPROM, then decrypt it as described on Landis+Gyr EEPROM Storage Map.