diff --git a/target/linux/ramips/dts/mt7621_teltonika_rutm-common.dtsi b/target/linux/ramips/dts/mt7621_teltonika_rutm-common.dtsi new file mode 100644 index 0000000000..b99de1b386 --- /dev/null +++ b/target/linux/ramips/dts/mt7621_teltonika_rutm-common.dtsi @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include "mt7621.dtsi" + +#include +#include +#include + +/ { + aliases { + led-boot = &led_power; + led-failsafe = &led_power; + led-running = &led_power; + led-upgrade = &led_power; + }; + + /* NAND flash is devided by half for failover. + Bootloader dynamically pass which partition to boot, + we can't change CONFIG_MIPS_CMDLINE_FROM_DTB, so + cmdline have to be hardcoded to second partition */ + + chosen { + bootargs = "console=ttyS0,115200n8 ubi.mtd=rutos-b"; + }; + + keys { + compatible = "gpio-keys"; + + reset { + label = "reset"; + linux,code = ; + gpios = <&gpio 10 GPIO_ACTIVE_LOW>; + debounce-interval = <60>; + }; + }; + + leds { + compatible = "gpio-leds"; + + led_power: power { + function = LED_FUNCTION_POWER; + color = ; + gpios = <&gpio 0 GPIO_ACTIVE_LOW>; + }; + }; +}; + +&spi0 { + status = "okay"; + + flash@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + spi-max-frequency = <10000000>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "u-boot"; + reg = <0x0 0x80000>; + read-only; + }; + + partition@80000 { + label = "u-boot-env"; + reg = <0x80000 0x10000>; + read-only; + }; + + partition@90000 { + label = "config"; + reg = <0x90000 0x10000>; + read-only; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + macaddr_config_0: macaddr@0 { + compatible = "mac-base"; + reg = <0x0 0x6>; + #nvmem-cell-cells = <1>; + }; + }; + }; + + partition@a0000 { + label = "bootconfig-a"; + reg = <0xa0000 0x10000>; + }; + + partition@b0000 { + label = "bootconfig-b"; + reg = <0xb0000 0x10000>; + }; + + partition@c0000 { + label = "factory"; + reg = <0xc0000 0x10000>; + read-only; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + eeprom_factory_0: eeprom@0 { + reg = <0x0 0x4da8>; + }; + }; + }; + + partition@d0000 { + label = "event-log"; + reg = <0xd0000 0x90000>; + }; + + partition@400000 { + label = "recovery"; + reg = <0x200000 0xe00000>; + }; + }; + }; + + flash@1 { + compatible = "spi-nand"; + #address-cells = <1>; + #size-cells = <1>; + reg = <1>; + spi-max-frequency = <24000000>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "rutos-a"; + reg = <0x00000000 0x08000000>; + }; + + partition@8000000 { + label = "rutos-b"; + reg = <0x08000000 0x08000000>; + }; + }; + }; +}; + +&gmac0 { + nvmem-cells = <&macaddr_config_0 0>; + nvmem-cell-names = "mac-address"; +}; + +&gmac1 { + status = "okay"; + label = "wan"; + phy-handle = <ðphy4>; + nvmem-cells = <&macaddr_config_0 1>; + nvmem-cell-names = "mac-address"; +}; + +&state_default { + gpio { + groups = "wdt", "jtag", "sdhci", "uart2", "uart3"; + function = "gpio"; + }; +}; + +ðphy4 { + /delete-property/ interrupts; +}; diff --git a/target/linux/ramips/dts/mt7621_teltonika_rutm50.dts b/target/linux/ramips/dts/mt7621_teltonika_rutm50.dts new file mode 100644 index 0000000000..478fd50cf3 --- /dev/null +++ b/target/linux/ramips/dts/mt7621_teltonika_rutm50.dts @@ -0,0 +1,250 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include "mt7621_teltonika_rutm-common.dtsi" + +/ { + compatible = "teltonika,rutm50", "mediatek,mt7621-soc"; + model = "Teltonika RUTM50/RUTM51"; + + gpio_spi { + compatible = "spi-gpio"; + #address-cells = <1>; + #size-cells = <0>; + + sck-gpios = <&gpio 9 GPIO_ACTIVE_HIGH>; + mosi-gpios = <&gpio 5 GPIO_ACTIVE_HIGH>; + cs-gpios = <&gpio 11 GPIO_ACTIVE_HIGH>; + num-chipselects = <1>; + + gpio_hc595: gpio_hc595@0 { + compatible = "fairchild,74hc595"; + reg = <0>; + gpio-controller; + #gpio-cells = <2>; + registers-number = <2>; + spi-max-frequency = <10000000>; + enable-gpios = <&gpio 44 GPIO_ACTIVE_LOW>; + }; + }; + + gpio-export { + compatible = "gpio-export"; + + gpio_modem_reset { + gpio-export,name = "modem_reset"; + gpio-export,output = <0>; + gpios = <&gpio 14 GPIO_ACTIVE_HIGH>; + }; + + gpio_modem_power { + gpio-export,name = "modem_power"; + gpio-export,output = <0>; + gpios = <&gpio 17 GPIO_ACTIVE_HIGH>; + }; + }; + + leds { + wan_sim1 { + function = "wan-sim1"; + color = ; + gpios = <&gpio 41 GPIO_ACTIVE_HIGH>; + }; + + wan_sim2 { + function = "wan-sim2"; + color = ; + gpios = <&gpio 43 GPIO_ACTIVE_HIGH>; + }; + + wan_eth { + function = "wan-eth"; + color = ; + gpios = <&gpio 45 GPIO_ACTIVE_HIGH>; + }; + + wan_wifi { + function = "wan-wifi"; + color = ; + gpios = <&gpio 42 GPIO_ACTIVE_HIGH>; + }; + + wifi_2g { + function = LED_FUNCTION_WLAN_2GHZ; + color = ; + gpios = <&gpio_hc595 10 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "phy0tpt"; + }; + + wifi_5g { + function = LED_FUNCTION_WLAN_5GHZ; + color = ; + gpios = <&gpio_hc595 11 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "phy1tpt"; + }; + + 3G { + function = "3G"; + color = ; + gpios = <&gpio 16 GPIO_ACTIVE_HIGH>; + }; + + 4G { + function = "4G"; + color = ; + gpios = <&gpio 15 GPIO_ACTIVE_HIGH>; + }; + + 5G { + function = "5G"; + color = ; + gpios = <&gpio 13 GPIO_ACTIVE_HIGH>; + }; + + rssi1 { + function = "rssi-1"; + color = ; + gpios = <&gpio 47 GPIO_ACTIVE_HIGH>; + }; + + rssi2 { + function = "rssi-2"; + color = ; + gpios = <&gpio 48 GPIO_ACTIVE_HIGH>; + }; + + rssi3 { + function = "rssi-3"; + color = ; + gpios = <&gpio 46 GPIO_ACTIVE_HIGH>; + }; + + lan1-g { + function = LED_FUNCTION_LAN; + function-enumerator = <1>; + color = ; + gpios = <&gpio_hc595 0 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "mt7530-0:00:1Gbps"; + }; + + lan1-y { + function = LED_FUNCTION_LAN; + function-enumerator = <1>; + color = ; + gpios = <&gpio_hc595 5 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "mt7530-0:00:100Mbps"; + }; + + lan2-g { + function = LED_FUNCTION_LAN; + function-enumerator = <2>; + color = ; + gpios = <&gpio_hc595 1 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "mt7530-0:01:1Gbps"; + }; + + lan2-y { + function = LED_FUNCTION_LAN; + function-enumerator = <2>; + color = ; + gpios = <&gpio_hc595 6 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "mt7530-0:01:100Mbps"; + }; + + lan3-g { + function = LED_FUNCTION_LAN; + function-enumerator = <3>; + color = ; + gpios = <&gpio_hc595 2 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "mt7530-0:02:1Gbps"; + }; + + lan3-y { + function = LED_FUNCTION_LAN; + function-enumerator = <3>; + color = ; + gpios = <&gpio_hc595 7 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "mt7530-0:02:100Mbps"; + }; + + lan4-g { + function = LED_FUNCTION_LAN; + function-enumerator = <4>; + color = ; + gpios = <&gpio_hc595 3 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "mt7530-0:03:1Gbps"; + }; + + lan4-y { + function = LED_FUNCTION_LAN; + function-enumerator = <4>; + color = ; + gpios = <&gpio_hc595 8 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "mt7530-0:03:100Mbps"; + }; + + wan-g { + function = LED_FUNCTION_WAN; + color = ; + gpios = <&gpio_hc595 4 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "mt7530-0:04:1Gbps"; + }; + + wan-y { + function = LED_FUNCTION_WAN; + color = ; + gpios = <&gpio_hc595 9 GPIO_ACTIVE_HIGH>; + linux,default-trigger = "mt7530-0:04:100Mbps"; + }; + }; +}; + +&switch0 { + ports { + port@0 { + status = "okay"; + label = "lan1"; + }; + + port@1 { + status = "okay"; + label = "lan2"; + }; + + port@2 { + status = "okay"; + label = "lan3"; + }; + + port@3 { + status = "okay"; + label = "lan4"; + }; + }; +}; + +&pcie { + status = "okay"; +}; + +&pcie0 { + wifi@0,0 { + compatible = "mediatek,mt76"; + reg = <0x0000 0 0 0 0>; + nvmem-cells = <&eeprom_factory_0>; + nvmem-cell-names = "eeprom"; + #address-cells = <1>; + #size-cells = <0>; + + band@0 { + reg = <0>; + nvmem-cells = <&macaddr_config_0 2>; + nvmem-cell-names = "mac-address"; + }; + + band@1 { + reg = <1>; + nvmem-cells = <&macaddr_config_0 3>; + nvmem-cell-names = "mac-address"; + }; + }; +}; diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk index 54a8bed143..a5d6d0404d 100644 --- a/target/linux/ramips/image/mt7621.mk +++ b/target/linux/ramips/image/mt7621.mk @@ -8,6 +8,8 @@ include ./common-tp-link.mk DEFAULT_SOC := mt7621 DEVICE_VARS += BUFFALO_TRX_MAGIC ELECOM_HWNAME LINKSYS_HWNAME DLINK_HWID +DEVICE_VARS += SUPPORTED_TELTONIKA_DEVICES +DEVICE_VARS += SUPPORTED_TELTONIKA_HW_MODS define Image/Prepare # For UBI we want only one extra block @@ -2866,6 +2868,29 @@ define Device/tenbay_t-mb5eu-v01 endef TARGET_DEVICES += tenbay_t-mb5eu-v01 +define Device/teltonika_rutm_common + $(Device/nand) + DEVICE_VENDOR := Teltonika + SUPPORTED_TELTONIKA_DEVICES := teltonika,rutm + SUPPORTED_TELTONIKA_HW_MODS := W25N02KV + KERNEL_IN_UBI := 1 + FILESYSTEMS := squashfs + IMAGE_SIZE := 147456k + DEVICE_PACKAGES := kmod-mt7615-firmware kmod-usb3 kmod-usb-serial-option \ + kmod-gpio-nxp-74hc164 kmod-spi-gpio -uboot-envtools + IMAGES += factory.bin + IMAGE/factory.bin := append-ubi | check-size | append-teltonika-metadata +endef + +define Device/teltonika_rutm50 + $(Device/teltonika_rutm_common) + DEVICE_MODEL := RUTM50 + DEVICE_ALT0_VENDOR := Teltonika + DEVICE_ALT0_MODEL := RUTM51 + DEVICE_PACKAGES += kmod-usb-net-qmi-wwan kmod-usb-net-cdc-ncm +endef +TARGET_DEVICES += teltonika_rutm50 + define Device/thunder_timecloud $(Device/dsa-migration) $(Device/uimage-lzma-loader) diff --git a/target/linux/ramips/mt7621/base-files/etc/board.d/03_gpio_switches b/target/linux/ramips/mt7621/base-files/etc/board.d/03_gpio_switches index 2e8158795a..4c1f3835b4 100644 --- a/target/linux/ramips/mt7621/base-files/etc/board.d/03_gpio_switches +++ b/target/linux/ramips/mt7621/base-files/etc/board.d/03_gpio_switches @@ -12,6 +12,10 @@ mikrotik,routerboard-760igs) telco-electronics,x1) ucidef_add_gpio_switch "modem_reset" "Modem Reset" "528" ;; +teltonika,rutm50) + ucidef_add_gpio_switch "modem_power" "Modem power button" "modem_power" "1" + ucidef_add_gpio_switch "modem_reset" "Modem reset" "modem_reset" "0" + ;; tozed,zlt-s12-pro) ucidef_add_gpio_switch "lt72_power" "Power LTE modem" "lt72_power" "1" ;; diff --git a/target/linux/ramips/mt7621/base-files/etc/init.d/bootcount b/target/linux/ramips/mt7621/base-files/etc/init.d/bootcount index 5704d39955..00830ee876 100755 --- a/target/linux/ramips/mt7621/base-files/etc/init.d/bootcount +++ b/target/linux/ramips/mt7621/base-files/etc/init.d/bootcount @@ -49,5 +49,27 @@ boot() { [ $(printf %d $(fw_printenv -n Image1Stable)) -gt 0 ] || fw_setenv Image1Stable 1 [ $(printf %d $(fw_printenv -n Image1Try)) -gt 0 ] && fw_setenv Image1Try 0 ;; + teltonika,rutm50) + #Bootloader expect successfull startup value after update, we need to write success value to bootconfig partition + #otherwise bootloader will fallback to previous root partition + . /lib/functions.sh + local PART="$(cmdline_get_var ubi.mtd)" + local MTD_INDEX=$(find_mtd_index bootconfig-a) + + case "$PART" in + rutos-a) + [ "$(md5sum /dev/mtd$MTD_INDEX | awk '{print $1}')" = "adc4a78e76efc6b4afdc41925e4017c6" ] || { + logger -t "bootcount" "saving new failsafe boot config in /dev/mtd$MTD_INDEX bootconfig-a partition rutos-a" + echo -ne "\xe1\xb0\xba\xba\x01\x00\xf9\x01\xf8\x01\xf0\x00\x3d\xd4\xfb\x95" | mtd -e bootconfig-a write - bootconfig-a + } + ;; + rutos-b) + [ "$(md5sum /dev/mtd$MTD_INDEX | awk '{print $1}')" = "2904b3476604ef153d1925acdde062e8" ] || { + logger -t "bootcount" "saving new failsafe boot config in /dev/mtd$MTD_INDEX bootconfig-a partition rutos-b" + echo -ne "\xe1\xb0\xba\xba\x01\x01\xf7\x01\xf8\x00\xf0\x00\xce\xd4\x44\x08" | mtd -e bootconfig-a write - bootconfig-a + } + ;; + esac + ;; esac } diff --git a/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh index f80d9d9266..0439c494da 100644 --- a/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh +++ b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh @@ -230,6 +230,10 @@ platform_do_upgrade() { zyxel_mstc_upgrade_prepare nand_do_upgrade "$1" ;; + teltonika,rutm50) + CI_UBIPART="$(cmdline_get_var ubi.mtd)" + nand_do_upgrade "$1" + ;; *) default_do_upgrade "$1" ;;