Repository navigation
ramips: add support for Zyxel LTE3301-M209/Q222 - #25670
ddimension wants to merge 4 commits into
Conversation
ce8c7de to
474f7de
Compare
474f7de to
d5b4b1a
Compare
d5b4b1a to
c584461
Compare
|
Converted to DSA ( |
| CONFIG_USE_OF=y | ||
| CONFIG_WATCHDOG_CORE=y | ||
| CONFIG_ZBOOT_LOAD_ADDRESS=0x0 | ||
| CONFIG_MTD_SPLIT_FIT_FW=y |
There was a problem hiding this comment.
Is this necessary, or does it perhaps turn on automatically by default? If so, please explain why.
There was a problem hiding this comment.
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.
c584461 to
324c980
Compare
|
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 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. |
| zyxel,lte3301-m209|\ | ||
| zyxel,lte3301-q222) | ||
| # No ethernet WAN - the WAN is the LTE modem. | ||
| ucidef_set_interface_lan "lan1 lan2 lan3 lan4" | ||
| ;; |
There was a problem hiding this comment.
please sort alphabetically, this case belongs after the case at line 293-296.
There was a problem hiding this comment.
Done, the case now follows zyxel,keenetic-viva.
5adb43d to
daaf042
Compare
openwrt-ai
left a comment
There was a problem hiding this comment.
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
| 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| 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)) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
Use the flag macro instead of a bare 0.
| gpios = <&gpio0 0 0>; | |
| gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>; |
Generated by Claude Code
| /* | ||
| * 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. | ||
| */ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
nit: in-tree DTS use lowercase hex (the U-Boot DT in this PR already writes 0xfb0000).
| reg = <0x40000 0xFB0000>; | |
| reg = <0x40000 0xfb0000>; |
Generated by Claude Code
|
|
||
| }; |
There was a problem hiding this comment.
nit: stray blank line before the closing brace; same at lines 148-149 (&spi0).
| }; | |
| }; |
Generated by Claude Code
| + compatible = "gpio-leds"; | ||
| + | ||
| + led_power: power { | ||
| + label = "green:power"; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
daaf042 to
4960cd2
Compare
|
Marked ready for review: the device support is complete, all review threads are answered, and CI is green. One dependency remains: the |
| compatible = "zyxel,lte3301-m209", "ralink,mt7620n-soc"; | ||
| model = "Zyxel LTE3301-M209"; |
There was a problem hiding this comment.
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 = ðernet; };.
There was a problem hiding this comment.
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 = ðernet; in 0394d52. It went into the shared mt7620n_zyxel_lte3301.dtsi, where the other aliases already are: both variants use the same ðernet 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.
4960cd2 to
0394d52
Compare
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]>
0394d52 to
e54e62e
Compare
|
Rebased onto current main. 980a740 had already bumped |
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 anddefault environment. The MAC is read from the config partition with
env readmemlike on the other boards in this package, and the environment isthe 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— theLTE3301 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 wastreated as a record count) and bounds the record walk.
build: add pad-to-ff image command— padding with 0xff for flash areas thathave 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
jbootimagetool theu-boot-install.binrecipe uses. This PR stays a draft until that is merged;the
tools: firmware-utils: update to Git HEADcommit is added afterwards.Installing over the vendor firmware
The vendor recovery only accepts its own record format, so
u-boot-install.binis 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:
The file field must be named
FNand the file name must be forced to a shortname ending in
.bin; the long default image name is what makes the browserupload fail with
ERROR/CAS 8002. Success is an HTML page containingCAS 8000. jboot writes the flash during the POST, so the image takes severalminutes. Power-cycle afterwards.
Tested on hardware (LTE3301-M209)
then flashed and verified byte-for-byte;
_firstbootreads the MAC out of the config partition (ethaddrmatches thelabel) and saves it, the next boot comes up with
Loading Environment from MTD... OK;button reset/button wps, partitions inmtd list;boot_tftp_sysupgrade→nor_write_production) and throughsysupgrade, FIT boot from flash;(
rt2800_read_eeprom_file/RF chipset 7620 detected), wlan0 = eth0 + 1;fw_printenvon the device;u-boot-install.binuploaded through the recovery (CAS 8000), and thedevice comes up with U-Boot, OpenWrt and a jffs2 overlay that initialises
itself on the first boot.