[PATCH] octeon: add support for Ubiquiti UniFi Security Gateway

openwrt at wireloss.net openwrt at wireloss.net
Sat May 28 12:34:48 PDT 2022


From: Clemens Hopfer <openwrt at wireloss.net>

Ubiquiti UniFi Security Gateway (USG) is largely identical to
the EdgeRouter Lite (ERLite-3) apart from a different board ID
and two dome leds.

Device data (from WikiDev):
  CPU: Cavium Octeon Plus CN5020 @500MHz 2-cores
  Ethernet: 3x Atheros AR8035-A GbE PHY's
  Flash: On-board 4MB Flash
  Storage: Internal 3.8GB USB Flash (Kingston ID) drive
    w/ 1.5GB free for use occupies single internal USB port.
  Serial: 1x RJ45 port on front panel. 115200, 8N1
  Buttons: 1x Reset

Flash instructions are identical to EdgeRouter Lite.

Signed-off-by: Clemens Hopfer <openwrt at wireloss.net>
---
 .../octeon/base-files/etc/board.d/01_network  |  3 +-
 .../octeon/base-files/lib/preinit/01_sysinfo  |  4 +
 .../base-files/lib/preinit/79_move_config     |  3 +-
 .../octeon/base-files/lib/upgrade/platform.sh |  9 +-
 .../dts/cavium-octeon/cn5020_ubnt_usg.dts     | 97 +++++++++++++++++++
 target/linux/octeon/image/Makefile            | 10 ++
 .../patches-5.10/150-ubnt_usg_support.patch   | 46 +++++++++
 .../patches-5.15/150-ubnt_usg_support.patch   | 46 +++++++++
 8 files changed, 213 insertions(+), 5 deletions(-)
 create mode 100644 target/linux/octeon/files/arch/mips/boot/dts/cavium-octeon/cn5020_ubnt_usg.dts
 create mode 100644 target/linux/octeon/patches-5.10/150-ubnt_usg_support.patch
 create mode 100644 target/linux/octeon/patches-5.15/150-ubnt_usg_support.patch

diff --git a/target/linux/octeon/base-files/etc/board.d/01_network b/target/linux/octeon/base-files/etc/board.d/01_network
index 194faeaad9..906e838a6f 100644
--- a/target/linux/octeon/base-files/etc/board.d/01_network
+++ b/target/linux/octeon/base-files/etc/board.d/01_network
@@ -7,7 +7,8 @@
 board_config_update
 
 case "$(board_name)" in
-itus,shield-router)
+itus,shield-router|\
+ubnt,usg)
 	ucidef_set_interfaces_lan_wan "eth1 eth2" "eth0"
 	;;
 ubnt,edgerouter-4)
diff --git a/target/linux/octeon/base-files/lib/preinit/01_sysinfo b/target/linux/octeon/base-files/lib/preinit/01_sysinfo
index d66618b0cf..5ea65d3042 100644
--- a/target/linux/octeon/base-files/lib/preinit/01_sysinfo
+++ b/target/linux/octeon/base-files/lib/preinit/01_sysinfo
@@ -22,6 +22,10 @@ do_sysinfo_octeon() {
 		return 0
 		;;
 
+	"UBNT_USG"*)
+		name="ubnt,usg"
+		;;
+
 	"ITUS_SHIELD"*)
 		name="itus,shield-router"
 		;;
diff --git a/target/linux/octeon/base-files/lib/preinit/79_move_config b/target/linux/octeon/base-files/lib/preinit/79_move_config
index ae155a3c5c..01491500a0 100644
--- a/target/linux/octeon/base-files/lib/preinit/79_move_config
+++ b/target/linux/octeon/base-files/lib/preinit/79_move_config
@@ -15,7 +15,8 @@ octeon_move_config() {
 	. /lib/functions.sh
 
 	case "$(board_name)" in
-		erlite)
+		erlite|\
+		ubnt,usg)
 			move_config "/dev/sda1"
 			;;
 		itus,shield-router)
diff --git a/target/linux/octeon/base-files/lib/upgrade/platform.sh b/target/linux/octeon/base-files/lib/upgrade/platform.sh
index 84533d642a..14b3eefe7e 100755
--- a/target/linux/octeon/base-files/lib/upgrade/platform.sh
+++ b/target/linux/octeon/base-files/lib/upgrade/platform.sh
@@ -27,7 +27,8 @@ platform_copy_config_helper() {
 
 platform_copy_config() {
 	case "$(board_name)" in
-	erlite)
+	erlite|\
+	ubnt,usg)
 		platform_copy_config_helper /dev/sda1
 		;;
 	itus,shield-router)
@@ -91,7 +92,8 @@ platform_do_upgrade() {
 	ubnt,edgerouter-6p)
 		kernel=mmcblk0p1
 		;;
-	erlite)
+	erlite|\
+	ubnt,usg)
 		kernel=sda1
 		;;
 	itus,shield-router)
@@ -119,7 +121,8 @@ platform_check_image() {
 	erlite | \
 	itus,shield-router | \
 	ubnt,edgerouter-4 | \
-	ubnt,edgerouter-6p)
+	ubnt,edgerouter-6p | \
+	ubnt,usg)
 		local kernel_length=$(tar xf $tar_file $board_dir/kernel -O | wc -c 2> /dev/null)
 		local rootfs_length=$(tar xf $tar_file $board_dir/root -O | wc -c 2> /dev/null)
 		[ "$kernel_length" = 0 -o "$rootfs_length" = 0 ] && {
diff --git a/target/linux/octeon/files/arch/mips/boot/dts/cavium-octeon/cn5020_ubnt_usg.dts b/target/linux/octeon/files/arch/mips/boot/dts/cavium-octeon/cn5020_ubnt_usg.dts
new file mode 100644
index 0000000000..4a9c1a31c2
--- /dev/null
+++ b/target/linux/octeon/files/arch/mips/boot/dts/cavium-octeon/cn5020_ubnt_usg.dts
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Device tree source for Ubiquity UniFi Security Gateway.
+ *
+ * Written for EdgeRouter Lite by: Aaro Koskinen <aaro.koskinen at iki.fi>
+ * Adapted for USG by: Clemens Hopfer <openwrt at wireloss.net>
+ */
+
+/include/ "octeon_3xxx.dtsi"
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/input/input.h>
+
+/ {
+	compatible = "ubnt,usg";
+	model = "Ubiquiti UniFi Security Gateway";
+
+	soc at 0 {
+		smi0: mdio at 1180000001800 {
+			phy5: ethernet-phy at 5 {
+				reg = <5>;
+				compatible = "ethernet-phy-ieee802.3-c22";
+			};
+			phy6: ethernet-phy at 6 {
+				reg = <6>;
+				compatible = "ethernet-phy-ieee802.3-c22";
+			};
+			phy7: ethernet-phy at 7 {
+				reg = <7>;
+				compatible = "ethernet-phy-ieee802.3-c22";
+			};
+		};
+
+		pip: pip at 11800a0000000 {
+			interface at 0 {
+				ethernet at 0 {
+					phy-handle = <&phy7>;
+					rx-delay = <0>;
+					tx-delay = <0x10>;
+				};
+				ethernet at 1 {
+					phy-handle = <&phy6>;
+					rx-delay = <0>;
+					tx-delay = <0x10>;
+				};
+				ethernet at 2 {
+					phy-handle = <&phy5>;
+					rx-delay = <0>;
+					tx-delay = <0x10>;
+				};
+			};
+		};
+
+		uart0: serial at 1180000000800 {
+			clock-frequency = <500000000>;
+		};
+
+		usbn: usbn at 1180068000000 {
+			refclk-frequency = <12000000>;
+			refclk-type = "crystal";
+		};
+
+	};
+
+	leds {
+		compatible = "gpio-leds";
+
+		led_dome_white: dome_white {
+			label = "white:dome";
+			gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
+		};
+
+		led_dome_blue: dome_blue {
+			label = "blue:dome";
+			gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
+		};
+	};
+
+	keys {
+		compatible = "gpio-keys-polled";
+		poll-interval = <20>;
+
+		reset {
+			label = "reset";
+			linux,code = <KEY_RESTART>;
+			gpios = <&gpio 11 GPIO_ACTIVE_LOW>;
+			debounce-interval = <60>;
+		};
+	};
+
+	aliases {
+		pip = &pip;
+		led-boot = &led_dome_white;
+		led-failsafe = &led_dome_blue;
+		led-running = &led_dome_blue;
+		led-upgrade = &led_dome_blue;
+	};
+};
diff --git a/target/linux/octeon/image/Makefile b/target/linux/octeon/image/Makefile
index f77159e1f9..457461140e 100644
--- a/target/linux/octeon/image/Makefile
+++ b/target/linux/octeon/image/Makefile
@@ -82,4 +82,14 @@ define Device/ubnt_edgerouter-lite
 endef
 TARGET_DEVICES += ubnt_edgerouter-lite
 
+define Device/ubnt_unifi-usg
+  $(Device/ubnt_edgerouter-lite)
+  DEVICE_MODEL := UniFi Security Gateway
+  BOARD_NAME := ubnt,usg
+  DEVICE_PACKAGES += kmod-gpio-button-hotplug kmod-leds-gpio
+  DEVICE_DTS := cn5020_ubnt_usg
+  KERNEL += | append-dtb-to-elf
+endef
+TARGET_DEVICES += ubnt_unifi-usg
+
 $(eval $(call BuildImage))
diff --git a/target/linux/octeon/patches-5.10/150-ubnt_usg_support.patch b/target/linux/octeon/patches-5.10/150-ubnt_usg_support.patch
new file mode 100644
index 0000000000..721f657978
--- /dev/null
+++ b/target/linux/octeon/patches-5.10/150-ubnt_usg_support.patch
@@ -0,0 +1,46 @@
+--- a/arch/mips/include/asm/octeon/cvmx-bootinfo.h
++++ b/arch/mips/include/asm/octeon/cvmx-bootinfo.h
+@@ -296,6 +296,7 @@ enum cvmx_board_types_enum {
+ 	CVMX_BOARD_TYPE_CUST_PRIVATE_MIN = 20001,
+ 	CVMX_BOARD_TYPE_UBNT_E100 = 20002,
+ 	CVMX_BOARD_TYPE_UBNT_E200 = 20003,
++	CVMX_BOARD_TYPE_UBNT_USG = 20004,
+ 	CVMX_BOARD_TYPE_UBNT_E220 = 20005,
+ 	CVMX_BOARD_TYPE_ITUS_SHIELD = 20006,
+ 	CVMX_BOARD_TYPE_UBNT_E300 = 20300,
+@@ -399,6 +400,7 @@ static inline const char *cvmx_board_typ
+ 		    /* Customer private range */
+ 		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_CUST_PRIVATE_MIN)
+ 		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_UBNT_E100)
++		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_UBNT_USG)
+ 		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_UBNT_E200)
+ 		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_UBNT_E220)
+ 		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_ITUS_SHIELD)
+--- a/arch/mips/cavium-octeon/octeon-platform.c
++++ b/arch/mips/cavium-octeon/octeon-platform.c
+@@ -634,6 +634,7 @@ static void __init octeon_rx_tx_delay(in
+ 		}
+ 		break;
+ 	case CVMX_BOARD_TYPE_UBNT_E100:
++	case CVMX_BOARD_TYPE_UBNT_USG:
+ 		if (iface == 0 && port <= 2) {
+ 			_octeon_rx_tx_delay(eth, 0x0, 0x10);
+ 			return;
+--- a/arch/mips/cavium-octeon/executive/cvmx-helper-board.c
++++ b/arch/mips/cavium-octeon/executive/cvmx-helper-board.c
+@@ -170,6 +170,7 @@ int cvmx_helper_board_get_mii_address(in
+ 		else
+ 			return -1;
+ 	case CVMX_BOARD_TYPE_UBNT_E100:
++	case CVMX_BOARD_TYPE_UBNT_USG:
+ 		if (ipd_port >= 0 && ipd_port <= 2)
+ 			return 7 - ipd_port;
+ 		else
+@@ -337,6 +338,7 @@ enum cvmx_helper_board_usb_clock_types _
+ 	case CVMX_BOARD_TYPE_LANAI2_G:
+ 	case CVMX_BOARD_TYPE_NIC10E_66:
+ 	case CVMX_BOARD_TYPE_UBNT_E100:
++	case CVMX_BOARD_TYPE_UBNT_USG:
+ 		return USB_CLOCK_TYPE_CRYSTAL_12;
+ 	case CVMX_BOARD_TYPE_NIC10E:
+ 		return USB_CLOCK_TYPE_REF_12;
diff --git a/target/linux/octeon/patches-5.15/150-ubnt_usg_support.patch b/target/linux/octeon/patches-5.15/150-ubnt_usg_support.patch
new file mode 100644
index 0000000000..721f657978
--- /dev/null
+++ b/target/linux/octeon/patches-5.15/150-ubnt_usg_support.patch
@@ -0,0 +1,46 @@
+--- a/arch/mips/include/asm/octeon/cvmx-bootinfo.h
++++ b/arch/mips/include/asm/octeon/cvmx-bootinfo.h
+@@ -296,6 +296,7 @@ enum cvmx_board_types_enum {
+ 	CVMX_BOARD_TYPE_CUST_PRIVATE_MIN = 20001,
+ 	CVMX_BOARD_TYPE_UBNT_E100 = 20002,
+ 	CVMX_BOARD_TYPE_UBNT_E200 = 20003,
++	CVMX_BOARD_TYPE_UBNT_USG = 20004,
+ 	CVMX_BOARD_TYPE_UBNT_E220 = 20005,
+ 	CVMX_BOARD_TYPE_ITUS_SHIELD = 20006,
+ 	CVMX_BOARD_TYPE_UBNT_E300 = 20300,
+@@ -399,6 +400,7 @@ static inline const char *cvmx_board_typ
+ 		    /* Customer private range */
+ 		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_CUST_PRIVATE_MIN)
+ 		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_UBNT_E100)
++		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_UBNT_USG)
+ 		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_UBNT_E200)
+ 		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_UBNT_E220)
+ 		ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_ITUS_SHIELD)
+--- a/arch/mips/cavium-octeon/octeon-platform.c
++++ b/arch/mips/cavium-octeon/octeon-platform.c
+@@ -634,6 +634,7 @@ static void __init octeon_rx_tx_delay(in
+ 		}
+ 		break;
+ 	case CVMX_BOARD_TYPE_UBNT_E100:
++	case CVMX_BOARD_TYPE_UBNT_USG:
+ 		if (iface == 0 && port <= 2) {
+ 			_octeon_rx_tx_delay(eth, 0x0, 0x10);
+ 			return;
+--- a/arch/mips/cavium-octeon/executive/cvmx-helper-board.c
++++ b/arch/mips/cavium-octeon/executive/cvmx-helper-board.c
+@@ -170,6 +170,7 @@ int cvmx_helper_board_get_mii_address(in
+ 		else
+ 			return -1;
+ 	case CVMX_BOARD_TYPE_UBNT_E100:
++	case CVMX_BOARD_TYPE_UBNT_USG:
+ 		if (ipd_port >= 0 && ipd_port <= 2)
+ 			return 7 - ipd_port;
+ 		else
+@@ -337,6 +338,7 @@ enum cvmx_helper_board_usb_clock_types _
+ 	case CVMX_BOARD_TYPE_LANAI2_G:
+ 	case CVMX_BOARD_TYPE_NIC10E_66:
+ 	case CVMX_BOARD_TYPE_UBNT_E100:
++	case CVMX_BOARD_TYPE_UBNT_USG:
+ 		return USB_CLOCK_TYPE_CRYSTAL_12;
+ 	case CVMX_BOARD_TYPE_NIC10E:
+ 		return USB_CLOCK_TYPE_REF_12;
-- 
2.35.1




More information about the openwrt-devel mailing list