Jump to content

Extract Firmware - Landis+Gyr (M16C)

From RECESSIM, A Reverse Engineering Community

The Generation 4 Landis+Gyr residential meter (Focus AX board PCB 24-1082 rev AE) runs its radio and network stack on a Renesas M16C/62P processor (M30626FHPGP). This page shows how its internal flash is read out through header J6 with a Raspberry Pi Pico running pico-puller. The read uses the processor's own factory boot program and is read-only: nothing on the chip is erased or written.

File:LandisGyr PCB 24-1082 RevAE J6.jpg
Header J6, the Renesas serial programming header, on PCB 24-1082 rev AE. Photo to be added.

What is in the M16C

Memory Address Size Contents How to read it
Program flash 0xA0000-0xFFFFF 384 KB Landis+Gyr boot loader (0xFC000-0xFFFFF) and the UtiliNet application. The application starts with a UTILINET header at 0xA0000. J6, this page
Data flash (blocks A and B) 0x0F000-0x0FFFF 4 KB Small configuration records J6, same method (not read on our boards yet)
Factory boot ROM top of the address space, only while in boot mode 4 KB used Renesas standard serial I/O boot program, version VER.4.04 on our chips J6, bdump
External DataFlash (AT45DB081D) separate SPI chip 1 MB Configuration, keys, logs and the staged firmware update Dump EEPROM, Landis+Gyr EEPROM Storage Map

RAM (0x00400-0x07FFF) is not part of the image; a reset clears it.

How it works

The M16C/62P has a built-in standard serial I/O mode. When the CNVss and CE pins are high and EPM is low as the processor leaves reset, it starts the factory boot program instead of the meter firmware. The boot program accepts commands over a serial link to read, erase and program the flash. pico-puller talks to it in clock-synchronous mode: the Pico drives the serial clock and reads the flash 256 bytes at a time. It only uses the read commands.

Before the boot program allows a read, the host must send the chip's seven-byte ID code. It is stored in user flash at 0xFFFDF, 0xFFFE3, 0xFFFEB, 0xFFFEF, 0xFFFF3, 0xFFFF7 and 0xFFFFB, the unused top byte of each fixed interrupt vector. Landis+Gyr leaves it at the factory default: all seven bytes are 00 in firmware 251107-05.67, so id 0 0 0 0 0 0 0 passes. The ROM code protect byte (0xFFFFF) is 0xCF, i.e. protection off; it only applies to parallel programming mode anyway.

In the field, none of the Generation 4 meters we have read were locked: every one read out with a programmer and the default ID. Whether any Generation 4 CellNet/IWR modems (also M16C) use a non-default ID has not been checked yet. The Generation 5 SAM4C32, by contrast, is locked (see Extract Firmware - Landis+Gyr (ARM)).

The boot program allows three ID attempts per power-up. After three wrong IDs even the right one fails until the board is power-cycled; pulling RESET with power held does not clear the count. A correct ID survives a RESET with power held: the boot program keeps a copy and comes back already verified. If the reset vector at 0xFFFFC reads FFFFFFFF (a blank chip), the ID check is skipped entirely.

What you need

  • A Raspberry Pi Pico with pico-puller (build and install steps are in its README and manual).
  • A 3.3 V bench supply to power the meter board. On our board the Pico hung whenever the M16C ran from the Pico's own 3V3(OUT) pin.
  • Jumper wires or a 2x5 0.1" connector for J6.
  • The meter board out of the meter and disconnected from mains.

Warning: never connect anything to J6 while the board is powered from the meter's mains supply. The board's logic ground can sit at line potential.

Wiring

J6 is the standard 10-pin Renesas programming header; its numbering matches the "Header pin" column of the pico-puller README. M16C pin numbers are for the 100-pin square package (M30626FHPGP).

J6 pin Signal M16C pin Connect to
1 VCC 14 Bench supply +3.3 V
2 BUSY 32 Pico GP21 (pin 27)
3 SCLK 31 Pico GP18 (pin 24)
4 RXD1 30 Pico GP19 (pin 25)
5 CE 44 +3.3 V
6 EPM 39 GND
7 GND 63 Bench supply GND and Pico GND (pin 28)
8 RESET 10 Pico GP22 (pin 29)
9 CNVss 7 +3.3 V
10 TXD1 29 Pico GP20 (pin 26)
  • CE, CNVss and EPM are the boot-mode straps. With them fitted the board enters boot mode on every reset, so remove them (or drive them from spare Pico GPIOs and release them) before running the meter normally.
  • The M16C's clock comes from the CC1020 radio's 14.7456 MHz oscillator, so the whole board must be powered, not just the processor. Feeding 3.3 V into J6-1 was enough on our board.
  • The same J6 pins 4, 7 and 10 carry the meter's debug console; see Debug console.
File:LandisGyr M16C pico-puller bench.jpg
Pico wired to J6, board powered from a 3.3 V bench supply. Photo to be added.

Reading the flash

Open the Pico's USB serial port (the pico-puller script from the project, or any terminal) and enter the commands below. Status values are what our boards returned.

set_speed 2.5e6
reset 1
reset 0
version                  Version: "VER.4.04"
status                   SRD = 0x80, SRD1 = 0x60
id 0 0 0 0 0 0 0
status                   SRD1 = 0x6c   (bits 2 and 3 set: ID checked and verified)
dump                     0xC0000-0xFFFFF
  • Upstream dump reads 0xC0000-0xFFFFF, which suits a 256 KB part. The M30626FHP has 384 KB, so this misses the first 128 KB (0xA0000-0xBFFFF).
  • bdump reads the factory boot program the same way.
  • The read works with any value of the ROM code protect byte; only the ID code gates it.
  • Never use eblock, ppage, all_erase, lockwrite, enable, disable or ramload on a meter: they erase or program the chip.

Save the output to a file and convert it to binary as the pico-puller README shows:

awk '/^[0-9a-f]{8}:/' dump.hex | xxd -r -g -1 > dump.bin

Afterwards remove the straps (CE, CNVss, EPM) and power-cycle; the meter boots its own firmware as before.

Alternative: UART boot mode

The same boot program also has an asynchronous (UART) mode, so a plain 3.3 V USB-serial adapter can read the chip. Strap SCLK (J6-3) low to select it, keep CNVss and CE high and EPM low, and connect J6-4/J6-10 to the adapter's TX/RX. The host sends sixteen 00 bytes at 9600 baud (the boot program answers B0 once it has measured the baud rate), can switch to 57600 with command B3 (the fastest VER.4.04 offers), and then uses the same commands: FB version, 70 status, F5 DF FF 0F 07 + ID1…ID7 for the ID check, and FF + address bits 8–15 + bits 16–23 to read a 256-byte page. Until the ID is verified only status, ID check, version and baud commands are answered. We wrote a read-only reader for this mode but have not yet run it on a board; the Pico method above is the one we used.

Boot program internals

Notes from our disassembly of the VER.4.04 boot program (read with bdump):

  • At reset it copies its code into RAM and runs from there: a small stub to 0x0F00 and one of two main programs to 0x0600, chosen by a pin sampled at reset (one for UART mode, one apparently for clock-synchronous mode).
  • The ID compare is branch-free: all seven bytes and the address/length check are XORed and ORed into one value, and the only data-dependent branch comes after the verdict. There is no timing difference between a guess with one right byte and one with six, so the byte-by-byte timing attack known from older M16C boot programs does not work on this version.
  • The compare still runs after the three-try lockout (only the verdict bit is gated), and the boot program polls the UART from RAM on the external 14.7456 MHz clock, so its timing is deterministic. Its BUSY output (J6-2) is a natural trigger.
  • For a fault-injection attempt the decision points are single instructions: the final ID verdict, the per-command "ID verified?" gate (a glitch there would let one page read through without touching the try counter), and the blank-chip check on the reset vector. These are untested ideas, not results.

Checking the image

  • Read it twice and compare. Our two boards gave identical reads each time.
  • Use the image's own CRC. The UTILINET header at 0xA0000 stores the start (+0x25), length (+0x29) and CRC (+0x2D) of the code it covers (0xA0100-0xF7FFF in firmware 251107-05.67). The CRC is CRC-16/CCITT reflected (polynomial 0x8408, initial value 0xFFFF, the M16C's hardware CRC). The meter's boot loader runs the same check at every reset. An older dump of ours had a two-byte read error that this check caught.
  • Compare with the staged copy. A meter that has received a firmware update over the air keeps a compressed copy of its application in the external DataFlash (see Landis+Gyr EEPROM Storage Map). On one of our meters that copy decoded to the same code as the internal flash, apart from a few header bytes that change per unit.

Results

Board Firmware Read Notes
Gen 4 meter (2 units) 251107-05.67 November 2026, pico-puller on J6 Two reads per unit identical; header CRC matches. Code identical between units; only per-unit header and configuration bytes differ.
Gen 4 meter (first dump) 251107-05.67 Programmer on J6, serial boot mode, default ID One two-byte read error at 0xD0580, found by the header CRC and the staged DataFlash copy.

For loading the image into Ghidra see Ghidra Configuration - M16C Processor.

References