openwrt/target/linux/ramips/patches-5.4
David Bauer ce61c36624 ramips: add support for Ubiquiti UniFi 6 Lite
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.

Below are the original installation instructions prior to the discovery
of "devmode=TRUE". They are not required for installation and are
documentation only.

The bootloader employs signature verification on the FIT image
configurations. This way, booting unauthorized image without patching
the bootloader is not possible. Manually configuring the bootcmd in the
U-Boot envronment won't work, as this is restored to the default value
if modified.

The bootloader is made up of three different parts.

1. The SPL performing early board initialization and providing a XModem
   recovery in case the PBL is missing

2. The PBL being the primary U-Boot application and containing the
   control FDT. It is LZMA packed with a uImage header.

3. A Ubiquiti standalone U-Boot application providing the main boot
   routine as well as their recovery mechanism.

In a perfect world, we would only replace the PBL, as the SPL does not
perform checks on the PBLs integrity. However, as the PBL is in the same
eraseblock as the SPL, we need to at least rewrite both.

The bootloader will only verify integrity in case it has a "signature"
node in it's control device-tree. Renaming the signature node to
something else will prevent this from happening.

Warning: These instructions are based on the firmware intially
shipped with the device and potentially brick your device in a way it
can only be recovered using a SPI flasher.

Only (!) proceed if you understand this!

1. Extract the bootloader from the U-Boot partition using the OpenWrt
   initramfs image.

2. Split the bootloader into it's 3 components:

   $ dd if=bootloader.bin of=spl.bin bs=1 skip=0 count=45056
   $ dd if=bootloader.bin of=pbl.uimage bs=1 skip=45056 count=143360
   $ dd if=bootloader.bin of=ubnt.uimage bs=1 skip=188416

3. Strip the uImage header from the PBL

   $ dd if=pbl.uimage of=pbl.lzma bs=64 skip=1

4. Decompress the PBL

   $ lzma -d pbl.lzma --single-stream

   The decompressed PBL sha256sum should be
   d8b406c65240d260cf15be5f97f40c1d6d1b6e61ec3abed37bb841c90fcc1235

5. Open the decompressed PBL using your favorite hexeditor. Locate the
   control FDT at offset 0x4CED0 (0xD00DFEED). At offset 0x4D5BC, the
   label for the signature node is located. Rename the "signature"
   string at this offset to "signaturr".

   The patched PBL sha256sum should be
   d028e374cdb40ba44b6e3cef2e4e8a8c16a3b85eb15d9544d24fdd10eed64c97

6. Compress the patched PBL

   $ lzma -z pbl --lzma1=dict=67108864

   The resulting pbl.lzma file should have the sha256sum
   7ae6118928fa0d0b3fe4ff81abd80ecfd9ba2944cb0f0a462b6ae65913088b42

7. Create the PBL uimage

   $ SOURCE_DATE_EPOCH=1607909492 mkimage -A mips -O u-boot -C lzma
     -n "U-Boot 2018.03 [UniFi,v1.1.40.71]" -a 84000000 -e 84000000
     -T firmware -d pbl.lzma patched_pbl.uimage

   The resulting patched_pbl.uimage should have the sha256sum
   b90d7fa2dcc6814180d3943530d8d6b0d6a03636113c94e99af34f196d3cf2ce

8. Reassemble the complete bootloader

   $ dd if=patched_pbl.uimage of=aligned_pbl.uimage bs=143360 count=1
     conv=sync
   $ cat spl.bin > patched_uboot.bin
   $ cat aligned_pbl.uimage >> patched_uboot.bin
   $ cat ubnt.uimage >> patched_uboot.bin

   The resulting patched_uboot.bin should have the sha256sum
   3e1186f33b88a525687285c2a8b22e8786787b31d4648b8eee66c672222aa76b

9. Transfer your patched bootloader to the device. Also install the
   kmod-mtd-rw package using opkg and load it.

   $ insmod mtd-rw.ko i_want_a_brick=1

   Write the patched bootloader to mtd0

   $ mtd write patched_uboot.bin u-boot

10. Erase the kernel1 partition, as the bootloader might otherwise
    decide to boot from there.

    $ mtd erase kernel1

11. Transfer the OpenWrt sysupgrade image to the device and install
    using sysupgrade.

FIT configurations
------------------

In the future, the MT7621 UniFi6 family can be supported by a single
OpenWrt image.

config@1: U6 Lite
config@2: U6 IW
config@3: U6 Mesh
config@4: U6 Extender
config@5: U6 LR-EA (Early Access - GA is MT7622)

Signed-off-by: David Bauer <mail@david-bauer.net>
Signed-off-by: maurerr <mariusd84@gmail.com>
2021-09-01 08:07:26 +00:00
..
100-mt7621-core-detect-hack.patch
101-mt7621-timer.patch
102-mt7621-fix-cpu-clk-add-clkdev.patch
105-mt7621-memory-detect.patch
110-mt7621-perfctr-fix.patch
111-gpio-mmio-introduce-BGPIOF_NO_SET_ON_INPUT.patch ramips: mt7621: backport GPIO driver fix 2020-04-04 14:14:43 +08:00
112-gpio-mt7621-add-BGPIOF_NO_SET_ON_INPUT-flag.patch ramips: mt7621: backport GPIO driver fix 2020-04-04 14:14:43 +08:00
200-add-ralink-eth.patch ramips: move and rename out-of-tree mtk eth driver 2020-04-12 22:27:17 +08:00
300-mt7620-export-chip-version-and-pkg.patch
301-MIPS-ralink-mt7621-introduce-soc_device-initializati.patch ramips: mt7621: introduce 'soc_device' initialization 2020-04-04 14:56:14 +08:00
302-spi-nor-add-gd25q512.patch kernel: bump 5.4 to 5.4.83 2021-09-01 08:07:21 +00:00
401-net-ethernet-mediatek-support-net-labels.patch kernel: bump 5.4 to 5.4.85 2021-09-01 08:07:23 +00:00
990-NET-no-auto-carrier-off-support.patch ramips: fix whitespace in 990_NET-no-auto-carrier-support.patch 2020-04-13 11:49:16 +08:00
991-at803x.patch kernel: bump 5.4 to 5.4.79 2021-09-01 08:07:13 +00:00
999-fix-pci-init-mt7620.patch
0001-MIPS-cmdline-Clean-up-boot_command_line-initializati.patch ramips: add support for Ubiquiti UniFi 6 Lite 2021-09-01 08:07:26 +00:00
0002-MIPS-Always-define-builtin_cmdline.patch ramips: add support for Ubiquiti UniFi 6 Lite 2021-09-01 08:07:26 +00:00
0003-MIPS-Fix-memory-reservation-in-bootmem_init-for-cert.patch
0005-MIPS-use-set_mode-to-enable-disable-the-cevt-r4k-irq.patch
0006-MIPS-ralink-add-cpu-frequency-scaling.patch
0007-MIPS-ralink-copy-the-commandline-from-the-devicetree.patch
0010-MIPS-add-bootargs-override-property.patch ramips: add support for Ubiquiti UniFi 6 Lite 2021-09-01 08:07:26 +00:00
0013-owrt-hack-fix-mt7688-cache-issue.patch kernel: bump 5.4 to 5.4.48 2020-06-22 12:51:22 +02:00
0015-arch-mips-do-not-select-illegal-access-driver-by-def.patch
0024-GPIO-add-named-gpio-exports.patch
0026-DT-Add-documentation-for-gpio-ralink.patch ramips: replace pinctrl property names 2020-04-12 22:29:17 +08:00
0027-GPIO-MIPS-ralink-add-gpio-driver-for-ralink-SoC.patch ramips: replace pinctrl property names 2020-04-12 22:29:17 +08:00
0029-gpio-ralink-Add-support-for-GPIO-as-interrupt-contro.patch
0031-uvc-add-iPassion-iP2970-support.patch
0037-mtd-cfi-cmdset-0002-force-word-write.patch
0041-DT-Add-documentation-for-spi-rt2880.patch
0042-SPI-ralink-add-Ralink-SoC-spi-driver.patch
0044-i2c-MIPS-adds-ralink-I2C-driver.patch
0046-mmc-MIPS-ralink-add-sdhci-for-mt7620a-SoC.patch
0048-asoc-add-mt7620-support.patch
0051-serial-add-ugly-custom-baud-rate-hack.patch
0052-pwm-add-mediatek-support.patch
0069-awake-rt305x-dwc2-controller.patch kernel: bump 5.4 to 5.4.58 2021-09-01 08:06:51 +00:00
0070-weak_reordering.patch
0098-disable_cm.patch
0100-staging-mt7621-pci-simplify-mt7621_pcie_init_virtual.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0101-staging-mt7621-pci-enable-clock-bit-for-each-port.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0102-staging-mt7621-pci-use-gpios-for-properly-reset.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0103-staging-mt7621-pci-change-value-for-PERST_DELAY_MS.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0104-staging-mt7621-pci-release-gpios-after-pci-initializ.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0105-staging-mt7621-pci-delete-no-more-needed-mt7621_rese.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0106-staging-mt7621-pci-phy-add-mt7621_phy_rmw-to-simplif.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0107-staging-mt7621-pci-fix-io-space-and-properly-set-res.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0108-staging-mt7621-pci-fix-register-to-set-up-virtual-br.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0109-staging-mt7621-pci-don-t-return-if-get-gpio-fails.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0110-staging-mt7621-pci-phy-avoid-to-create-to-different-.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0111-staging-mt7621-pci-use-only-two-phys-from-device-tre.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0112-staging-mt7621-pci-change-variable-to-print-for-slot.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0113-staging-mt7621-pci-be-sure-gpio-descriptor-is-null-o.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0114-staging-mt7621-pci-avoid-to-poweroff-the-phy-for-slo.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0115-staging-mt7621-pci-delete-release-gpios-related-code.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0116-staging-mt7621-pci-use-builtin_platform_driver.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0117-staging-mt7621-pci-phy-use-builtin_platform_driver.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0118-staging-mt7621-pci-phy-re-do-xtal_mode-detection.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0119-staging-mt7621-pci-avoid-to-set-iomem_resource-addre.patch ramips: mt7621: backport PCIe driver fixes from staging-test 2020-04-04 14:14:43 +08:00
0120-staging-mt7621-pci-properly-power-off-dual-ported-pc.patch ramips: mt7621: backport more pcie driver fixes 2020-04-18 13:06:48 +08:00
0121-staging-mt7621-pci-fix-PCIe-interrupt-mapping.patch ramips: mt7621: backport more pcie driver fixes 2020-04-18 13:06:48 +08:00
0122-mips-ralink-enable-zboot-support.patch ramips: add linux zboot support 2021-09-01 08:07:07 +00:00
0200-linkit_bootstrap.patch
0300-mtd-rawnand-add-driver-support-for-MT7621-nand-flash.patch ramips: fix kernel oops in mt7621_nfc_write_page_hwecc 2021-09-01 08:07:09 +00:00
0301-dt-bindings-add-documentation-for-mt7621-nand-driver.patch ramips: mt7621: add new NAND driver 2020-04-04 14:56:14 +08:00