From a55d09d2917a55ab2eeb2dd5bb0866bb4cd9b524 Mon Sep 17 00:00:00 2001 From: Andrii Kuiukoff Date: Mon, 24 Aug 2026 16:00:12 +0300 Subject: [PATCH] mediatek: filogic: cmcc rax3000m: add all-in-UBI layout This commit introduces OpenWrt U-Boot all-in-UBI layout support for the CMCC RAX3000M / RAX3000Me, enabling: - Prolonged device lifetime by allocating most of the flash to UBI (which takes care of wear-leveling) - Maximum available storage space for OpenWrt OpenWrt U-Boot UBI flash instructions ------------------------------------- A device running stock firmware should be upgraded to the latest OpenWrt firmware (https://firmware-selector.openwrt.org/?target=mediatek%2Ffilogic&id=cmcc_rax3000m). Back up critical data --------------------- LuCI Web-UI: "System" -> "Backup / Flash Firmware" -> "Save mtdblock contents" Save mtdblock: factory Make sure the file were successfully downloaded to your downloads directory. Using the installer image ------------------------- To simplify the installation process, this method uses a fork of Daniel Golle's (@dangowrt) UBI Installer https://github.com/dangowrt/owrt-ubi-installer 1. Ensure your router is running the latest OpenWrt firmware. Upgrade it if necessary. 2. Obtain the installer image: Build the installer from source according to your device variant https://github.com/andros-ua/owrt-ubi-installer/tree/rax3000m-ddr3 or https://github.com/andros-ua/owrt-ubi-installer/tree/rax3000m-ddr4 or download a prebuilt image from the https://github.com/andros-ua/owrt-ubi-installer/releases 3. Flash the openwrt*-initramfs-recovery-installer.itb image using sysupgrade. 4. Wait for installation: the green status LED will blink rapidly, indicating that the all-in-UBI installer is running. Once the installation finishes, the status LED will turn solid amber for 5 seconds. 5. After the device reboots, perform a final sysupgrade using the openwrt*-squashfs-sysupgrade.itb image. BL2 and FIP Recovery -------------------- Use mtk_uartboot to recover corrupted BL2 or FIP via UART: https://github.com/981213/mtk_uartboot OpenWrt U-Boot layout ---------------------------------------- | dev: size erasesize name | | mtd4: 00100000 00020000 "bl2" | | mtd3: 00080000 00020000 "u-boot-env" | | mtd2: 00200000 00020000 "factory" | | mtd1: 00200000 00020000 "fip" | | mtd0: 07200000 00020000 "ubi" | ---------------------------------------- OpenWrt U-Boot UBI layout ---------------------------------- | dev: size erasesize name | | mtd1: 00100000 00020000 "bl2" | | mtd0: 07f00000 00020000 "ubi" | ---------------------------------- Update MAC table after inspecting the factory partition: ---------------------------------------------------------------- | Interface | MAC | Source | | |--------------|-------------------|---------------|-----------| | WAN (label) | 54:4d:d4:xx:xx:xx | factory, 0x24 | label | | LAN | 54:4d:d4:xx:xx:xx | factory, 0x2a | label + 3 | | WLAN 2.4 GHz | 54:4d:d4:xx:xx:xx | factory, 0x4 | label + 1 | | WLAN 5 GHz | 54:4d:d4:xx:xx:xx | factory, 0xa | label + 2 | ---------------------------------------------------------------- Signed-off-by: Andrii Kuiukoff Link: https://github.com/openwrt/openwrt/pull/24575 Signed-off-by: Jonas Jelonek --- .../dts/mt7981b-cmcc-rax3000m-ubi.dtso | 178 ++++++++++++++++++ target/linux/mediatek/image/filogic.mk | 10 +- 2 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 target/linux/mediatek/dts/mt7981b-cmcc-rax3000m-ubi.dtso diff --git a/target/linux/mediatek/dts/mt7981b-cmcc-rax3000m-ubi.dtso b/target/linux/mediatek/dts/mt7981b-cmcc-rax3000m-ubi.dtso new file mode 100644 index 00000000000..37014bcd642 --- /dev/null +++ b/target/linux/mediatek/dts/mt7981b-cmcc-rax3000m-ubi.dtso @@ -0,0 +1,178 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +/dts-v1/; +/plugin/; + +#include + +/ { + compatible = "cmcc,rax3000m", "mediatek,mt7981"; + + fragment@0 { + target = <&chosen>; + __overlay__ { + rootdisk = <&ubi_rootdisk>; + }; + }; + + fragment@1 { + target = <&gmac0>; + __overlay__ { + nvmem-cells = <&macaddr_factory_2a 0>; + nvmem-cell-names = "mac-address"; + }; + }; + + fragment@2 { + target = <&gmac1>; + __overlay__ { + nvmem-cells = <&macaddr_factory_24 0>; + nvmem-cell-names = "mac-address"; + }; + }; + + fragment@3 { + target = <&pio>; + __overlay__ { + spi0_flash_pins: spi0-pins { + mux { + function = "spi"; + groups = "spi0", "spi0_wp_hold"; + }; + + conf-pu { + pins = "SPI0_CS", "SPI0_HOLD", "SPI0_WP"; + drive-strength = ; + bias-disable; /* bias-disable */ + }; + + conf-pd { + pins = "SPI0_CLK", "SPI0_MOSI", "SPI0_MISO"; + drive-strength = ; + bias-disable; /* bias-disable */ + }; + }; + }; + }; + + fragment@4 { + target = <&spi0>; + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + pinctrl-names = "default"; + pinctrl-0 = <&spi0_flash_pins>; + status = "okay"; + + spi_nand@0 { + compatible = "spi-nand"; + reg = <0>; + + spi-max-frequency = <52000000>; + spi-tx-bus-width = <4>; + spi-rx-bus-width = <4>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "bl2"; + reg = <0x00000 0x0100000>; + read-only; + }; + + partition@100000 { + label = "ubi"; + reg = <0x100000 0x7f00000>; + compatible = "linux,ubi"; + + volumes { + ubi_factory: ubi-volume-factory { + volname = "factory"; + }; + + ubi_rootdisk: ubi-volume-fit { + volname = "fit"; + }; + + ubi-volume-ubootenv { + volname = "ubootenv"; + nvmem-layout { + compatible = "u-boot,env-redundant-bool"; + }; + }; + + ubi-volume-ubootenv2 { + volname = "ubootenv2"; + nvmem-layout { + compatible = "u-boot,env-redundant-bool"; + }; + }; + }; + }; + }; + }; + }; + }; + + fragment@5 { + target = <&ubi_factory>; + __overlay__ { + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + eeprom_factory_0: eeprom@0 { + reg = <0x0 0x1000>; + }; + + macaddr_factory_4: macaddr@4 { + reg = <0x4 0x6>; + compatible = "mac-base"; + #nvmem-cell-cells = <1>; + }; + + macaddr_factory_a: macaddr@a { + reg = <0xa 0x6>; + compatible = "mac-base"; + #nvmem-cell-cells = <1>; + }; + + macaddr_factory_24: macaddr@24 { + compatible = "mac-base"; + reg = <0x24 0x6>; + #nvmem-cell-cells = <1>; + }; + + macaddr_factory_2a: macaddr@2a { + compatible = "mac-base"; + reg = <0x2a 0x6>; + #nvmem-cell-cells = <1>; + }; + }; + }; + }; + + fragment@6 { + target = <&wifi>; + __overlay__ { + nvmem-cells = <&eeprom_factory_0>; + nvmem-cell-names = "eeprom"; + + band@0 { + reg = <0>; + nvmem-cells = <&macaddr_factory_4 0>; + nvmem-cell-names = "mac-address"; + }; + + band@1 { + reg = <1>; + nvmem-cells = <&macaddr_factory_a 0>; + nvmem-cell-names = "mac-address"; + }; + }; + }; +}; diff --git a/target/linux/mediatek/image/filogic.mk b/target/linux/mediatek/image/filogic.mk index b3a6ba32165..1cf71d6e737 100644 --- a/target/linux/mediatek/image/filogic.mk +++ b/target/linux/mediatek/image/filogic.mk @@ -1026,7 +1026,7 @@ define Device/cmcc_rax3000m DEVICE_ALT0_VENDOR := CMCC DEVICE_ALT0_MODEL := RAX3000Me DEVICE_DTS := mt7981b-cmcc-rax3000m - DEVICE_DTS_OVERLAY := mt7981b-cmcc-rax3000m-emmc mt7981b-cmcc-rax3000m-nand + DEVICE_DTS_OVERLAY := mt7981b-cmcc-rax3000m-emmc mt7981b-cmcc-rax3000m-nand mt7981b-cmcc-rax3000m-ubi DEVICE_DTS_DIR := ../dts DEVICE_DTC_FLAGS := --pad 4096 DEVICE_DTS_LOADADDR := 0x43f00000 @@ -1048,7 +1048,9 @@ define Device/cmcc_rax3000m emmc-ddr3-bl31-uboot.fip emmc-ddr3-preloader.bin \ emmc-ddr4-bl31-uboot.fip emmc-ddr4-preloader.bin \ nand-ddr3-bl31-uboot.fip nand-ddr3-preloader.bin \ - nand-ddr4-bl31-uboot.fip nand-ddr4-preloader.bin + nand-ddr4-bl31-uboot.fip nand-ddr4-preloader.bin \ + ubi-ddr3-bl31-uboot.fip ubi-ddr3-preloader.bin \ + ubi-ddr4-bl31-uboot.fip ubi-ddr4-preloader.bin ARTIFACT/emmc-gpt.bin := mt798x-gpt emmc ARTIFACT/emmc-ddr3-bl31-uboot.fip := mt7981-bl31-uboot cmcc_rax3000m-emmc-ddr3 ARTIFACT/emmc-ddr3-preloader.bin := mt7981-bl2 emmc-ddr3-1866 @@ -1058,6 +1060,10 @@ define Device/cmcc_rax3000m ARTIFACT/nand-ddr3-preloader.bin := mt7981-bl2 spim-nand-ddr3-1866 ARTIFACT/nand-ddr4-bl31-uboot.fip := mt7981-bl31-uboot cmcc_rax3000m-nand-ddr4 ARTIFACT/nand-ddr4-preloader.bin := mt7981-bl2 spim-nand-ddr4 + ARTIFACT/ubi-ddr3-bl31-uboot.fip := mt7981-bl31-uboot cmcc_rax3000m-ubi-ddr3 + ARTIFACT/ubi-ddr3-preloader.bin := mt7981-bl2 spim-nand-ubi-ddr3-1866 + ARTIFACT/ubi-ddr4-bl31-uboot.fip := mt7981-bl31-uboot cmcc_rax3000m-ubi-ddr4 + ARTIFACT/ubi-ddr4-preloader.bin := mt7981-bl2 spim-nand-ubi-ddr4 endef TARGET_DEVICES += cmcc_rax3000m