From aa73053a71533ce5e3f4b2ab975a5657a6e033fa Mon Sep 17 00:00:00 2001 From: AmadeusGhost <42570690+AmadeusGhost@users.noreply.github.com> Date: Sun, 11 Jul 2021 01:25:59 +0800 Subject: [PATCH] ipq806x: re-added support for Ruijie M520 again (#7330) Signed-off-by: AmadeusGhost --- .../ipq806x/base-files/etc/board.d/02_network | 7 + .../etc/hotplug.d/firmware/11-ath10k-caldata | 24 +- .../base-files/lib/preinit/04_reorder_eth | 5 + .../base-files/lib/upgrade/platform.sh | 3 + .../ipq806x/base-files/lib/upgrade/ruijie.sh | 54 +++ target/linux/ipq806x/config-5.10 | 2 + target/linux/ipq806x/config-5.4 | 6 +- .../boot/dts/qcom-ipq8064-rg-mtfi-m520.dts | 351 ++++++++++++++++++ target/linux/ipq806x/image/Makefile | 17 + .../0069-arm-boot-add-dts-files.patch | 3 +- .../0069-arm-boot-add-dts-files.patch | 3 +- 11 files changed, 468 insertions(+), 7 deletions(-) create mode 100644 target/linux/ipq806x/base-files/lib/upgrade/ruijie.sh create mode 100644 target/linux/ipq806x/files/arch/arm/boot/dts/qcom-ipq8064-rg-mtfi-m520.dts diff --git a/target/linux/ipq806x/base-files/etc/board.d/02_network b/target/linux/ipq806x/base-files/etc/board.d/02_network index 1a1cec51a..9523c5168 100644 --- a/target/linux/ipq806x/base-files/etc/board.d/02_network +++ b/target/linux/ipq806x/base-files/etc/board.d/02_network @@ -71,6 +71,13 @@ qcom,ipq8064-db149) ucidef_add_switch "switch0" \ "1:lan" "2:lan" "3:lan" "4:lan" "6u@eth1" "5:wan" "0u@eth0" ;; +ruijie,rg-mtfi-m520) + hw_mac_addr=$(mtd_get_mac_ascii PRODUCTINFO ethaddr) + ucidef_add_switch "switch0" \ + "1:lan" "6@eth1" "5:wan" "0@eth0" + ucidef_set_interface_macaddr "wan" "$hw_mac_addr" + ucidef_set_interface_macaddr "lan" "$(macaddr_add $hw_mac_addr 1)" + ;; tplink,ad7200) ucidef_add_switch "switch0" \ "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "6@eth1" "1:wan" "0@eth0" diff --git a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index d2bdf034b..c2c9c194b 100644 --- a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -7,9 +7,27 @@ board=$(board_name) case "$FIRMWARE" in +"ath10k/cal-pci-0000:01:00.0.bin") + case "$board" in + ruijie,rg-mtfi-m520) + caldata_extract "ART" 0x1000 0x844 + ath10k_patch_mac $(macaddr_add $(mtd_get_mac_ascii PRODUCTINFO ethaddr) 2) + ;; + esac + ;; +"ath10k/cal-pci-0001:01:00.0.bin") + case "$board" in + ruijie,rg-mtfi-m520) + caldata_extract "ART" 0x5000 0x844 + ath10k_patch_mac $(macaddr_add $(mtd_get_mac_ascii PRODUCTINFO ethaddr) 3) + ;; + esac + ;; "ath10k/pre-cal-pci-0000:01:00.0.bin") case $board in - askey,rt4230w-rev6 |\ + askey,rt4230w-rev6) + caldata_extract "0:ART" 0x1000 0x2f20 + ;; asrock,g10) if [ -b "$(find_mtd_part 0:art)" ]; then caldata_extract "0:art" 0x1000 0x2f20 @@ -69,7 +87,9 @@ case "$FIRMWARE" in ;; "ath10k/pre-cal-pci-0001:01:00.0.bin") case $board in - askey,rt4230w-rev6 |\ + askey,rt4230w-rev6) + caldata_extract "0:ART" 0x5000 0x2f20 + ;; asrock,g10) if [ -b "$(find_mtd_part 0:art)" ]; then caldata_extract "0:art" 0x5000 0x2f20 diff --git a/target/linux/ipq806x/base-files/lib/preinit/04_reorder_eth b/target/linux/ipq806x/base-files/lib/preinit/04_reorder_eth index 9f5847361..38d0606e9 100644 --- a/target/linux/ipq806x/base-files/lib/preinit/04_reorder_eth +++ b/target/linux/ipq806x/base-files/lib/preinit/04_reorder_eth @@ -7,6 +7,11 @@ preinit_reorder_eth() { ip link set eth1 name eth0 ip link set ethtmp name eth1 ;; + ruijie,rg-mtfi-m520) + base_mac=$(mtd_get_mac_ascii PRODUCTINFO ethaddr) + ip link set dev eth0 address $(macaddr_add "$base_mac" 1) + ip link set dev eth1 address $(macaddr_add "$base_mac" 2) + ;; esac } diff --git a/target/linux/ipq806x/base-files/lib/upgrade/platform.sh b/target/linux/ipq806x/base-files/lib/upgrade/platform.sh index a5e18201d..b77cfb3f8 100644 --- a/target/linux/ipq806x/base-files/lib/upgrade/platform.sh +++ b/target/linux/ipq806x/base-files/lib/upgrade/platform.sh @@ -55,6 +55,9 @@ platform_do_upgrade() { MTD_CONFIG_ARGS="-s 0x200000" default_do_upgrade "$1" ;; + ruijie,rg-mtfi-m520) + ruijie_do_upgrade "$1" + ;; zyxel,nbg6817) zyxel_do_upgrade "$1" ;; diff --git a/target/linux/ipq806x/base-files/lib/upgrade/ruijie.sh b/target/linux/ipq806x/base-files/lib/upgrade/ruijie.sh new file mode 100644 index 000000000..664462171 --- /dev/null +++ b/target/linux/ipq806x/base-files/lib/upgrade/ruijie.sh @@ -0,0 +1,54 @@ +# +# Copyright (C) 2016 lede-project.org +# + +ruijie_do_flash() { + local tar_file=$1 + local kernel=$2 + local rootfs=$3 + + # keep sure its unbound + losetup --detach-all || { + echo Failed to detach all loop devices. Skip this try. + reboot -f + } + + # use the first found directory in the tar archive + local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$') + board_dir=${board_dir%/} + + echo "flashing kernel to $kernel" + tar xf $tar_file ${board_dir}/kernel -O > $kernel + + echo "flashing rootfs to $rootfs" + tar xf $tar_file ${board_dir}/root -O > $rootfs + + # Cleanup + losetup -d /dev/loop0 >/dev/null 2>&1 + sync + umount -a + reboot -f +} + +ruijie_do_upgrade() { + local tar_file="$1" + local board=$(board_name) + local kernel= + local rootfs= + + case "$board" in + ruijie,rg-mtfi-m520) + kernel="/dev/mmcblk0p2" + rootfs="/dev/mmcblk0p3" + ;; + *) + return 1 + ;; + esac + + ruijie_do_flash $tar_file $kernel $rootfs + + nand_do_upgrade "$1" + + return 0 +} diff --git a/target/linux/ipq806x/config-5.10 b/target/linux/ipq806x/config-5.10 index 6b8a418d3..ba321dc0b 100644 --- a/target/linux/ipq806x/config-5.10 +++ b/target/linux/ipq806x/config-5.10 @@ -174,6 +174,8 @@ CONFIG_GENERIC_TIME_VSYSCALL=y CONFIG_GENERIC_VDSO_32=y CONFIG_GPIOLIB=y CONFIG_GPIOLIB_IRQCHIP=y +CONFIG_GPIO_PCA953X=y +CONFIG_GPIO_PCA953X_IRQ=y CONFIG_GRO_CELLS=y CONFIG_HANDLE_DOMAIN_IRQ=y CONFIG_HARDEN_BRANCH_PREDICTOR=y diff --git a/target/linux/ipq806x/config-5.4 b/target/linux/ipq806x/config-5.4 index ea68b8400..04ab0e365 100644 --- a/target/linux/ipq806x/config-5.4 +++ b/target/linux/ipq806x/config-5.4 @@ -1,6 +1,3 @@ -# CONFIG_PHY_QCOM_IPQ806X_USB is not set -CONFIG_REGULATOR_NSS_VOLT=y -# CONFIG_SHORTCUT_FE is not set CONFIG_64BIT_TIME=y CONFIG_ALIGNMENT_TRAP=y # CONFIG_APQ_GCC_8084 is not set @@ -168,6 +165,8 @@ CONFIG_GENERIC_STRNLEN_USER=y CONFIG_GENERIC_TIME_VSYSCALL=y CONFIG_GPIOLIB=y CONFIG_GPIOLIB_IRQCHIP=y +CONFIG_GPIO_PCA953X=y +CONFIG_GPIO_PCA953X_IRQ=y CONFIG_GRO_CELLS=y CONFIG_HANDLE_DOMAIN_IRQ=y CONFIG_HARDEN_BRANCH_PREDICTOR=y @@ -382,6 +381,7 @@ CONFIG_REGMAP=y CONFIG_REGMAP_MMIO=y CONFIG_REGULATOR=y CONFIG_REGULATOR_FIXED_VOLTAGE=y +CONFIG_REGULATOR_NSS_VOLT=y CONFIG_REGULATOR_QCOM_RPM=y # CONFIG_REGULATOR_QCOM_SPMI is not set CONFIG_RESET_CONTROLLER=y diff --git a/target/linux/ipq806x/files/arch/arm/boot/dts/qcom-ipq8064-rg-mtfi-m520.dts b/target/linux/ipq806x/files/arch/arm/boot/dts/qcom-ipq8064-rg-mtfi-m520.dts new file mode 100644 index 000000000..db992d7ae --- /dev/null +++ b/target/linux/ipq806x/files/arch/arm/boot/dts/qcom-ipq8064-rg-mtfi-m520.dts @@ -0,0 +1,351 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include "qcom-ipq8064-v2.0.dtsi" + +#include + +/ { + model = "Ruijie RG-MTFi-M520"; + compatible = "ruijie,rg-mtfi-m520", "qcom,ipq8064"; + + memory@0 { + reg = <0x42000000 0x7e000000>; + device_type = "memory"; + }; + + aliases { + mdio-gpio0 = &mdio0; + sdcc1 = &sdcc1; + + led-boot = &led_sys; + led-failsafe = &led_sys; + led-running = &led_sys; + led-upgrade = &led_sys; + }; + + chosen { + bootargs = "root=/dev/mmcblk0p3 rootfstype=squashfs,ext4 rootwait noinitrd"; + }; + + leds { + compatible = "gpio-leds"; + + led_sys: sys { + label = "green:sys"; + gpios = <&gpio_ext 15 GPIO_ACTIVE_LOW>; + }; + }; + + keys { + compatible = "gpio-keys"; + pinctrl-0 = <&button_pins>; + pinctrl-names = "default"; + + reset { + label = "reset"; + gpios = <&qcom_pinmux 54 GPIO_ACTIVE_LOW>; + linux,code = ; + }; + }; +}; + +&qcom_pinmux { + button_pins: button_pins { + mux { + pins = "gpio54"; + function = "gpio"; + drive-strength = <2>; + bias-pull-up; + }; + }; + + mdio0_pins: mdio0_pins { + clk { + pins = "gpio1"; + input-disable; + }; + }; + + rgmii2_pins: rgmii2_pins { + tx { + pins = "gpio27", "gpio28", "gpio29", "gpio30", "gpio31", "gpio32"; + input-disable; + }; + }; + + sdcc1_pins: sdcc1_pinmux { + mux { + pins = "gpio38", "gpio39", "gpio40", "gpio41", "gpio42", + "gpio43", "gpio44", "gpio45", "gpio46", "gpio47"; + function = "sdc1"; + }; + + cmd { + pins = "gpio45"; + drive-strength = <10>; + bias-pull-up; + }; + + data { + pins = "gpio38", "gpio39", "gpio40", "gpio41", + "gpio43", "gpio44", "gpio46", "gpio47"; + drive-strength = <10>; + bias-pull-up; + }; + + clk { + pins = "gpio42"; + drive-strength = <16>; + bias-disable; + }; + }; + + spi_pins: spi_pins { + cs { + pins = "gpio20"; + drive-strength = <12>; + }; + }; +}; + +&gsbi2 { + qcom,mode = ; + status = "okay"; + + i2c@124a0000 { + status = "okay"; + + lm75@48 { + compatible = "lm75"; + reg = <0x48>; + }; + + pcf8563: rtc@51 { + compatible = "nxp,pcf8563"; + reg = <0x51>; + }; + + gpio_ext: tca9539@74 { + compatible = "ti,tca9539"; + reg = <0x74>; + + gpio-controller; + #gpio-cells = <2>; + }; + }; +}; + +&gsbi5 { + qcom,mode = ; + status = "okay"; + + spi4: spi@1a280000 { + status = "okay"; + + pinctrl-0 = <&spi_pins>; + pinctrl-names = "default"; + + cs-gpios = <&qcom_pinmux 20 GPIO_ACTIVE_HIGH>; + + m25p80@0 { + compatible = "s25fl256s1"; + #address-cells = <1>; + #size-cells = <1>; + spi-max-frequency = <50000000>; + reg = <0>; + + SBL1@0 { + label = "SBL1"; + reg = <0x0 0x10000>; + read-only; + }; + + MIBIB@10000 { + label = "MIBIB"; + reg = <0x10000 0x10000>; + read-only; + }; + + SBL2@20000 { + label = "SBL2"; + reg = <0x20000 0x20000>; + read-only; + }; + + SBL3@40000 { + label = "SBL3"; + reg = <0x40000 0x30000>; + read-only; + }; + + DDRCONFIG@70000 { + label = "DDRCONFIG"; + reg = <0x70000 0x10000>; + read-only; + }; + + PRODUCTINFO@80000 { + label = "PRODUCTINFO"; + reg = <0x80000 0x10000>; + read-only; + }; + + TZ@90000 { + label = "TZ"; + reg = <0x90000 0x30000>; + read-only; + }; + + RPM@c0000 { + label = "RPM"; + reg = <0xc0000 0x20000>; + read-only; + }; + + APPSBL@e0000 { + label = "APPSBL"; + reg = <0xe0000 0x80000>; + read-only; + }; + + APPSBLENV@160000 { + label = "APPSBLENV"; + reg = <0x160000 0x10000>; + read-only; + }; + + BOOTCONFIG@170000 { + label = "BOOTCONFIG"; + reg = <0x170000 0x10000>; + read-only; + }; + + ART@180000 { + label = "ART"; + reg = <0x180000 0x40000>; + read-only; + }; + }; + }; +}; + +&sata_phy { + status = "okay"; +}; + +&sata { + status = "okay"; +}; + +&usb3_0 { + status = "okay"; +}; + +&usb3_1 { + status = "okay"; +}; + +&pcie0 { + status = "okay"; + reset-gpio = <&qcom_pinmux 3 GPIO_ACTIVE_HIGH>; + pinctrl-0 = <&pcie0_pins>; + pinctrl-names = "default"; +}; + +&pcie1 { + status = "okay"; + reset-gpio = <&qcom_pinmux 48 GPIO_ACTIVE_HIGH>; + pinctrl-0 = <&pcie1_pins>; + pinctrl-names = "default"; + max-link-speed = <1>; +}; + +&mdio0 { + status = "okay"; + pinctrl-0 = <&mdio0_pins>; + pinctrl-names = "default"; + phy0: ethernet-phy@0 { + reg = <0>; + qca,ar8327-initvals = < + 0x00004 0x7600000 /* PAD0_MODE */ + 0x00008 0x1000000 /* PAD5_MODE */ + 0x0000c 0x80 /* PAD6_MODE */ + 0x000e4 0x6a545 /* MAC_POWER_SEL */ + 0x000e0 0xc74164de /* SGMII_CTRL */ + 0x0007c 0x4e /* PORT0_STATUS */ + 0x00094 0x4e /* PORT6_STATUS */ + >; + }; + phy4: ethernet-phy@4 { + reg = <4>; + }; +}; + +&gmac1 { + status = "okay"; + compatible = "qcom,nss-gmac"; + reg = <0x37200000 0x200000>; + interrupts = ; + phy-mode = "rgmii"; + qcom,id = <1>; + qcom,pcs-chanid = <0>; + qcom,phy-mdio-addr = <0>; + qcom,poll-required = <0>; + qcom,rgmii-delay = <1>; + qcom,phy_mii_type = <0>; + qcom,emulation = <0>; + qcom,forced-speed = <1000>; + qcom,forced-duplex = <1>; + qcom,socver = <0>; + qcom,irq = <255>; + mdiobus = <&mdio0>; + + pinctrl-0 = <&rgmii2_pins>; + pinctrl-names = "default"; + + fixed-link { + speed = <1000>; + full-duplex; + }; +}; + +&gmac2 { + status = "okay"; + compatible = "qcom,nss-gmac"; + reg = <0x37400000 0x200000>; + interrupts = ; + phy-mode = "sgmii"; + qcom,id = <2>; + qcom,pcs-chanid = <1>; + qcom,phy-mdio-addr = <4>; + qcom,poll-required = <0>; /* no polling */ + qcom,rgmii-delay = <0>; + qcom,phy_mii_type = <1>; + qcom,emulation = <0>; + qcom,forced-speed = <1000>; + qcom,forced-duplex = <1>; + qcom,socver = <0>; + qcom,irq = <258>; + mdiobus = <&mdio0>; + + fixed-link { + speed = <1000>; + full-duplex; + }; +}; + +&amba { + sdcc1: sdcc@12400000 { + status = "okay"; + pinctrl-0 = <&sdcc1_pins>; + pinctrl-names = "default"; + }; +}; + +&adm_dma { + status = "okay"; +}; + +&CPU_SPC { + status = "disabled"; +}; diff --git a/target/linux/ipq806x/image/Makefile b/target/linux/ipq806x/image/Makefile index e53fba1e1..235459f74 100644 --- a/target/linux/ipq806x/image/Makefile +++ b/target/linux/ipq806x/image/Makefile @@ -344,6 +344,23 @@ define Device/qcom_ipq8064-db149 endef TARGET_DEVICES += qcom_ipq8064-db149 +define Device/ruijie_rg-mtfi-m520 + DEVICE_VENDOR := Ruijie + DEVICE_MODEL := RG-MTFi-M520 + SOC := qcom-ipq8064 + BLOCKSIZE := 64k + KERNEL_SIZE := 4096k + KERNEL_SUFFIX := -uImage + KERNEL = kernel-bin | append-dtb | uImage none | pad-to $$(KERNEL_SIZE) + KERNEL_NAME := zImage + IMAGES += factory.bin + IMAGE/factory.bin := qsdk-ipq-factory-mmc + IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-to $$$$(BLOCKSIZE) | sysupgrade-tar rootfs=$$$$@ | append-metadata + DEVICE_PACKAGES := ath10k-firmware-qca988x-ct e2fsprogs kmod-hwmon-lm75 \ + kmod-fs-ext4 kmod-fs-f2fs kmod-rtc-pcf8563 losetup mkf2fs +endef +TARGET_DEVICES += ruijie_rg-mtfi-m520 + define Device/tplink_ad7200 $(call Device/TpSafeImage) DEVICE_VENDOR := TP-Link diff --git a/target/linux/ipq806x/patches-5.10/0069-arm-boot-add-dts-files.patch b/target/linux/ipq806x/patches-5.10/0069-arm-boot-add-dts-files.patch index 87d6b6569..573ced9d9 100644 --- a/target/linux/ipq806x/patches-5.10/0069-arm-boot-add-dts-files.patch +++ b/target/linux/ipq806x/patches-5.10/0069-arm-boot-add-dts-files.patch @@ -10,7 +10,7 @@ Signed-off-by: John Crispin --- a/arch/arm/boot/dts/Makefile +++ b/arch/arm/boot/dts/Makefile -@@ -907,8 +907,26 @@ dtb-$(CONFIG_ARCH_QCOM) += \ +@@ -907,8 +907,27 @@ dtb-$(CONFIG_ARCH_QCOM) += \ qcom-ipq4019-ap.dk04.1-c3.dtb \ qcom-ipq4019-ap.dk07.1-c1.dtb \ qcom-ipq4019-ap.dk07.1-c2.dtb \ @@ -26,6 +26,7 @@ Signed-off-by: John Crispin + qcom-ipq8064-g10.dtb \ + qcom-ipq8064-r7500.dtb \ + qcom-ipq8064-r7500v2.dtb \ ++ qcom-ipq8064-rg-mtfi-m520.dtb \ + qcom-ipq8064-unifi-ac-hd.dtb \ + qcom-ipq8064-wg2600hp.dtb \ + qcom-ipq8064-wpq864.dtb \ diff --git a/target/linux/ipq806x/patches-5.4/0069-arm-boot-add-dts-files.patch b/target/linux/ipq806x/patches-5.4/0069-arm-boot-add-dts-files.patch index b97d36fd7..41827443d 100644 --- a/target/linux/ipq806x/patches-5.4/0069-arm-boot-add-dts-files.patch +++ b/target/linux/ipq806x/patches-5.4/0069-arm-boot-add-dts-files.patch @@ -10,7 +10,7 @@ Signed-off-by: John Crispin --- a/arch/arm/boot/dts/Makefile +++ b/arch/arm/boot/dts/Makefile -@@ -842,7 +842,25 @@ dtb-$(CONFIG_ARCH_QCOM) += \ +@@ -842,7 +842,26 @@ dtb-$(CONFIG_ARCH_QCOM) += \ qcom-ipq4019-ap.dk04.1-c3.dtb \ qcom-ipq4019-ap.dk07.1-c1.dtb \ qcom-ipq4019-ap.dk07.1-c2.dtb \ @@ -25,6 +25,7 @@ Signed-off-by: John Crispin + qcom-ipq8064-g10.dtb \ + qcom-ipq8064-r7500.dtb \ + qcom-ipq8064-r7500v2.dtb \ ++ qcom-ipq8064-rg-mtfi-m520.dtb \ + qcom-ipq8064-unifi-ac-hd.dtb \ + qcom-ipq8064-wg2600hp.dtb \ + qcom-ipq8064-wpq864.dtb \