From 1eeca33c8df1caa40aeb010891f67e81084817d8 Mon Sep 17 00:00:00 2001
From: "Manu.WTF" <43337106+Dark4MD@users.noreply.github.com>
Date: Wed, 15 Sep 2021 00:44:34 +0200
Subject: [PATCH] ramips-mt7621: add support for Ubiquiti UniFi 6 Lite (#2310)

Hardware
--------
MediaTek MT7621AT
256M DDR3
32M SPI-NOR
MediaTek MT7603 2T2R 802.11n 2.4GHz
MediaTek MT7915 2T2R 802.11ax 5GHz

Not Working
-----------
 - Bluetooth (connected to UART3)

UART
----

UART is located in the lower left corner of the board. Pinout is

0 - 3V3 (don't connect)
1 - RX
2 - TX
3 - GND

Console is 115200 8N1.

Boot
----

1. Connect to the serial console and connect power.

2. Double-press ESC when prompted

3. Set the fdt address

   $ fdt addr $(fdtcontroladdr)

4. Remove the signature node from the control FDT

   $ fdt rm /signature

5. Transfer and boot the OpenWrt initramfs image to the device.
   Make sure to name the file C0A80114.img and have it reachable at
   192.168.1.1/24

   $ tftpboot; bootm

Installation
------------

1. Connect to the booted device at 192.168.1.20 using username/password
   "ubnt".

2. Update the bootloader environment.

   $ fw_setenv devmode TRUE
   $ fw_setenv boot_openwrt "fdt addr \$(fdtcontroladdr);
     fdt rm /signature; bootubnt"
   $ fw_setenv bootcmd "run boot_openwrt"

3. Transfer the OpenWrt sysupgrade image to the device using SCP.

4. Check the mtd partition number for bs / kernel0 / kernel1

   $ cat /proc/mtd

5. Set the bootselect flag to boot from kernel0

   $ dd if=/dev/zero bs=1 count=1 of=/dev/mtdblock4

6. Write the OpenWrt sysupgrade image to both kernel0 as well as kernel1

   $ dd if=openwrt.bin of=/dev/mtdblock6
   $ dd if=openwrt.bin of=/dev/mtdblock7

7. Reboot the device. It should boot into OpenWrt.
---
 docs/user/supported_devices.rst | 1 +
 targets/ramips-mt7621           | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/docs/user/supported_devices.rst b/docs/user/supported_devices.rst
index f7573dd78..47447c310 100644
--- a/docs/user/supported_devices.rst
+++ b/docs/user/supported_devices.rst
@@ -223,6 +223,7 @@ ramips-mt7621
 
   - EdgeRouter X
   - EdgeRouter X-SFP
+  - UniFi 6 Lite
 
 * ZBT
 
diff --git a/targets/ramips-mt7621 b/targets/ramips-mt7621
index c8a42d0e5..531a81aed 100644
--- a/targets/ramips-mt7621
+++ b/targets/ramips-mt7621
@@ -29,6 +29,13 @@ device('netgear-wndr3700-v5', 'netgear_wndr3700-v5', {
 })
 
 
+-- Ubiquiti
+
+device('ubiquiti-unifi-6-lite', 'ubnt_unifi-6-lite', {
+	factory = false,
+})
+
+
 -- Xiaomi
 
 device('xiaomi-mi-router-4a-gigabit-edition', 'xiaomi_mi-router-4a-gigabit', {
-- 
GitLab