From 9e20d3ddab6bc3648f690199c176b27773d6b826 Mon Sep 17 00:00:00 2001 From: INAGAKI Hiroshi Date: Thu, 25 Apr 2024 01:08:41 +0900 Subject: [PATCH] ath79: add support for NEC Aterm WR8750N MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NEC Aterm WR8750N is a 2.4/5 GHz band 11n (Wi-Fi 4) router, based on AR9344. Specification: - SoC : Atheros AR9344 - RAM : DDR2 128 MiB (2x Hynix H5PS5162GFR-S6C) - Flash : SPI-NOR 8 MiB (Macronix MX25L6406EMI-12G) - WLAN : 2.4/5 GHz 2T2R - 2.4 GHz : Atheros AR9344 (SoC) - 5 GHz : Atheros AR9382 - Ethernet : 5x 10/100/1000 Mbps - switch : Atheros AR8327 - LEDs/Keys (GPIO): 10x/4x - note : all LEDs are controlled by ath9k chip (AR9382) - UART : through-hole on PCB - assignment : 3.3V, GND, NC, TX, RX from tri-angle marking - settings : 9600n8 - USB : 1x USB 2.0 Type-A - hub (internal): NEC uPD720114 - Power : 12 VDC, 1.5 A (Max. 16 W) - Stock OS : NetBSD based Flash instruction using initramfs-factory.bin image: 1. Boot WR8750N with router mode normally 2. Access to the WebUI ("http://aterm.me/" or "http://192.168.0.1/") on the device and open firmware update page ("ファームウェア更新") 3. Select the OpenWrt initramfs-factory.bin image and click update ("更新") button 4. After updating, the device will be rebooted and booted with OpenWrt initramfs image 5. On the initramfs image, upload (or download) uboot.bin and sysupgrade.bin image to the device 6. Replace the bootloader with a uboot.bin image mtd write bootloader 7. Perform sysupgrade with a sysupgrade.bin image sysupgrade 8. Wait ~120 seconds to complete flashing Flash instruction using initramfs-necboot.bin image: 1. Connect and open serial console 2. Power on WR8750N and interrupt bootloader by ESC key 3. Login to the bootloader CLI with a password "chiron" 4. Start TFTP server by "tftpd" command 5. Upload initramfs-necboot.bin via tftp from your computer example (Windows): tftp -i 192.168.0.1 PUT initramfs-necboot.bin 6. Boot initramfs image by "boot" command 7. On the initramfs image, back up the stock bootloader and firmware if needed 8. Upload (or download) uboot.bin and sysupgrade.bin image to the device 9. Replace the bootloader with a uboot.bin image 10. Perform sysupgrade with a sysupgrade.bin image 11. Wait ~120 seconds to complete flashing Notes: - All LEDs are connected to the GPIO controller on the ath9k chip (AR9382) and controlled by it. Those LEDs are probed after probing of ath9k chip, so they cannot be handled as status LEDs of OpenWrt while booting. - A reset pin of the internal USB hub is connected to the GPIO controller of the ath9k chip, like LEDs above. That hub will be detected after probing of the ath9k chip. - The stock bootloader requires an unknown filesystem on firmware area in the flash. Booting of OpenWrt from that filesystem cannot be handled, so the bootloader needs to be replaced to mainline U-Boot before OpenWrt installation. MAC Addresses: LAN : 1C:B1:7F:xx:xx:00 (config, 0x6 (hex)) WAN : 1C:B1:7F:xx:xx:01 (config, 0xc (hex)) 2.4 GHz: 1C:B1:7F:xx:xx:02 (config, 0x0 (hex) / art, 0x1002 (hex)) 5 GHz : 1C:B1:7F:xx:xx:03 (config, 0x12 (hex) / art, 0x5002 (hex)) Signed-off-by: INAGAKI Hiroshi --- target/linux/ath79/dts/ar9344_nec_aterm.dtsi | 300 ++++++++++++++++++ target/linux/ath79/dts/ar9344_nec_wr8750n.dts | 16 + target/linux/ath79/image/common-nec.mk | 75 +++++ .../linux/ath79/image/lzma-loader/src/board.c | 65 ++++ target/linux/ath79/image/tiny.mk | 11 + .../tiny/base-files/etc/board.d/02_network | 13 +- .../tiny/base-files/lib/upgrade/platform.sh | 16 +- 7 files changed, 491 insertions(+), 5 deletions(-) create mode 100644 target/linux/ath79/dts/ar9344_nec_aterm.dtsi create mode 100644 target/linux/ath79/dts/ar9344_nec_wr8750n.dts create mode 100644 target/linux/ath79/image/common-nec.mk diff --git a/target/linux/ath79/dts/ar9344_nec_aterm.dtsi b/target/linux/ath79/dts/ar9344_nec_aterm.dtsi new file mode 100644 index 00000000000000..f6ce148762bb9d --- /dev/null +++ b/target/linux/ath79/dts/ar9344_nec_aterm.dtsi @@ -0,0 +1,300 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include +#include +#include + +#include "ar9344.dtsi" + +/ { + aliases { + led-running = &led_power_green; + led-upgrade = &led_power_green; + }; + + chosen { + /* + * don't specify bootargs property in DeviceTree to + * enable a console with a default baudrate (9600) + * or passed console= parameter from the bootloader + */ + /delete-property/ bootargs; + stdout-path = &uart; + }; + + keys: keys { + compatible = "gpio-keys"; + pinctrl-names = "default"; + pinctrl-0 = <&jtag_disable_pins>; + + button-eco { + label = "eco"; + gpios = <&gpio 3 GPIO_ACTIVE_LOW>; + linux,code = ; + debounce-interval = <60>; + }; + + switch-ap { + label = "ap"; + gpios = <&gpio 11 GPIO_ACTIVE_LOW>; + linux,code = ; + debounce-interval = <60>; + }; + + button-reset { + label = "reset"; + gpios = <&gpio 15 GPIO_ACTIVE_LOW>; + linux,code = ; + debounce-interval = <60>; + }; + + button-wps { + label = "wps"; + gpios = <&gpio 16 GPIO_ACTIVE_LOW>; + linux,code = ; + debounce-interval = <60>; + }; + }; + + ath9k_leds: ath9k-leds { + /* all LEDs are connected to ath9k chip (AR938x) */ + compatible = "gpio-leds"; + + led_power_green: led-0 { + gpios = <&ath9k 0 GPIO_ACTIVE_LOW>; + color = ; + function = LED_FUNCTION_POWER; + default-state = "on"; + }; + + led-1 { + gpios = <&ath9k 1 GPIO_ACTIVE_LOW>; + color = ; + function = LED_FUNCTION_POWER; + }; + + led-2 { + gpios = <&ath9k 2 GPIO_ACTIVE_LOW>; + color = ; + function = LED_FUNCTION_WAN_ONLINE; + }; + + led-3 { + gpios = <&ath9k 3 GPIO_ACTIVE_LOW>; + color = ; + function = LED_FUNCTION_WAN_ONLINE; + }; + + led-4 { + gpios = <&ath9k 4 GPIO_ACTIVE_LOW>; + color = ; + function = LED_FUNCTION_WLAN_2GHZ; + linux,default-trigger = "phy0tpt"; + }; + + led-5 { + gpios = <&ath9k 5 GPIO_ACTIVE_LOW>; + color = ; + function = LED_FUNCTION_WLAN_2GHZ; + }; + + led-6 { + gpios = <&ath9k 6 GPIO_ACTIVE_LOW>; + color = ; + function = LED_FUNCTION_WLAN_5GHZ; + linux,default-trigger = "phy1tpt"; + }; + + led-7 { + gpios = <&ath9k 7 GPIO_ACTIVE_LOW>; + color = ; + function = LED_FUNCTION_WLAN_5GHZ; + }; + + led-8 { + gpios = <&ath9k 12 GPIO_ACTIVE_LOW>; + color = ; + function = "tv"; + }; + + led-9 { + gpios = <&ath9k 13 GPIO_ACTIVE_LOW>; + color = ; + function = "tv"; + }; + }; + + reg_usb_vbus: regulator { + compatible = "regulator-fixed"; + regulator-name = "usb-vbus"; + regulator-min-microvolt = <5000000>; + regulator-max-microvolt = <5000000>; + gpio = <&gpio 20 GPIO_ACTIVE_HIGH>; + enable-active-high; + regulator-always-on; + }; +}; + +&ref { + clock-frequency = <40000000>; +}; + +&spi { + status = "okay"; + + flash@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + spi-max-frequency = <25000000>; + + partitions: partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + /* + * since the OEM bootloader requires unknown + * filesystem on firmware area, needs to be + * replaced to u-boot before OpenWrt installation + */ + partition@0 { + label = "bootloader"; + reg = <0x000000 0x020000>; + }; + + /* not compatible with u-boot */ + partition@20000 { + label = "config"; + reg = <0x020000 0x010000>; + read-only; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + macaddr_config_6: macaddr@6 { + reg = <0x6 0x6>; + }; + }; + }; + + partition@30000 { + label = "art"; + reg = <0x030000 0x010000>; + read-only; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + cal_art_1000: calibration@1000 { + reg = <0x1000 0x440>; + }; + + cal_art_5000: calibration@5000 { + reg = <0x5000 0x440>; + }; + }; + }; + }; + }; +}; + +&mdio0 { + status = "okay"; + + phy0: ethernet-phy@0 { + reg = <0>; + + qca,ar8327-initvals = < + 0x04 0x07a00000 /* PORT0_PAD_MODE_CTRL */ + 0x08 0x00000000 /* PORT5_PAD_MODE_CTRL */ + 0x0c 0x00000000 /* PORT6_PAD_MODE_CTRL */ + 0x10 0x81000080 /* POWER_ON_STRAP */ + 0x50 0xcf37cf37 /* LED_CTRL0 */ + 0x54 0x00000000 /* LED_CTRL1 */ + 0x58 0x00000000 /* LED_CTRL2 */ + 0x5c 0x03ffff00 /* LED_CTRL3 */ + 0x7c 0x0000007e /* PORT0_STATUS */ + >; + }; +}; + +ð0 { + status = "okay"; + + pll-data = <0x06000000 0x00000101 0x00001616>; + + phy-mode = "rgmii"; + phy-handle = <&phy0>; + + nvmem-cells = <&macaddr_config_6>; + nvmem-cell-names = "mac-address"; + + gmac-config { + device = <&gmac>; + + rgmii-gmac0 = <1>; + rxdv-delay = <0>; + rxd-delay = <0>; + txd-delay = <0>; + txen-delay = <0>; + }; +}; + +&gpio { + switch-reset { + gpio-hog; + gpios = <13 GPIO_ACTIVE_HIGH>; + output-high; + }; +}; + +&pcie { + status = "okay"; + + ath9k: wifi@0,0 { + compatible = "pci168c,0030"; + reg = <0x0000 0 0 0 0>; + #gpio-cells = <2>; + gpio-controller; + + nvmem-cells = <&cal_art_5000>; + nvmem-cell-names = "calibration"; + + usb-hub-reset { + gpio-hog; + gpios = <10 GPIO_ACTIVE_HIGH>; + output-high; + }; + }; +}; + +&usb_phy { + status = "okay"; +}; + +&usb { + status = "okay"; + #address-cells = <1>; + #size-cells = <0>; + + dr_mode = "host"; + + /delete-node/ port@1; + + /* NEC uPD720114 */ + hub@1 { + compatible = "usb0409,005a"; + reg = <1>; + }; +}; + +&wmac { + status = "okay"; + + nvmem-cells = <&cal_art_1000>; + nvmem-cell-names = "calibration"; +}; diff --git a/target/linux/ath79/dts/ar9344_nec_wr8750n.dts b/target/linux/ath79/dts/ar9344_nec_wr8750n.dts new file mode 100644 index 00000000000000..47e49dddc5b71b --- /dev/null +++ b/target/linux/ath79/dts/ar9344_nec_wr8750n.dts @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include "ar9344_nec_aterm.dtsi" + +/ { + compatible = "nec,wr8750n", "qca,ar9344"; + model = "NEC Aterm WR8750N"; +}; + +&partitions { + partition@40000 { + compatible = "denx,uimage"; + label = "firmware"; + reg = <0x040000 0x7c0000>; + }; +}; diff --git a/target/linux/ath79/image/common-nec.mk b/target/linux/ath79/image/common-nec.mk new file mode 100644 index 00000000000000..6996c3eafb5cf0 --- /dev/null +++ b/target/linux/ath79/image/common-nec.mk @@ -0,0 +1,75 @@ +DEVICE_VARS += NEC_FW_TYPE + +define Build/nec-append-uboot + cat $(STAGING_DIR_IMAGE)/$(SOC)_nec_aterm-u-boot.bin >> $@ +endef + +define Build/nec-boot-header + $(eval flags=$(if $(1),$(word 1,$(1)),0x0002)) + $(eval addr=$(if $(word 2,$(1)),$(word 2,$(1)),80060000)) + $(eval databin=$(if $(word 3,$(1)),$(word 3,$(1)),$@)) + ( \ + flags=$$(printf "%04x%04x" $(flags) $$((~$(flags) & 0xffff))); \ + nec_fw_size=$$(printf '%08x' "$$(($$(stat -c%s $(databin)) + 0x18))"); \ + printf $$(echo "$${flags}$${nec_fw_size}0000001800000000$(addr)$(addr)" | \ + sed 's/../\\x&/g'); \ + cat $(databin); \ + ) > $(databin).new + mv $(databin).new $(databin) + ( \ + cksum=$$( \ + dd if=$(databin) ibs=4 skip=1 | od -A n -t u2 --endian=little | \ + tr -s ' ' '\n' | \ + awk '{s+=$$0}END{printf "%04x", 0xffff-(s%0x100000000)%0xffff}'); \ + printf "\x$${cksum:2:2}\x$${cksum:0:2}" | \ + dd of=$(databin) conv=notrunc bs=2 seek=6 count=1; \ + ) +endef + +define Build/nec-usbaterm-fw + ( \ + printf "VERSION: 9.99.99\nOEM1 VERSION: 9.9.99\n"; \ + printf "$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION)\n"; \ + ) | dd of=$@.copyblk bs=4 conv=sync + touch $@.endblk + $(call Build/nec-boot-header,0x0000 00000000 $@.copyblk) + $(call Build/nec-boot-header,0x0001 00000000 $@.endblk) + ( \ + printf "USB ATERMWL3050\x00"; \ + printf $$(echo "ffffffffffffffffffffffffffffffff" | sed 's/../\\x&/g'); \ + cat $@.copyblk $@ "$(KDIR)/loader-$(DEVICE_NAME).bin" $@.endblk; \ + ) > $@.new + printf "Binary Type$(1) File END \r\n" > $@.footer + ( \ + pad=$$((0x20 - $$(stat -c%s $@.footer))); \ + for i in $$(seq 1 $$pad); do printf "\xff"; done; \ + cat $@.footer; \ + ) >> $@.new + mv $@.new $@ + rm -f $@.copyblk $@.endblk $@.footer +endef + +define Build/remove-uimage-header + dd if=$@ of=$@.new iflag=skip_bytes skip=64 2>/dev/null + mv $@.new $@ +endef + +define Device/nec-netbsd-aterm + DEVICE_VENDOR := NEC + LOADER_TYPE := bin + KERNEL := kernel-bin | append-dtb | lzma | loader-kernel | uImage none + KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | loader-kernel | uImage none + ARTIFACTS := uboot.bin +ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),) + COMPILE := loader-$(1).bin + COMPILE/loader-$(1).bin := loader-okli-compile | pad-to 4 | nec-boot-header + ARTIFACTS += initramfs-factory.bin initramfs-necboot.bin + ARTIFACT/initramfs-factory.bin := append-image-stage initramfs-kernel.bin | \ + remove-uimage-header | pad-to 4 | nec-boot-header 0003 | \ + nec-usbaterm-fw $$$$(NEC_FW_TYPE) | check-size + ARTIFACT/initramfs-necboot.bin := append-image-stage initramfs-kernel.bin | \ + remove-uimage-header | pad-to 4 | nec-boot-header +endif + ARTIFACT/uboot.bin := nec-append-uboot | check-size 128k + DEVICE_PACKAGES := kmod-usb2 -uboot-envtools +endef diff --git a/target/linux/ath79/image/lzma-loader/src/board.c b/target/linux/ath79/image/lzma-loader/src/board.c index 13926e9b1e6548..65dcf6bede8fa3 100644 --- a/target/linux/ath79/image/lzma-loader/src/board.c +++ b/target/linux/ath79/image/lzma-loader/src/board.c @@ -207,9 +207,74 @@ static inline void ap5030dn_init(void) static inline void ap5030dn_init(void) { } #endif +#ifdef CONFIG_BOARD_NEC_WR8750N + +#define AR934X_PLL_SWITCH_CLK_CTRL_REG 0x24 +#define AR934X_PLL_SWITCH_CLK_CTRL_SWITCHCLK_SEL BIT(0) + +static inline void nec_aterm_init(void) +{ + unsigned int reg, val; + + printf("NEC Aterm series (AR9344)\n"); + + /* set REFCLK=40MHz to switch PLL */ + reg = KSEG1ADDR(AR71XX_PLL_BASE); + val = READREG(reg + AR934X_PLL_SWITCH_CLK_CTRL_REG); + val &= ~AR934X_PLL_SWITCH_CLK_CTRL_SWITCHCLK_SEL; + WRITEREG(reg + AR934X_PLL_SWITCH_CLK_CTRL_REG, val); + + reg = KSEG1ADDR(AR71XX_RESET_BASE); +#ifndef LOADADDR + /* + * This is for initramfs-factory image. + * When the system was reset by watchdog and started from the + * OEM bootloader with a dummy firmware (this loader), reset + * again by FULL_CHIP_RESET bit in the RESET register to + * load an actual OpenWrt initramfs image in TP (Test Program?) + * block in a factory image. + * On the stock firmware, TP block contains a POST function and + * sub commands of "tp" command. + * + * Behaviors of OEM bootloader: + * + * - reset by watchdog (ex.: rebooting on the stock firmware): + * called as "SOFT-RESET", boot a firmware without POST + * + * - reset by FULL_CHIP_RESET (or powering on): + * called as "HARD-RESET", run POST and boot a firmware + */ + printf("\n## booted with dummy firmware (lzma-loader), resetting... ##\n"); + val = READREG(reg + AR934X_RESET_REG_RESET_MODULE); + val |= AR934X_RESET_FULL_CHIP; + WRITEREG(reg + AR934X_RESET_REG_RESET_MODULE, val); +#endif + /* + * set maximum watchdog count to avoid reset while + * booting from stock bootloader + */ + WRITEREG(reg + AR71XX_RESET_REG_WDOG, 0xffffffff); + + /* + * deassert some RESET bits that are not handled + * by drivers and mainline U-Boot + * + * - ETH_SWITCH(_ANALOG): eth0 + * - RTC : wmac + */ + val = READREG(reg + AR934X_RESET_REG_RESET_MODULE); + val &= ~(AR934X_RESET_ETH_SWITCH | AR934X_RESET_ETH_SWITCH_ANALOG | + AR934X_RESET_RTC); + WRITEREG(reg + AR934X_RESET_REG_RESET_MODULE, val); +} +#else +static inline void nec_aterm_init(void) {} +#endif + void board_init(void) { tlwr1043nd_init(); mr18_init(); ap5030dn_init(); + nec_aterm_init(); } diff --git a/target/linux/ath79/image/tiny.mk b/target/linux/ath79/image/tiny.mk index 955d0fbff22c0b..09d00ddd6db74e 100644 --- a/target/linux/ath79/image/tiny.mk +++ b/target/linux/ath79/image/tiny.mk @@ -1,4 +1,5 @@ include ./common-buffalo.mk +include ./common-nec.mk include ./common-senao.mk define Device/buffalo_whr-g301n @@ -120,6 +121,16 @@ define Device/engenius_enh202-v1 endef TARGET_DEVICES += engenius_enh202-v1 +define Device/nec_wr8750n + $(Device/nec-netbsd-aterm) + SOC := ar9344 + DEVICE_MODEL := Aterm WR8750N + BLOCKSIZE := 4k + IMAGE_SIZE := 7936k + NEC_FW_TYPE := H033a +endef +TARGET_DEVICES += nec_wr8750n + define Device/pqi_air-pen SOC := ar9330 DEVICE_VENDOR := PQI diff --git a/target/linux/ath79/tiny/base-files/etc/board.d/02_network b/target/linux/ath79/tiny/base-files/etc/board.d/02_network index fa2ea3aa6fffa4..6f0f988309c9e2 100644 --- a/target/linux/ath79/tiny/base-files/etc/board.d/02_network +++ b/target/linux/ath79/tiny/base-files/etc/board.d/02_network @@ -69,6 +69,11 @@ ath79_setup_interfaces() ucidef_add_switch "switch0" \ "0@eth1" "4:lan:1" ;; + nec,wr8750n|\ + tplink,tl-wr941n-v7-cn) + ucidef_add_switch "switch0" \ + "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan" + ;; tplink,tl-mr3220-v1|\ tplink,tl-mr3420-v1|\ tplink,tl-mr3420-v3|\ @@ -105,10 +110,6 @@ ath79_setup_interfaces() tplink,tl-wr941-v2) ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan" ;; - tplink,tl-wr941n-v7-cn) - ucidef_add_switch "switch0" \ - "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan" - ;; ubnt,airrouter) ucidef_set_interface_wan "eth1" ucidef_add_switch "switch0" \ @@ -152,6 +153,10 @@ ath79_setup_macs() ubnt,picostation-m) label_mac=$(cat /sys/class/ieee80211/phy0/macaddress) ;; + nec,wr8750n) + wan_mac=$(mtd_get_mac_binary config 0xc) + label_mac=$wan_mac + ;; tplink,tl-wr941-v2|\ tplink,tl-wr941n-v7-cn) base_mac=$(mtd_get_mac_binary u-boot 0x1fc00) diff --git a/target/linux/ath79/tiny/base-files/lib/upgrade/platform.sh b/target/linux/ath79/tiny/base-files/lib/upgrade/platform.sh index eb8441c6d267fa..6b0ffd4046ad7a 100644 --- a/target/linux/ath79/tiny/base-files/lib/upgrade/platform.sh +++ b/target/linux/ath79/tiny/base-files/lib/upgrade/platform.sh @@ -9,7 +9,21 @@ RAMFS_COPY_BIN='fw_setenv' RAMFS_COPY_DATA='/etc/fw_env.config' platform_check_image() { - return 0 + local board=$(board_name) + + case "$board" in + nec,wr8750n) + local uboot_mtd=$(find_mtd_part "bootloader") + + # check "U-Boot ." string in the "bootloader" partition + if ! grep -q "U-Boot [0-9]\{4\}\.[0-9]\{2\}" $uboot_mtd; then + v "The bootloader doesn't seem to be replaced to U-Boot!" + return 1 + fi + ;; + *) + return 0 + esac } platform_do_upgrade() {