ramips: add support for TP-Link Archer C20 v1
authorMaxim Anisimov <maxim.anisimov.ua@gmail.com>
Fri, 8 Sep 2017 09:39:17 +0000 (12:39 +0300)
committerMathias Kresin <dev@kresin.me>
Wed, 13 Sep 2017 06:07:54 +0000 (08:07 +0200)
TP-Link Archer C20 v1 is a router with 5-port FE switch and
non-detachable antennas. It's very similiar to TP-Link Archer C50.
Also it's based on MediaTek MT7620A+MT7610EN.

Specification:
- MediaTek MT7620A (580 Mhz)
- 64 MB of RAM
- 8 MB of FLASH
- 2T2R 2.4 GHz and 1T1R 5 GHz
- 5x 10/100 Mbps Ethernet
- 2x external, non-detachable antennas
- UART (J1) header on PCB (115200 8n1)
- 8x LED (GPIO-controlled*), 2x button, power input switch
- 1 x USB 2.0 port

* WAN LED in this devices is a dual-color, dual-leads type which isn't
  (fully) supported by gpio-leds driver. This type of LED requires both
  GPIOs state change at the same time to select color or turn it off.
  For now, we support/use only the blue part of the LED.
* MT7610EN ac chip isn't not supported by LEDE. Therefore 5Ghz won't
  work.

Factory image notes:

These devices use version 3 of TP-Link header, fortunately without RSA
signature (at least in case of devices sold in Europe). The difference
lays in the requirement for a non-zero value in "Additional Hardware
Version" field. Ideally, it should match the value stored in vendor
firmware header on device.

We are able to prepare factory firwmare file which is accepted and
(almost) correctly flashed from the vendor GUI. As it turned out, it
accepts files without U-Boot image with second header at the beginning
but due to some kind of bug in upgrade routine, flashed image gets
corrupted before it's written to flash. So, to flash this device we must
to prepare image using original firmware from tp-link site with uboot.

Flash instruction:

Until (if at all) TP-Link fixes described problem, the only way to flash
LEDE image in these devices is to use tftp recovery mode in U-Boot.
There are two ways to flash the device to LEDE:

1) Using tftp mode with UART connection and original LEDE image

 - Place lede-ramips-mt7620-ArcherC20-squashfs-factory.bin in tftp
   server directory
 - Configure PC with static IP 192.168.0.66/24 and tftp server.
 - Connect PC with one of LAN ports, power up the router and press
   key "4" to access U-Boot CLI.
 - Use the following commands to update the device to LEDE:

    setenv serverip 192.168.0.66
    tftp 0x80060000 lede-ramips-mt7620-ArcherC20-squashfs-factory.bin
    erase tplink 0x20000 0x7a0000
    cp.b 0x80060000 0x20000 0x7a0000
    reset

 - After that the device will reboot and boot to LEDE

2) Using tftp mode without UART connection but require some
   manipulations with target image

 - Download and unpack TP-Link Archer C20 v1 firmware from original web
   site
 - Split uboot.bin from original firmware by this command (example):

    dd if=Archer_C20v1_0.9.1_4.0_up_boot(160427)_2016-04-27_13.53.59.bin of=uboot.bin bs=512 count=256 skip=1

 - Create ArcherC20V1_tp_recovery.bin using this command:

    cat uboot.bin lede-ramips-mt7620-ArcherC20-squashfs-factory.bin > ArcherC20V1_tp_recovery.bin

 - Place ArcherC20V1_tp_recovery.bin in tftp server directory.
 - Configure PC with static IP 192.168.0.66/24 and tftp server.
 - Connect PC with one of LAN ports, press the reset button, power up
   the router and keep button pressed for around 6-7 seconds, until
   device starts downloading the file.
 - Router will download file from server, write it to flash and reboot.

Signed-off-by: Maxim Anisimov <maxim.anisimov.ua@gmail.com>
target/linux/ramips/base-files/etc/board.d/01_leds
target/linux/ramips/base-files/etc/board.d/02_network
target/linux/ramips/base-files/etc/diag.sh
target/linux/ramips/base-files/lib/ramips.sh
target/linux/ramips/base-files/lib/upgrade/platform.sh
target/linux/ramips/dts/ArcherC20.dts [new file with mode: 0644]
target/linux/ramips/image/mt7620.mk
tools/firmware-utils/src/mktplinkfw2.c

index f6a7bac81ad45dea0580829bad988932325e4088..a0baa61027105f94bad9da569623b84e08fed130 100755 (executable)
@@ -86,6 +86,12 @@ c108)
        ucidef_set_led_netdev "lan" "lan" "$board:green:lan" "eth0"
        ucidef_set_led_netdev "modem" "modem" "$board:green:modem" "wwan0"
        ;;
+c20)
+       ucidef_set_led_switch "lan" "lan" "$board:blue:lan" "switch0" "0x1e"
+       ucidef_set_led_switch "wan" "wan" "$board:blue:wan" "switch0" "0x01"
+       set_usb_led "$board:blue:usb"
+       ucidef_set_led_netdev "wlan2g" "wlan2g" "$board:blue:wlan2g" "wlan0"
+       ;;
 c20i)
        ucidef_set_led_switch "lan" "lan" "$board:blue:lan" "switch0" "0x1e"
        ucidef_set_led_switch "wan" "wan" "$board:blue:wan" "switch0" "0x01"
index 6f05259467eb295c73f6658e2dd2a6f1e994dd08..862e99b0bbd221ae28bbf3dcbfd396f8ab80614e 100755 (executable)
@@ -184,6 +184,7 @@ ramips_setup_interfaces()
                ucidef_add_switch "switch0" \
                        "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
                ;;
+       c20|\
        c50)
                ucidef_add_switch "switch0" \
                        "1:lan:3" "2:lan:4" "3:lan:1" "4:lan:2" "0:wan" "6@eth0"
index 16c83f2d3f92062f1c648b6e2bb0e95ed7012e29..0345f1e8bf774eb50f2014dee1c01126b693d88c 100644 (file)
@@ -119,6 +119,7 @@ get_status_led() {
        w502u)
                status_led="$board:blue:wps"
                ;;
+       c20|\
        d240|\
        dap-1350|\
        na930|\
index d0055d422b73b88903207c858a07934f6d6870b0..d0b9bb126279a7a4a64f83047e33efbe52544ece 100755 (executable)
@@ -88,6 +88,9 @@ ramips_board_detect() {
        *"C108")
                name="c108"
                ;;
+       *"C20")
+               name="c20"
+               ;;
        *"C20i")
                name="c20i"
                ;;
index 09a7dae394600927ee72290d1088d1b703bbfc08..e08c45d8dbfcea01d49e059371618c267a2cab90 100755 (executable)
@@ -230,6 +230,7 @@ platform_check_image() {
                }
                return 0
                ;;
+       c20|\
        c20i|\
        c50|\
        mr200|\
diff --git a/target/linux/ramips/dts/ArcherC20.dts b/target/linux/ramips/dts/ArcherC20.dts
new file mode 100644 (file)
index 0000000..a0e7c61
--- /dev/null
@@ -0,0 +1,189 @@
+/dts-v1/;
+
+#include "mt7620a.dtsi"
+
+#include <dt-bindings/input/input.h>
+#include <dt-bindings/gpio/gpio.h>
+
+/ {
+       compatible = "tplink,c20", "ralink,mt7620a-soc";
+       model = "TP-Link Archer C20";
+
+       chosen {
+               bootargs = "console=ttyS0,115200";
+       };
+
+       gpio-leds {
+               compatible = "gpio-leds";
+
+               lan {
+                       label = "c20:blue:lan";
+                       gpios = <&gpio0 1 GPIO_ACTIVE_LOW>;
+               };
+
+               power {
+                       label = "c20:blue:power";
+                       gpios = <&gpio0 7 GPIO_ACTIVE_LOW>;
+               };
+
+               usb {
+                       label = "c20:blue:usb";
+                       gpios = <&gpio2 4 GPIO_ACTIVE_LOW>;
+               };
+
+               wan {
+                       label = "c20:blue:wan";
+                       gpios = <&gpio0 11 GPIO_ACTIVE_HIGH>;
+               };
+
+               wan_orange {
+                       label = "c20:orange:wan";
+                       gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>;
+               };
+
+               wlan5g {
+                       label = "c20:blue:wlan5g";
+                       gpios = <&gpio0 17 GPIO_ACTIVE_LOW>;
+               };
+
+               wlan2g {
+                       label = "c20:blue:wlan2g";
+                       gpios = <&gpio3 0 GPIO_ACTIVE_LOW>;
+               };
+
+               wps {
+                       label = "c20:blue:wps";
+                       gpios = <&gpio1 15 GPIO_ACTIVE_LOW>;
+               };
+       };
+
+       gpio-keys-polled {
+               compatible = "gpio-keys-polled";
+               #address-cells = <1>;
+               #size-cells = <0>;
+               poll-interval = <20>;
+
+               reset {
+                       label = "reset";
+                       gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
+                       linux,code = <KEY_RESTART>;
+               };
+
+               rfkill {
+                       label = "rfkill";
+                       gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
+                       linux,code = <KEY_RFKILL>;
+               };      };
+};
+
+&gpio1 {
+       status = "okay";
+};
+
+&gpio2 {
+       status = "okay";
+};
+
+&gpio3 {
+       status = "okay";
+};
+
+&spi0 {
+       status = "okay";
+
+       m25p80@0 {
+               #address-cells = <1>;
+               #size-cells = <1>;
+               compatible = "jedec,spi-nor";
+               reg = <0>;
+               spi-max-frequency = <10000000>;
+
+               partition@0 {
+                       label = "u-boot";
+                       reg = <0x0 0x20000>;
+                       read-only;
+               };
+
+               partition@20000 {
+                       label = "firmware";
+                       reg = <0x20000 0x7a0000>;
+               };
+
+               partition@7c0000 {
+                       label = "config";
+                       reg = <0x7c0000 0x10000>;
+                       read-only;
+               };
+
+               rom: partition@7d0000 {
+                       label = "rom";
+                       reg = <0x7d0000 0x10000>;
+                       read-only;
+               };
+
+               partition@7e0000 {
+                       label = "romfile";
+                       reg = <0x7e0000 0x10000>;
+                       read-only;
+               };
+
+               radio: partition@7f0000 {
+                       label = "radio";
+                       reg = <0x7f0000 0x10000>;
+                       read-only;
+               };
+       };
+};
+
+&pinctrl {
+       state_default: pinctrl0 {
+               gpio {
+                       ralink,group = "i2c", "uartf", "wled", "ephy", "spi refclk", "wdt";
+                       ralink,function = "gpio";
+               };
+
+               pa {
+                       ralink,group = "pa";
+                       ralink,function = "pa";
+               };
+       };
+};
+
+&ethernet {
+               pinctrl-names = "default";
+               mtd-mac-address = <&rom 0xf100>;
+               mediatek,portmap = "wllll";
+       };
+
+&ehci {
+       status = "okay";
+};
+
+&ohci {
+       status = "okay";
+};
+
+&gsw {
+       mediatek,port4 = "ephy";
+};
+
+&wmac {
+       ralink,mtd-eeprom = <&radio 0>;
+       mtd-mac-address = <&rom 0xf100>;
+       mtd-mac-address-increment = <(-2)>;
+};
+
+&pcie {
+       status = "okay";
+
+       pcie-bridge {
+               mt76@0,0 {
+                       reg = <0x0000 0 0 0 0>;
+                       device_type = "pci";
+                       mediatek,mtd-eeprom = <&radio 32768>;
+                       ieee80211-freq-limit = <5000000 6000000>;
+                       mtd-mac-address = <&rom 0xf100>;
+                       mtd-mac-address-increment = <(-1)>;
+               };
+       };
+};
index 6d2533d349bab48a4c1e9b81bd513f5e799ff534..f964b3e0821ceb7de58724559cc3f5712343a629 100644 (file)
@@ -32,6 +32,17 @@ define Device/Archer
   IMAGE/sysupgrade.bin := tplink-v2-image -s | append-metadata
 endef
 
+define Device/ArcherC20
+  $(Device/Archer)
+  DTS := ArcherC20
+  SUPPORTED_DEVICES := c20
+  TPLINK_BOARD_ID := ArcherC20
+  IMAGES += factory.bin
+  DEVICE_TITLE := TP-Link ArcherC20
+  DEVICE_PACKAGES := kmod-usb-core kmod-usb2 kmod-usb-ledtrig-usbport
+endef
+TARGET_DEVICES += ArcherC20
+
 define Device/ArcherC20i
   $(Device/Archer)
   DTS := ArcherC20i
index 7d094774c85dbb2413162483113472dbf56fe6c3..6ef51db55b9fc14ca39b3b3f631c6e4074fb2d1e 100644 (file)
@@ -180,6 +180,14 @@ static struct board_info boards[] = {
                .hw_id          = 0x89800001,
                .hw_rev         = 14,
                .layout_id      = "8Mltq",
+       }, {
+               .id             = "ArcherC20",
+               .hw_id          = 0xc2000001,
+               .hw_rev         = 0x44,
+               .hw_ver_add     = 0x1,
+               .layout_id      = "8Mmtk",
+               .hdr_ver        = 3,
+               .flags          = FLAG_LE_KERNEL_LA_EP
        }, {
                .id             = "ArcherC20i",
                .hw_id          = 0xc2000001,