Skip to content

ramips: add support for Zyxel LTE3301-M209/Q222 - #25670

Open
ddimension wants to merge 4 commits into
openwrt:mainfrom
ddimension:lte3301-pr
Open

ddimension wants to merge 4 commits into
openwrt:mainfrom
ddimension:lte3301-pr

Conversation

@ddimension

@ddimension ddimension commented Oct 6, 2026 •

Copy link
Copy Markdown

Adds the Zyxel LTE3301-M209 and its Q222 sibling: MT7620N, 64 MB RAM, 16 MB
SPI-NOR, internal 5-port FE switch (4x LAN), rt2800 WiFi and a QMI LTE modem on
the internal USB bus. There is no ethernet WAN port; the WAN side is the modem.
Both variants are the same board and share a device tree, differing only in the
offset of the base MAC in the vendor config partition.

The stock firmware runs on the AMIT "jboot" loader, which cannot be kept: its
layout hard-codes the kernel area to 1507328 bytes (0x170000) with the rootfs at
the fixed offset 0x180000, and jboot's own update records carry that erase
length, so a current kernel does not fit - and jboot cannot boot a FIT image
either. These images therefore replace it with mainline U-Boot from
uboot-mediatek, which then boots a FIT out of the firmware partition.

Commits:

  • uboot-mediatek: add Zyxel LTE3301-M209/Q222 — defconfig, device tree and
    default environment. The MAC is read from the config partition with
    env readmem like on the other boards in this package, and the environment is
    the usual OpenWrt boot menu with TFTP recovery. In addition, holding reset or
    WPS at boot starts the TFTP recovery boot, because the device has no serial
    header a user could reach. Writing a bootloader is refused unless the image in
    RAM starts with the SPL signature.
  • jboot-tools: support Zyxel LTE3301 and fail safely on bad input — the
    LTE3301 config records are odd length, so the multi-byte fields have to be
    read byte-wise; the previous struct-member reads assumed natural alignment.
    Also fixes a SIGSEGV on an unrelated mtd (find_header() error return was
    treated as a record count) and bounds the record walk.
  • build: add pad-to-ff image command — padding with 0xff for flash areas that
    have to look erased, i.e. the region the jffs2 overlay initialises itself in.
  • ramips: add support for Zyxel LTE3301-M209/Q222 — device tree, image recipe,
    board.d, calibration data extraction, uboot-envtools.

Depends on openwrt/firmware-utils#81, which adds the jbootimage tool the
u-boot-install.bin recipe uses. This PR stays a draft until that is merged;
the tools: firmware-utils: update to Git HEAD commit is added afterwards.

Installing over the vendor firmware

The vendor recovery only accepts its own record format, so u-boot-install.bin
is flashed through it, not factory.bin. Put the device into the jboot recovery
(hold reset at power-on, or let it find an invalid firmware) so it answers at
192.168.123.254, give the host an address in that /24, and upload with a single
multipart POST:

curl -m 900 -F "[email protected];filename=firmware.bin" \
     http://192.168.123.254/upg

The file field must be named FN and the file name must be forced to a short
name ending in .bin; the long default image name is what makes the browser
upload fail with ERROR / CAS 8002. Success is an HTML page containing
CAS 8000. jboot writes the flash during the POST, so the image takes several
minutes. Power-cycle afterwards.

Tested on hardware (LTE3301-M209)

  • the new U-Boot was RAM-tested (chainloaded) before it was written to offset 0,
    then flashed and verified byte-for-byte;
  • environment in MTD: the first boot falls back to the default environment,
    _firstboot reads the MAC out of the config partition (ethaddr matches the
    label) and saves it, the next boot comes up with
    Loading Environment from MTD... OK;
  • boot menu, button reset / button wps, partitions in mtd list;
  • firmware written through the boot menu TFTP path (boot_tftp_sysupgrade →
    nor_write_production) and through sysupgrade, FIT boot from flash;
  • WiFi calibration data extracted from the config partition
    (rt2800_read_eeprom_file / RF chipset 7620 detected), wlan0 = eth0 + 1;
  • LTE modem enumerates, LEDs, switch, fw_printenv on the device;
  • full vendor-recovery installation: vendor bootloader restored from a backup,
    u-boot-install.bin uploaded through the recovery (CAS 8000), and the
    device comes up with U-Boot, OpenWrt and a jffs2 overlay that initialises
    itself on the first boot.

@openwrt openwrt Bot added build/scripts/tools pull request/issues for build, scripts and tools related changes core packages pull request/issue for core (in-tree) packages kernel pull request/issue with Linux kernel related changes target/mediatek pull request/issue for mediatek target target/ramips pull request/issue for ramips target labels Oct 6, 2026
@ddimension
ddimension force-pushed the lte3301-pr branch 2 times, most recently from ce8c7de to 474f7de Compare October 6, 2026 17:48
@namiltd

namiltd commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Why don't you use DSA instead of swconfig? Look at: #24493 and #25881, #26529.

@ddimension

Copy link
Copy Markdown
Author

Why don't you use DSA instead of swconfig? Look at: #24493 and #25881, #26529.

Good point, thanks!

@ddimension

Copy link
Copy Markdown
Author

Converted to DSA (kmod-dsa-mt7620, no swconfig): ports 0-3 are lan4..lan1, port 6 is the CPU port, and board.d now sets lan1 lan2 lan3 lan4 as LAN. Tested on two M209 by sysupgrade from the swconfig build: DSA tree up, CPU port at 1 Gbps/full, bridge and LTE WAN working.

Comment thread target/linux/ramips/mt7620/config-6.18 Outdated
CONFIG_USE_OF=y
CONFIG_WATCHDOG_CORE=y
CONFIG_ZBOOT_LOAD_ADDRESS=0x0
CONFIG_MTD_SPLIT_FIT_FW=y

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary, or does it perhaps turn on automatically by default? If so, please explain why.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed: generic/config-6.18 disables it and nothing on mt7620 selects it. This is the first mt7620 board whose firmware partition is denx,fit, and without mtdsplit_fit the rootfs is not found (mt7621 enables it target-wide for the same reason). Moved it to its sorted place and noted it in the commit message.

@ddimension

Copy link
Copy Markdown
Author

On the draft status: the device support itself is done and tested on two M209, and DSA is in since the last push. It is a draft only because the u-boot-install.bin recipe needs jbootimage from openwrt/firmware-utils#81, which is not merged yet. The tools: firmware-utils: update to Git HEAD commit follows once it is.

Reviews of the rest are welcome in the meantime. If you would rather review it as a regular PR, I can take it out of draft now and keep the dependency noted here.

Comment on lines +78 to +82
zyxel,lte3301-m209|\
zyxel,lte3301-q222)
# No ethernet WAN - the WAN is the LTE modem.
ucidef_set_interface_lan "lan1 lan2 lan3 lan4"
;;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please sort alphabetically, this case belongs after the case at line 293-296.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, the case now follows zyxel,keenetic-viva.

@ddimension
ddimension force-pushed the lte3301-pr branch 2 times, most recently from 5adb43d to daaf042 Compare November 18, 2026 19:40

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit checks

  • daaf042 "ramips: add support for Zyxel LTE3301-M209/Q222" — the hardware specification is incomplete: add WiFi band/chains, the buttons, UART (say if there is no usable header) and power input.
  • daaf042 "ramips: add support for Zyxel LTE3301-M209/Q222" — the message says "Verified on both the M209 and the Q222", but the PR body and the DSA comment report testing only on M209 units. Make them agree.

Generated by Claude Code

Comment on lines 255 to +256
data_table[data_header_counter] = tmp_data_header;
tmp_buf +=
DATA_HEADER_SIZE + data_table[data_header_counter]->length;
tmp_buf += DATA_HEADER_SIZE + get_le16(tmp_buf + 4);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A record whose length runs past the end of the buffer is still stored, and write_eeprom() / print_data_header() then read length bytes beyond the allocation. Stop the walk (or skip the record) when (size_t)(tmp_buf - buf) + DATA_HEADER_SIZE + get_le16(tmp_buf + 4) > buf_size.


Generated by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: a record whose data would run past the buffer now ends the walk before it is stored. With a crafted config (the last record's length set to 0xfff0), the old code overflows the heap in print_data_header() under ASan; the new code does not, and the MAC, -p output and extracted EEPROM from real M209 config partitions are unchanged.

Comment on lines +228 to +231
if (tmp_checksum !=
(uint16_t) ~jboot_checksum(0, (uint16_t *) (tmp_buf + STAG_SIZE),
tmp_csxf_header->raw_length +
CSXF_SIZE);

if (tmp_checksum != tmp_csxf_header->checksum) {
ERR("CSXF checksum incorrect! Stored: 0x%X Calculated: 0x%X",
tmp_checksum, tmp_csxf_header->checksum);
get_le32((uint8_t *)tmp_csxf_header + 12) +
CSXF_SIZE)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raw_length comes straight from the input and is handed to jboot_checksum() unchecked, so a corrupt CSXF header makes the checksum read past buf. Check CSXF_SIZE + raw_length against the bytes left after the STAG header before computing it.


Generated by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: the CSXF length is checked against the bytes left after the STAG and CSXF headers before the checksum runs. A header with a length of 0x10000 overflows the heap in jboot_checksum() under ASan with the old code; it is refused now.

usbpower {
gpio-export,name = "usbpower";
gpio-export,output = <1>;
gpios = <&gpio0 0 0>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the flag macro instead of a bare 0.

Suggested change
gpios = <&gpio0 0 0>;
gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;

Generated by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +68 to +72
/*
* No gpio-keys here: pin 2 (WPS) has to stay unclaimed, the modem
* stops enumerating as soon as anything else on the port is driven.
* The modem only needs the usbpower switch below.
*/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only explains WPS (pin 2), but the [U-Boot DT in this PR](https://github.com/openwrt/openwrt/blob/daaf0429b81839bf4e72e395e238c33a5d99f647/package/boot/uboot-mediatek/patches/505-add-zyxel_lte3301.patch#L51-L55) puts reset on gpio0 1; without a KEY_RESTART key OpenWrt has no button failsafe or factory reset. Can reset be added as gpio-keys (with the i2c group muxed to gpio, as U-Boot does), or does it hit the same modem problem?


Generated by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not added on purpose, for now. Pin 2 (WPS) is known to keep the modem from enumerating once it is claimed. Reset on pin 1 needs the i2c group muxed to gpio, as U-Boot does, and I have not yet tested in Linux whether that leaves the modem alone. I'd rather keep that out of this PR than ship a button that may cost the modem; if a test on the M209 shows it is safe, it can follow as a separate change.

partition@40000 {
compatible = "denx,fit";
label = "firmware";
reg = <0x40000 0xFB0000>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: in-tree DTS use lowercase hex (the U-Boot DT in this PR already writes 0xfb0000).

Suggested change
reg = <0x40000 0xFB0000>;
reg = <0x40000 0xfb0000>;

Generated by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +84 to +85

};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: stray blank line before the closing brace; same at lines 148-149 (&spi0).

Suggested change
};
};

Generated by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, both.

+ compatible = "gpio-leds";
+
+ led_power: power {
+ label = "green:power";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

label = "<color>:<function>" is deprecated; use color = <LED_COLOR_ID_GREEN>; + function = LED_FUNCTION_POWER; (and include <dt-bindings/leds/common.h>), which U-Boot's led_get_function_name() turns into the same name. Same for the other five LEDs (lines 73-103); regenerate the patch afterwards so the hunk header matches.


Generated by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done for all six LEDs, with <dt-bindings/leds/common.h> included and the hunk header updated. The DT preprocesses and compiles, and led_get_function_name() in 2026.07 gives the same names as before (green:power, red:mobile, …), so nothing that refers to them changes.

@ddimension
ddimension marked this pull request as ready for review November 22, 2026 02:36
@ddimension

Copy link
Copy Markdown
Author

Marked ready for review: the device support is complete, all review threads are answered, and CI is green. One dependency remains: the u-boot-install.bin recipe needs the jbootimage tool from openwrt/firmware-utils#81, which is not merged yet. #81 should go in first (it adds that one tool and changes nothing else); the rest of this PR does not depend on it.

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 new commits; no new issues found.


Generated by Claude Code

Comment on lines +8 to +9
compatible = "zyxel,lte3301-m209", "ralink,mt7620n-soc";
model = "Zyxel LTE3301-M209";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the label of the device show a mac address? if so, please add a label-mac-device alias pointing to the interface that uses this mac to both mt7620n_zyxel_lte3301-m209.dts and mt7620n_zyxel_lte3301-q222.dts, e.g. aliases { label-mac-device = &ethernet; };.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the label shows the base MAC, which is the one ethaddr reads from the config partition and eth0 uses (macaddr_base 0). I added label-mac-device = &ethernet; in 0394d52. It went into the shared mt7620n_zyxel_lte3301.dtsi, where the other aliases already are: both variants use the same &ethernet node and differ only in the MAC offset, so one line covers M209 and Q222. Both device trees compile, and the alias resolves to /ethernet@10100000 in each.

Add mainline U-Boot for the Zyxel LTE3301-M209 and its Q222 sibling:
MT7620N, 64 MB DDR, 16 MB SPI-NOR, 115200 baud console on uartlite,
internal 5-port FE switch, and a QMI LTE modem on USB.

Both variants are the same board and share one device tree. Apart from
the LTE modem, which the boot loader does not touch, and a few vendor
config entries, they differ in where the vendor config partition keeps
the base MAC (M209 0xe2a8, Q222 0xe07c), so each gets its own defconfig
and default environment; the MAC is read with "env readmem" as on the
other boards in this package.

Flash layout: u-boot 192K at 0x0, u-boot-env 64K at 0x30000, firmware
(FIT) at 0x40000, vendor config at 0xff0000. The environment is the
usual boot menu with TFTP recovery; in addition, holding the reset or
the WPS button at boot runs the TFTP recovery boot, because the device
has no serial header a user could reach. Writing a bootloader is
refused unless the image in RAM starts with the SPL signature - a wrong
file at offset 0 leaves the device dead.

The front LED pads are taken out of EPHY mode through the pinctrl
groups the driver already has ("ephy led", "wled", "wdt rst", "i2c"):
in EPHY mode the switch drives those pads, which blinks the LEDs on LAN
traffic and touches the modem strap lines. Pad 72 is deliberately left
unclaimed, driving it keeps the modem from enumerating.

Assisted-by: Claude:claude-opus-5
Signed-off-by: André Valentin <[email protected]>
The config partition of the Zyxel LTE3301-M209/Q222 uses the same JBOOT
STAG/CSXF record layout as the D-Link devices, but the records are odd
length, so every multi-byte field has to be read byte-wise; the previous
struct-member reads assumed natural alignment. Read all 16/32-bit fields
through get_le16()/get_le32() helpers and widen the title/description to
cover Zyxel.

Also make the parser fail safely instead of crashing on an unrelated mtd
(reproduced as a SIGSEGV on the LTE3301): find_header() now returns a
negative value when no valid header is found (the caller treats every
positive return as a record count and would walk an uninitialised
table), main() reports EXIT_FAILURE in that case, an -o offset past the
input is refused, the header search stops early enough that the CSXF
header behind it stays inside the buffer, the CSXF length that the
checksum covers is checked against the buffer before it is used, the
record walk stops at the table size and at a record whose data would run
past the buffer, a MAC record shorter than six bytes is not printed, and
the pointer arithmetic uses ptrdiff_t instead of casting pointers to
uint32_t.

Assisted-by: Claude:claude-opus-5
Signed-off-by: André Valentin <[email protected]>
Build/pad-to pads with 0x00. For flash areas that have to look erased -
the region a jffs2 overlay initialises itself in on first boot, for
example - the padding has to be 0xff instead, otherwise the first mount
finds a partition full of zeros and the overlay has to be erased by
hand.

Add Build/pad-to-ff, which pads to an absolute size with 0xff and fails
instead of silently truncating when the image is already larger than
the target size.

Assisted-by: Claude:claude-opus-5
Signed-off-by: André Valentin <[email protected]>
LTE router based on the MT7620N: 64 MB RAM, 16 MB SPI-NOR, the internal
FE switch with four LAN jacks (no ethernet WAN), the SoC's 2.4 GHz
802.11n 2x2 WiFi (rt2800), a QMI LTE modem on USB, reset and WPS
buttons and a DC power input. There is no serial header a user can
reach. The M209 and the Q222 are the same board apart from the LTE
modem and a few entries in the vendor config partition, and share one
device tree (mt7620n_zyxel_lte3301.dtsi) plus a thin per-variant file
that only differs in compatible/model and the base-MAC offset in the
vendor config partition.

The device ships with the AMIT "jboot" loader, which cannot stay: its
layout hard-codes the kernel area to 1507328 bytes (0x170000) with the
rootfs at the fixed offset 0x180000, and its update records carry that
erase length, so a current kernel does not fit - and jboot cannot boot a
FIT image either. These images therefore migrate the device to the
mainline U-Boot layout from this tree:

- sysupgrade.bin / factory.bin for a device already running our U-Boot,
- u-boot-install.bin, an image in the jboot record format (built by the
  firmware-utils jbootimage tool) that writes U-Boot, kernel and rootfs
  through the vendor recovery web UI, U-Boot record last so an aborted
  upload leaves the device recoverable. Its rootfs record spans the
  whole firmware partition and pads the overlay area with 0xff, so the
  jffs2 overlay initialises on first boot without a manual mtd erase,
- uboot.bin for the bootloader update from the U-Boot console.

The firmware partition is a "denx,fit" FIT padded to the 64K erase
boundary; the factory image pads the overlay region with 0xff for the
same reason as above. Splitting it needs CONFIG_MTD_SPLIT_FIT_FW, which
the generic config disables and nothing on mt7620 selects - this is the
first mt7620 board with a FIT firmware partition, so the subtarget
enables it, as mt7621 does.

Device integration:

- MAC addresses come from the config partition as a "mac-base" nvmem
  cell: eth0 = base, wlan0 = base + 1.
- The rt2x00 calibration data is extracted from the config partition
  under the inherited "soc_wmac.eeprom" name with a device-specific MAC
  patched in, the same way the other JBOOT devices do it.
- LEDs use the color/function bindings; the LAN LED follows eth0, the
  WAN LED the modem.
- The front-LED pads are taken out of EPHY mode so the switch does not
  drive the modem strap lines; pad 72 is left unclaimed, driving it
  keeps the modem from enumerating.
- The switch uses the MT7620 DSA driver (kmod-dsa-mt7620, no swconfig):
  ports 0-3 are lan4..lan1 (the jacks are wired in reverse), port 4 has
  no jack, port 6 is the CPU port.
- uboot-envtools points at the 64K environment at 0x30000.

Converting a device from the stock jboot firmware:

  The vendor recovery only accepts its own record format, so flash
  u-boot-install.bin through it, not factory.bin. Put the device in
  recovery (hold reset at power-on, or let an invalid firmware trigger
  it) so it answers at 192.168.123.254, give the host an address in
  that /24, and upload with a single multipart POST:

    curl -m 900 -F "[email protected];filename=firmware.bin" \
         http://192.168.123.254/upg

  The file field must be named FN, and the filename must be forced to a
  short name ending in .bin; the long default image name is what makes
  the browser upload fail with "ERROR" / CAS 8002. Success is an HTML
  page containing CAS 8000. jboot writes the flash during the POST, so
  a 16 MB image takes several minutes. Power-cycle to boot the freshly
  written U-Boot. Tested on the M209; the Q222 differs only in the
  modem and its config entries.

Assisted-by: Claude:claude-opus-5
Signed-off-by: André Valentin <[email protected]>
@ddimension

Copy link
Copy Markdown
Author

Rebased onto current main. 980a740 had already bumped uboot-tools to PKG_RELEASE:=4, so the bump in this PR merged away and the uboot-envtools/files/ramips change had none. It is PKG_RELEASE:=5 now. The other three commits are unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build/scripts/tools pull request/issues for build, scripts and tools related changes core packages pull request/issue for core (in-tree) packages kernel pull request/issue with Linux kernel related changes target/mediatek pull request/issue for mediatek target target/ramips pull request/issue for ramips target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants