ipq806x: add support for ASRock G10
authorChristian Lamparter <chunkeey@gmail.com>
Fri, 11 Oct 2019 22:49:15 +0000 (00:49 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 22 Dec 2020 18:11:50 +0000 (19:11 +0100)
The ASRock G10 is a 2.4/5 GHz band 11ac "Gaming" router,
based on Qualcomm IPQ8064.

Specifications:

SoC: Qualcomm IPQ8064
CPU: Dual-Core A15 @ (384 - 1,400 MHz, 2C2T)
DRAM: 512 MiB (~467 MiB available)
NAND: 128 MB (Micron MT29F1G08ABBEAH4)
WLAN0: 4T4R 5 GHz Wlan (QCA9980)
WLAN1: 4T4R 2.4 GHz Wlan (QCA9980)
ETH:    5x 10/100/1000 Mbps Ethernet (QCA8337)
INPUT:  Reset Button, WPS 2.4G and WPS 5G Button
LEDS:   1 multicolor status LED
USB:    2x USB 3.0 Type-A
POWER:  12VDC/3A AC Adapter + dedicated Power Switch
UART:   Setting is 115200-8-N-1. 1x4 .1" unpopulated header
on the PCB (J6 - very tiny silkscreen next to TX).
        Pinout: 1. 3v3 (Square - best skipped!), 2. RX, 3. GND, 4. TX

WARNING: The serial port needs a TTL/RS-232 3.3v level converter!
 (Depending on the serial adapter RX and TX might need to
  be swapped).

Note about the IR-Remote:
There's a 8-Bit MCU (SONIX SN8F25E21SG) which is controlling the
IR-Remote and is fed by the IR-Photodiode. The SoC can talk to
the device via I2C. The vendor's GPL archive comes with the source
of the interface driver for this as a (character driver), the main
control software is however a blob.

Installation Instructions:
 1. Download factory image to disk
 2. Apply factory image via stock web-gui

Back to stock:
 1. Login to router via ssh
 2. run "asrock_g10_back_to_factory" script from /sbin

Notes:
 - If something goes wrong durring sysupgrade, router will go back to
   factory image.
 - Asrock G10 uses partition layout from smem. So partition layout can
   be normal or alternate.
 - 900-arm-add-cmdline-override.patch was copied from 102-powerpc-add-cmdline-override.patch
   from powerpc target.

Knowledge about BOOTCONFIG partition was based on user "jmomo" post from old
OpenWrt forum (Post #50):
https://forum.archive.openwrt.org/viewtopic.php?id=65956&p=2

Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
[bump to 5.4, add factory image, fix sysupgrade, convert partition
layout to smem, remove ipq-wifi-asrock-g10 and use ART, minor fixes]
Co-Authored-by: Pawel Dembicki <paweldembicki@gmail.com>
Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
Tested-by: Lukasz Ostapiuk <palibrzuch@gmail.com>
13 files changed:
target/linux/ipq806x/base-files/etc/board.d/02_network
target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
target/linux/ipq806x/base-files/etc/init.d/bootcount
target/linux/ipq806x/base-files/lib/preinit/05_set_iface_mac_ipq806x.sh [new file with mode: 0644]
target/linux/ipq806x/base-files/lib/upgrade/asrock.sh [new file with mode: 0644]
target/linux/ipq806x/base-files/lib/upgrade/platform.sh
target/linux/ipq806x/base-files/sbin/asrock_g10_back_to_factory [new file with mode: 0755]
target/linux/ipq806x/config-5.4
target/linux/ipq806x/files-5.4/arch/arm/boot/dts/qcom-ipq8064-g10.dts [new file with mode: 0644]
target/linux/ipq806x/image/Makefile
target/linux/ipq806x/patches-5.4/0069-arm-boot-add-dts-files.patch
target/linux/ipq806x/patches-5.4/900-arm-add-cmdline-override.patch [new file with mode: 0644]
target/linux/ipq806x/patches-5.4/997-device_tree_cmdline.patch

index 3f9d96881d36d07dfd8c90564bcce75e059f373f..eecf81a8cd000ff436f002bf55a1c065d4d4a9f3 100755 (executable)
@@ -12,6 +12,11 @@ board_config_update
 board=$(board_name)
 
 case "$board" in
+asrock,g10 |\
+nec,wg2600hp)
+       ucidef_add_switch "switch0" \
+               "2:lan" "3:lan" "4:lan" "5:lan" "6@eth1" "1:wan" "0@eth0"
+       ;;
 buffalo,wxr-2533dhp |\
 compex,wpq864 |\
 netgear,d7800 |\
@@ -41,10 +46,6 @@ linksys,ea8500)
        ucidef_set_interface_macaddr "lan" "$hw_mac_addr"
        ucidef_set_interface_macaddr "wan" "$hw_mac_addr"
        ;;
-nec,wg2600hp)
-       ucidef_add_switch "switch0" \
-               "2:lan" "3:lan" "4:lan" "5:lan" "6@eth1" "1:wan" "0@eth0"
-       ;;
 netgear,r7800 |\
 tplink,c2600)
        ucidef_add_switch "switch0" \
index 74ad00c5ced91f53b99b554efe235eaf2528a789..a22af9b676f9b2e97d763bf8fddf47fee1af4806 100644 (file)
@@ -9,6 +9,9 @@ board=$(board_name)
 case "$FIRMWARE" in
 "ath10k/pre-cal-pci-0000:01:00.0.bin")
        case $board in
+       asrock,g10)
+               caldata_extract "0:ART" 0x1000 0x2f20
+               ;;
        buffalo,wxr-2533dhp)
                caldata_extract "ART" 0x1000 0x2f20
                ath10k_patch_mac $(mtd_get_mac_binary ART 0x1e)
@@ -47,6 +50,9 @@ case "$FIRMWARE" in
        ;;
 "ath10k/pre-cal-pci-0001:01:00.0.bin")
        case $board in
+       asrock,g10)
+               caldata_extract "0:ART" 0x5000 0x2f20
+               ;;
        buffalo,wxr-2533dhp)
                caldata_extract "ART" 0x5000 0x2f20
                ath10k_patch_mac $(mtd_get_mac_binary ART 0x18)
index 77965e647bb94cb6b1972c47d393ed2e17109435..7a54c34dbaca433320e594e86fbb605914750d55 100755 (executable)
@@ -2,8 +2,16 @@
 
 START=99
 
+. /lib/upgrade/asrock.sh
+
 boot() {
        case $(board_name) in
+       asrock,g10)
+               asrock_bootconfig_mangle "bootcheck"
+               if [ $? -eq 0 ]; then
+                       reboot
+               fi
+               ;;
        edgecore,ecw5410)
                fw_setenv bootcount 0
                ;;
diff --git a/target/linux/ipq806x/base-files/lib/preinit/05_set_iface_mac_ipq806x.sh b/target/linux/ipq806x/base-files/lib/preinit/05_set_iface_mac_ipq806x.sh
new file mode 100644 (file)
index 0000000..ca8d0b1
--- /dev/null
@@ -0,0 +1,14 @@
+. /lib/functions.sh
+
+preinit_set_mac_address() {
+       case $(board_name) in
+       asrock,g10)
+               lan_mac=$(mtd_get_mac_ascii hwconfig HW.LAN.MAC.Address)
+               wan_mac=$(mtd_get_mac_ascii hwconfig HW.WAN.MAC.Address)
+               ip link set dev eth0 address "${lan_mac}"
+               ip link set dev eth1 address "${wan_mac}"
+               ;;
+       esac
+}
+
+boot_hook_add preinit_main preinit_set_mac_address
diff --git a/target/linux/ipq806x/base-files/lib/upgrade/asrock.sh b/target/linux/ipq806x/base-files/lib/upgrade/asrock.sh
new file mode 100644 (file)
index 0000000..71cac3f
--- /dev/null
@@ -0,0 +1,55 @@
+. /lib/functions.sh
+
+
+asrock_bootconfig_mangle() {
+       local mtdnum="$( find_mtd_index 0:BOOTCONFIG )"
+
+       if [ -z "$mtdnum" ]; then
+               echo "cannot find bootconfig mtd partition"
+               return 1
+       fi
+       dd if=/dev/mtd$mtdnum of=/tmp/mtd$mtdnum bs=1k
+
+       local partition_byte="$(dd if=/tmp/mtd$mtdnum bs=1 skip=52 count=1)"
+       local upgrade_byte="$(dd if=/tmp/mtd$mtdnum bs=1 skip=4 count=1)"
+
+       if [ $1 = "bootcheck" ]; then
+               if [ ! -s $upgrade_byte ]; then
+                       dd if=/dev/mtd$mtdnum of=/tmp/mtd$mtdnum bs=1k
+                       printf '\x00' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=4
+                       printf '\x00' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=56
+               else
+                       return 1
+               fi
+       elif [ $1 = "sysupgrade" ]; then
+               printf '\x01' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=4
+               printf '\x01' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=56
+       fi
+
+       if [ -s $partition_byte ]; then
+               printf '\x01' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=52
+       else
+               printf '\x00' | dd of=/tmp/mtd$mtdnum conv=notrunc bs=1 seek=52
+       fi
+
+       mtd write /tmp/mtd$mtdnum /dev/mtd$mtdnum
+       return 0
+}
+
+asrock_upgrade_prepare() {
+       local ubidev="$( nand_find_ubi ubi )"
+
+       #Set upgrade flag. If something goes wrong, router will boot with
+       #factory firmware.
+       asrock_bootconfig_mangle 'sysupgrade'
+
+       if [ $? -ne 0 ]; then
+               echo "cannot find bootconfig mtd partition"
+               exit 1
+       fi
+
+       # Just delete these partitions if present and use
+       # OpenWrt's standard names for those.
+       ubirmvol /dev/$ubidev -N ubi_rootfs &> /dev/null || true
+       ubirmvol /dev/$ubidev -N ubi_rootfs_data &> /dev/null || true
+}
index f61e8ee8782d634564f2bde4afc5c9809db62e53..f5d6c5d55d66e52ada80c75d57d922fc518f5f09 100644 (file)
@@ -10,6 +10,10 @@ platform_check_image() {
 
 platform_do_upgrade() {
        case "$(board_name)" in
+       asrock,g10)
+               asrock_upgrade_prepare
+               nand_do_upgrade "$1"
+               ;;
        buffalo,wxr-2533dhp)
                buffalo_upgrade_prepare_ubi
                CI_ROOTPART="ubi_rootfs"
diff --git a/target/linux/ipq806x/base-files/sbin/asrock_g10_back_to_factory b/target/linux/ipq806x/base-files/sbin/asrock_g10_back_to_factory
new file mode 100755 (executable)
index 0000000..55aa91e
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+. /lib/upgrade/asrock.sh
+
+case $(board_name) in
+asrock,g10)
+       asrock_bootconfig_mangle "factory"
+       if [ $? -eq 0 ]; then
+               reboot
+       fi
+       ;;
+*)
+       echo "Unsupported hardware."
+       ;;
+esac
+
index 2c8e6bbbb0936854d16ed6982e6aa09ad836bb39..e6160bd4554d5aa6f429e93c2752e1ce3a5399f5 100644 (file)
@@ -78,6 +78,7 @@ CONFIG_CC_HAS_KASAN_GENERIC=y
 CONFIG_CLKDEV_LOOKUP=y
 CONFIG_CLKSRC_QCOM=y
 CONFIG_CLONE_BACKWARDS=y
+CONFIG_CMDLINE_OVERRIDE=y
 CONFIG_COMMON_CLK=y
 CONFIG_COMMON_CLK_QCOM=y
 CONFIG_COMPAT_32BIT_TIME=y
diff --git a/target/linux/ipq806x/files-5.4/arch/arm/boot/dts/qcom-ipq8064-g10.dts b/target/linux/ipq806x/files-5.4/arch/arm/boot/dts/qcom-ipq8064-g10.dts
new file mode 100644 (file)
index 0000000..15ed5b4
--- /dev/null
@@ -0,0 +1,242 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "qcom-ipq8064-v2.0.dtsi"
+
+#include <dt-bindings/input/input.h>
+#include <dt-bindings/soc/qcom,tcsr.h>
+
+/ {
+       compatible = "asrock,g10", "qcom,ipq8064";
+       model = "ASRock G10";
+
+       aliases {
+               ethernet0 = &gmac1;
+               ethernet1 = &gmac0;
+
+               led-boot = &led_status_blue;
+               led-failsafe = &led_status_amber;
+               led-running = &led_status_blue;
+               led-upgrade = &led_status_amber;
+       };
+
+       chosen {
+               bootargs-override = "console=ttyMSM0,115200n8";
+       };
+
+       leds {
+               compatible = "gpio-leds";
+
+               pinctrl-0 = <&led_pins>;
+               pinctrl-names = "default";
+
+               /*
+                * this is a bit misleading. Because there are about seven
+                * multicolor LEDs connected all wired together in parallel.
+                */
+
+               status_yellow {
+                       label = "yellow:status";
+                       gpios = <&qcom_pinmux 8 GPIO_ACTIVE_HIGH>;
+               };
+
+               led_status_amber: status_amber {
+                       label = "amber:status";
+                       gpios = <&qcom_pinmux 7 GPIO_ACTIVE_HIGH>;
+               };
+
+               led_status_blue: status_blue {
+                       label = "blue:status";
+                       gpios = <&qcom_pinmux 9 GPIO_ACTIVE_HIGH>;
+               };
+
+               /*
+                * LED is declared in vendors boardfile but it's not
+                * working and the manual doesn't mention anything
+                * about the LED being white.
+
+               status_white {
+                       label = "white:status";
+                       gpios = <&qcom_pinmux 26 GPIO_ACTIVE_HIGH>;
+               };
+               */
+       };
+
+       i2c-gpio {
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               compatible = "i2c-gpio";
+               gpios = <&qcom_pinmux 53 GPIO_ACTIVE_HIGH>, /* sda */
+                       <&qcom_pinmux 54 GPIO_ACTIVE_HIGH>; /* scl */
+               i2c-gpio,delay-us = <5>;
+               i2c-gpio,scl-output-only;
+
+               mcu@50 {
+                       reg = <0x50>;
+                       compatible = "sonix,sn8f25e21";
+               };
+       };
+
+       keys {
+               compatible = "gpio-keys";
+
+               pinctrl-0 = <&button_pins>;
+               pinctrl-names = "default";
+
+               ir-remote {
+                       label = "ir-remote";
+                       gpios = <&qcom_pinmux 15 GPIO_ACTIVE_LOW>;
+                       linux,code = <BTN_0>;
+               };
+
+               reset {
+                       label = "reset";
+                       gpios = <&qcom_pinmux 16 GPIO_ACTIVE_LOW>;
+                       linux,code = <KEY_RESTART>;
+               };
+
+               wps5g {
+                       label = "wps5g";
+                       gpios = <&qcom_pinmux 64 GPIO_ACTIVE_LOW>;
+                       linux,code = <KEY_WPS_BUTTON>;
+               };
+
+               wps2g {
+                       label = "wps2g";
+                       gpios = <&qcom_pinmux 65 GPIO_ACTIVE_LOW>;
+                       linux,code = <KEY_WPS_BUTTON>;
+               };
+       };
+};
+
+&adm_dma {
+       status = "okay";
+};
+
+&gmac1 {
+       status = "okay";
+
+       pinctrl-0 = <&rgmii2_pins>;
+       pinctrl-names = "default";
+
+       phy-mode = "rgmii";
+       qcom,id = <1>;
+
+       fixed-link {
+               speed = <1000>;
+               full-duplex;
+       };
+};
+
+&gmac2 {
+       status = "okay";
+
+       phy-mode = "sgmii";
+       qcom,id = <2>;
+
+       fixed-link {
+               speed = <1000>;
+               full-duplex;
+       };
+};
+
+&gsbi4_serial {
+       pinctrl-0 = <&uart0_pins>;
+       pinctrl-names = "default";
+};
+
+&mdio0 {
+       status = "okay";
+
+       pinctrl-0 = <&mdio0_pins>;
+       pinctrl-names = "default";
+
+       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 */
+                       >;
+       };
+};
+
+&nand_controller {
+       status = "okay";
+
+       pinctrl-0 = <&nand_pins>;
+       pinctrl-names = "default";
+
+       nand@0 {
+               reg = <0>;
+               compatible = "qcom,nandcs";
+
+               nand-ecc-strength = <4>;
+               nand-bus-width = <8>;
+               nand-ecc-step-size = <512>;
+
+               partitions {
+                       compatible = "qcom,smem";
+               };
+       };
+};
+
+&pcie0 {
+       status = "okay";
+};
+
+&pcie1 {
+       status = "okay";
+};
+
+&qcom_pinmux {
+       led_pins: led_pins {
+               mux {
+                       pins = "gpio7", "gpio8", "gpio9", "gpio26";
+                       function = "gpio";
+                       drive-strength = <2>;
+                       bias-pull-up;
+               };
+       };
+
+       button_pins: button_pins {
+               mux {
+                       pins = "gpio15", "gpio16", "gpio64", "gpio65";
+                       function = "gpio";
+                       drive-strength = <2>;
+                       bias-pull-up;
+               };
+       };
+
+       uart0_pins: uart0_pins {
+               mux {
+                       pins = "gpio10", "gpio11";
+                       function = "gsbi4";
+                       drive-strength = <10>;
+                       bias-disable;
+               };
+       };
+};
+
+&rpm {
+       pinctrl-0 = <&i2c4_pins>;
+       pinctrl-names = "default";
+};
+
+&usb3_0 {
+       status = "okay";
+};
+
+&usb3_1 {
+       status = "okay";
+};
+
+&tcsr {
+       qcom,usb-ctrl-select = <TCSR_USB_SELECT_USB3_DUAL>;
+};
+
+/delete-node/ &pcie2_pins;
+/delete-node/ &pcie2;
index ec73630ae575b907ec6ae47e3ca4da678bdd2f43..ad7c4b94d2b8008ee08f1f7b2ed52ce25d9d9b0f 100644 (file)
@@ -13,6 +13,16 @@ define Build/buffalo-rootfs-cksum
        ) >> $@
 endef
 
+define Build/edimax-header
+       $(eval edimax_model=$(word 1,$(1)))
+
+       $(STAGING_DIR_HOST)/bin/mkedimaximg \
+       -b -s CSYS -m $(edimax_model) \
+       -f 0x70000 -S 0x1200000 \
+       -i $@ -o $@.new
+       @mv $@.new $@
+endef
+
 define Device/Default
        PROFILES := Default
        KERNEL_DEPENDS = $$(wildcard $(DTS_DIR)/$$(DEVICE_DTS).dts)
@@ -82,6 +92,20 @@ define Device/ZyXELImage
        IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-to $$$$(BLOCKSIZE) | sysupgrade-tar rootfs=$$$$@ | append-metadata
 endef
 
+define Device/asrock_g10
+       $(call Device/FitImage)
+       $(call Device/UbiFit)
+       SOC := qcom-ipq8064
+       DEVICE_VENDOR := ASRock
+       DEVICE_MODEL := G10
+       BLOCKSIZE := 128k
+       PAGESIZE := 2048
+       KERNEL_SIZE := 5332k
+       DEVICE_PACKAGES := kmod-i2c-gpio ath10k-firmware-qca99x0-ct
+       IMAGE/nand-factory.bin := append-ubi | edimax-header RN67
+endef
+TARGET_DEVICES += asrock_g10
+
 define Device/buffalo_wxr-2533dhp
        $(call Device/LegacyImage)
        SOC := qcom-ipq8064
index 7e15b87e398ea71a045136d1319207dac0add15b..6bbf184ac7e8b2a9cb6e71a1956f350e8fb82b7d 100644 (file)
@@ -10,7 +10,7 @@ Signed-off-by: John Crispin <john@phrozen.org>
 
 --- a/arch/arm/boot/dts/Makefile
 +++ b/arch/arm/boot/dts/Makefile
-@@ -843,6 +843,20 @@ dtb-$(CONFIG_ARCH_QCOM) += \
+@@ -843,6 +843,21 @@ dtb-$(CONFIG_ARCH_QCOM) += \
        qcom-ipq4019-ap.dk07.1-c1.dtb \
        qcom-ipq4019-ap.dk07.1-c2.dtb \
        qcom-ipq8064-ap148.dtb \
@@ -20,6 +20,7 @@ Signed-off-by: John Crispin <john@phrozen.org>
 +      qcom-ipq8064-ap161.dtb \
 +      qcom-ipq8064-ea7500-v1.dtb \
 +      qcom-ipq8064-ea8500.dtb \
++      qcom-ipq8064-g10.dtb \
 +      qcom-ipq8064-r7500.dtb \
 +      qcom-ipq8064-r7500v2.dtb \
 +      qcom-ipq8064-wg2600hp.dtb \
diff --git a/target/linux/ipq806x/patches-5.4/900-arm-add-cmdline-override.patch b/target/linux/ipq806x/patches-5.4/900-arm-add-cmdline-override.patch
new file mode 100644 (file)
index 0000000..bb3aa26
--- /dev/null
@@ -0,0 +1,37 @@
+--- a/arch/arm/Kconfig
++++ b/arch/arm/Kconfig
+@@ -1836,6 +1836,14 @@ config ARM_ATAG_DTB_COMPAT_CMDLINE_MANGL
+         Only command line ATAG will be processed, the rest of the ATAGs
+         sent by bootloader will be ignored.
++config CMDLINE_OVERRIDE
++    bool "Use alternative cmdline from device tree"
++    help
++      Some bootloaders may have uneditable bootargs. While CMDLINE_FORCE can
++      be used, this is not a good option for kernels that are shared across
++      devices. This setting enables using "chosen/cmdline-override" as the
++      cmdline if it exists in the device tree.
++
+ endchoice
+ config CMDLINE
+--- a/drivers/of/fdt.c
++++ b/drivers/of/fdt.c
+@@ -1060,6 +1060,17 @@ int __init early_init_dt_scan_chosen(uns
+       if (p != NULL && l > 0)
+               strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
++    /* CONFIG_CMDLINE_OVERRIDE is used to fallback to a different
++     * device tree option of chosen/bootargs-override. This is
++     * helpful on boards where u-boot sets bootargs, and is unable
++     * to be modified.
++     */
++#ifdef CONFIG_CMDLINE_OVERRIDE
++      p = of_get_flat_dt_prop(node, "bootargs-override", &l);
++      if (p != NULL && l > 0)
++              strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));
++#endif
++
+       /*
+        * CONFIG_CMDLINE is meant to be a default in case nothing else
+        * managed to set the command line, unless CONFIG_CMDLINE_FORCE
index 3cc032fdd24bdb1758a821314077e4385f127712..b6b1b047656a0b9e7ef7205f5213fbdcde1271f5 100644 (file)
@@ -8,5 +8,5 @@
 +      if (p != NULL && l > 0)
 +              strlcat(data, p, min_t(int, strlen(data) + (int)l, COMMAND_LINE_SIZE));
  
-       /*
-        * CONFIG_CMDLINE is meant to be a default in case nothing else
+     /* CONFIG_CMDLINE_OVERRIDE is used to fallback to a different
+      * device tree option of chosen/bootargs-override. This is