From 108df3eabbb4dd93ff3c616c9455d69daaa98b49 Mon Sep 17 00:00:00 2001
From: Renaud Lepage <root@cybikbase.com>
Date: Sun, 10 May 2020 15:10:20 -0700
Subject: ath79: add support for the Netgear WNDRMAC v1

The Netgear WNDRMAC v1 is a hardware variant of the Netgear WNDR3700 v2

Specifications
==============
* SoC: Atheros AR7161
* RAM: 64mb
* Flash on board: 16mb
* WiFi: Atheros AR9220 (a/n), Atheros AR9223 (b/g/n)
* Ethernet: RealTek RTL8366SR (1xWAN, 4xLAN, Gigabit)
* Power: 12 VDC, 2.5 A
* Full specs on [openwrt.org](https://openwrt.org/toh/hwdata/netgear/netgear_wndrmac_v1)

Flash Instructions
==================
It is possible to use the OEM Upgrade page to install the `factory`
variant of the firmware.

After the initial upgrade, you will need to telnet into the router
(default IP 192.168.1.1) to install anything. You may install LuCI
this way. At this point, you will have a web interface to configure
OpenWRT on the WNDRMAC v1.

Please use the `sysupgrade` variant for subsequent flashes.

Recovery Instructions
=====================
A TFTP-based recovery flash is possible if the need arises. Please refer
to the WNDR3700 page on openwrt.org for details.

https://openwrt.org/toh/netgear/wndr3700#troubleshooting_and_recovery

Signed-off-by: Renaud Lepage <root@cybikbase.com>
[update DTSI include name]
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
---
 package/boot/uboot-envtools/files/ath79            |  3 +-
 .../linux/ath79/dts/ar7161_netgear_wndrmac-v1.dts  | 34 ++++++++++++++++++++++
 .../generic/base-files/etc/board.d/02_network      |  2 ++
 .../etc/hotplug.d/firmware/10-ath9k-eeprom         |  2 ++
 target/linux/ath79/image/generic.mk                | 12 ++++++++
 5 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 target/linux/ath79/dts/ar7161_netgear_wndrmac-v1.dts

diff --git a/package/boot/uboot-envtools/files/ath79 b/package/boot/uboot-envtools/files/ath79
index 928a46ca8e..3754b521a4 100644
--- a/package/boot/uboot-envtools/files/ath79
+++ b/package/boot/uboot-envtools/files/ath79
@@ -52,7 +52,8 @@ glinet,gl-ar150)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x8000" "0x10000"
 	;;
 netgear,wndr3700|\
-netgear,wndr3700-v2)
+netgear,wndr3700-v2|\
+netgear,wndrmac-v1)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x10000"
 	;;
 netgear,wndr3700-v4|\
diff --git a/target/linux/ath79/dts/ar7161_netgear_wndrmac-v1.dts b/target/linux/ath79/dts/ar7161_netgear_wndrmac-v1.dts
new file mode 100644
index 0000000000..d2dbcaacd0
--- /dev/null
+++ b/target/linux/ath79/dts/ar7161_netgear_wndrmac-v1.dts
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+/dts-v1/;
+
+#include "ar7161_netgear_wndr.dtsi"
+
+/ {
+	compatible = "netgear,wndrmac-v1", "qca,ar7161";
+	model = "Netgear WNDRMAC v1";
+};
+
+&partitions {
+	partition@0 {
+		label = "u-boot";
+		reg = <0x000000 0x050000>;
+		read-only;
+	};
+
+	partition@50000 {
+		label = "u-boot-env";
+		reg = <0x050000 0x020000>;
+	};
+
+	partition@70000 {
+		label = "firmware";
+		reg = <0x070000 0xf80000>;
+		compatible = "netgear,uimage";
+	};
+
+	art: partition@ff0000 {
+		label = "art";
+		reg = <0xff0000 0x010000>;
+		read-only;
+	};
+};
diff --git a/target/linux/ath79/generic/base-files/etc/board.d/02_network b/target/linux/ath79/generic/base-files/etc/board.d/02_network
index d7adf7e184..23a945aadc 100755
--- a/target/linux/ath79/generic/base-files/etc/board.d/02_network
+++ b/target/linux/ath79/generic/base-files/etc/board.d/02_network
@@ -205,6 +205,7 @@ ath79_setup_interfaces()
 	netgear,wndr3700-v2|\
 	netgear,wndr3800|\
 	netgear,wndr3800ch|\
+	netgear,wndrmac-v1|\
 	netgear,wndrmac-v2)
 		ucidef_set_interface_wan "eth1"
 		ucidef_add_switch "switch0" \
@@ -432,6 +433,7 @@ ath79_setup_macs()
 	netgear,wndr3700|\
 	netgear,wndr3700-v2|\
 	netgear,wndr3800|\
+	netgear,wndrmac-v1|\
 	netgear,wndrmac-v2)
 		lan_mac=$(macaddr_setbit_la "$(mtd_get_mac_binary art 0x0)")
 		;;
diff --git a/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
index c5fc02519e..fa36aab4fe 100644
--- a/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
+++ b/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
@@ -128,6 +128,7 @@ case "$FIRMWARE" in
 	netgear,wndr3700-v2|\
 	netgear,wndr3800|\
 	netgear,wndr3800ch|\
+	netgear,wndrmac-v1|\
 	netgear,wndrmac-v2)
 		caldata_extract "art" 0x1000 0xeb8
 		;;
@@ -147,6 +148,7 @@ case "$FIRMWARE" in
 	netgear,wndr3700-v2|\
 	netgear,wndr3800|\
 	netgear,wndr3800ch|\
+	netgear,wndrmac-v1|\
 	netgear,wndrmac-v2)
 		caldata_extract "art" 0x5000 0xeb8
 		;;
diff --git a/target/linux/ath79/image/generic.mk b/target/linux/ath79/image/generic.mk
index c66f0beae1..05b769b9c3 100644
--- a/target/linux/ath79/image/generic.mk
+++ b/target/linux/ath79/image/generic.mk
@@ -932,6 +932,18 @@ define Device/netgear_wndr3800ch
 endef
 TARGET_DEVICES += netgear_wndr3800ch
 
+define Device/netgear_wndrmac-v1
+  $(Device/netgear_wndr3x00)
+  DEVICE_MODEL := WNDRMAC
+  DEVICE_VARIANT := v1
+  NETGEAR_KERNEL_MAGIC := 0x33373031
+  NETGEAR_BOARD_ID := WNDRMAC
+  NETGEAR_HW_ID := 29763654+16+64
+  IMAGE_SIZE := 15872k
+  SUPPORTED_DEVICES += wndr3700
+endef
+TARGET_DEVICES += netgear_wndrmac-v1
+
 define Device/netgear_wndrmac-v2
   $(Device/netgear_wndr3x00)
   DEVICE_MODEL := WNDRMAC
-- 
cgit v1.2.3