From 0f8cdc28af2619d412b4a8f594b77ac6e7d27edd Mon Sep 17 00:00:00 2001
From: =?utf8?q?Petr=20=C5=A0tetiar?= <ynezz@true.cz>
Date: Sat, 17 Nov 2018 08:01:55 +0100
Subject: [PATCH] ar71xx: Add support for Ubiquity Bullet M (XW)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

CPU: AR9342 SoC
RAM:     64 MB DDR2
Flash:    8 MB NOR SPI
Ports:  100 MBit (24V PoE in)
WLAN: 2.4/5 GHz
UART:     1 UART on PCB marked as J1 with 115200 8N1 config
LEDs:       Power, Ethernet, 4x RSSI LEDs (orange, red, 2x green)
Buttons:    Reset

UART connection details

  .---------------------------------.
  |                                 |
[ETH]          J1                 [ANT]
  |    o VCC o RX o TX o GND        |
  `---------------------------------'

Flashing instructions using recovery method over TFTP

 1. Unplug the ethernet cable from the router.
 2. Using paper clip press and hold the router's reset button. Make sure
    you can feel it depressed by the paper clip. Do not release the button
    until step 4.
 3. While keeping the reset button pressed in, plug the ethernet cable
    back into the AP. Keep the reset button depressed until you see the
    device's LEDs flashing in upgrade mode (alternating LED1/LED3 and
    LED2/LED4), this may take up to 25 seconds.
 4. You may release the reset button, now the device should be in TFTP
    transfer mode.
 5. Set a static IP on your Computer's NIC. A static IP of 192.168.1.25/24
    should work.
 6. Plug the PoE injector's LAN cable directly to your computer.
 7. Start tftp client and issue following commands:
     tftp> binary
     tftp> connect 192.168.1.20
     tftp> put openwrt-ar71xx-generic-ubnt-bullet-m-xw-squashfs-factory.bin

Tested only on Bullet M2HP.

Signed-off-by: Petr Å tetiar <ynezz@true.cz>
---
 target/linux/ar71xx/base-files/etc/board.d/01_leds       | 1 +
 target/linux/ar71xx/base-files/etc/board.d/02_network    | 1 +
 target/linux/ar71xx/base-files/etc/diag.sh               | 1 +
 target/linux/ar71xx/base-files/lib/ar71xx.sh             | 3 +++
 target/linux/ar71xx/base-files/lib/upgrade/platform.sh   | 1 +
 target/linux/ar71xx/files/arch/mips/ath79/mach-ubnt-xm.c | 3 +++
 target/linux/ar71xx/files/arch/mips/ath79/machtypes.h    | 1 +
 target/linux/ar71xx/image/generic-ubnt.mk                | 7 +++++++
 8 files changed, 18 insertions(+)

diff --git a/target/linux/ar71xx/base-files/etc/board.d/01_leds b/target/linux/ar71xx/base-files/etc/board.d/01_leds
index 79f452d8cf..41dd8c52ea 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/01_leds
+++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds
@@ -179,6 +179,7 @@ bsb)
 	ucidef_set_led_default "sys" "SYS" "$board:red:sys" "1"
 	;;
 bullet-m|\
+bullet-m-xw|\
 loco-m-xw|\
 nanostation-m|\
 nanostation-m-xw|\
diff --git a/target/linux/ar71xx/base-files/etc/board.d/02_network b/target/linux/ar71xx/base-files/etc/board.d/02_network
index a7b97bb3dd..8e5ff101d6 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/02_network
+++ b/target/linux/ar71xx/base-files/etc/board.d/02_network
@@ -68,6 +68,7 @@ ar71xx_setup_interfaces()
 	ap91-5g|\
 	aw-nr580|\
 	bullet-m|\
+	bullet-m-xw|\
 	c-55|\
 	cap324|\
 	cap4200ag|\
diff --git a/target/linux/ar71xx/base-files/etc/diag.sh b/target/linux/ar71xx/base-files/etc/diag.sh
index 55654263af..558f338cd6 100644
--- a/target/linux/ar71xx/base-files/etc/diag.sh
+++ b/target/linux/ar71xx/base-files/etc/diag.sh
@@ -129,6 +129,7 @@ get_status_led() {
 		status_led="$board:red:sys"
 		;;
 	bullet-m|\
+	bullet-m-xw|\
 	loco-m-xw|\
 	nano-m|\
 	nanostation-m|\
diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index 56a4fab80c..990683a55b 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -530,6 +530,9 @@ ar71xx_board_detect() {
 		name="bullet-m"
 		ubnt_xm_board_detect
 		;;
+	*"Bullet M XW")
+		name="bullet-m-xw"
+		;;
 	*"BXU2000n-2 rev. A1")
 		name="bxu2000n-2-a1"
 		;;
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index 7fc3d4e3b3..81735017e5 100755
--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
@@ -218,6 +218,7 @@ platform_check_image() {
 	archer-c7-v4|\
 	archer-c7-v5|\
 	bullet-m|\
+	bullet-m-xw|\
 	c-55|\
 	carambola2|\
 	cf-e316n-v2|\
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-ubnt-xm.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-ubnt-xm.c
index ba79537b37..6ceb91efff 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/mach-ubnt-xm.c
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-ubnt-xm.c
@@ -656,6 +656,9 @@ MIPS_MACHINE(ATH79_MACH_UBNT_LOCO_M_XW, "UBNT-LOCO-XW", "Ubiquiti Loco M XW",
 MIPS_MACHINE(ATH79_MACH_UBNT_ROCKET_M_XW, "UBNT-RM-XW", "Ubiquiti Rocket M XW",
 	     ubnt_rocket_m_xw_setup);
 
+MIPS_MACHINE(ATH79_MACH_UBNT_BULLET_M_XW, "UBNT-BM-XW", "Ubiquiti Bullet M XW",
+	     ubnt_rocket_m_xw_setup);
+
 MIPS_MACHINE(ATH79_MACH_UBNT_ROCKET_M_TI, "UBNT-RM-TI", "Ubiquiti Rocket M TI",
 	     ubnt_rocket_m_ti_setup);
 
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
index fb832390c1..9722744a37 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
+++ b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
@@ -321,6 +321,7 @@ enum ath79_mach_type {
 	ATH79_MACH_UBNT_AIRGWP,			/* Ubiquiti AirGateway Pro */
 	ATH79_MACH_UBNT_AIRROUTER,		/* Ubiquiti AirRouter */
 	ATH79_MACH_UBNT_BULLET_M,		/* Ubiquiti Bullet M */
+	ATH79_MACH_UBNT_BULLET_M_XW,		/* Ubiquiti Bullet M XW */
 	ATH79_MACH_UBNT_LBE_M5,			/* Ubiquiti Litebeam M5 */
 	ATH79_MACH_UBNT_LOCO_M_XW,		/* Ubiquiti Loco M XW */
 	ATH79_MACH_UBNT_LSSR71,			/* Ubiquiti LS-SR71 */
diff --git a/target/linux/ar71xx/image/generic-ubnt.mk b/target/linux/ar71xx/image/generic-ubnt.mk
index 84471a5c50..5caad50b0a 100644
--- a/target/linux/ar71xx/image/generic-ubnt.mk
+++ b/target/linux/ar71xx/image/generic-ubnt.mk
@@ -188,6 +188,13 @@ define Device/ubnt-loco-m-xw
 endef
 TARGET_DEVICES += ubnt-loco-m-xw
 
+define Device/ubnt-bullet-m-xw
+  $(Device/ubnt-xw)
+  DEVICE_TITLE := Ubiquiti Bullet-M XW
+  BOARDNAME := UBNT-BM-XW
+endef
+TARGET_DEVICES += ubnt-bullet-m-xw
+
 define Device/ubnt-rocket-m-xw
   $(Device/ubnt-xw)
   DEVICE_TITLE := Ubiquiti Rocket M XW
-- 
2.30.2