6c35e07870279661374e88982468ed3b2fae18c8
[openwrt/staging/dedeckeh.git] / package / boot / uboot-mediatek / patches / 412-add-ubnt-unifi-6-lr.patch
1 --- /dev/null
2 +++ b/configs/mt7622_ubnt_unifi-6-lr_defconfig
3 @@ -0,0 +1,143 @@
4 +CONFIG_ARM=y
5 +CONFIG_POSITION_INDEPENDENT=y
6 +CONFIG_ARCH_MEDIATEK=y
7 +CONFIG_TARGET_MT7622=y
8 +CONFIG_SYS_TEXT_BASE=0x41e00000
9 +CONFIG_SYS_MALLOC_F_LEN=0x4000
10 +CONFIG_SYS_LOAD_ADDR=0x40080000
11 +CONFIG_USE_DEFAULT_ENV_FILE=y
12 +CONFIG_MTDPARTS_DEFAULT="mtdparts=nor0:128k(bl2),640k(fip),64k(u-boot-env),256k(factory),64k(eeprom),15232k(recovery),-(firmware)"
13 +CONFIG_ENV_IS_IN_MTD=y
14 +CONFIG_ENV_MTD_NAME="nor0"
15 +CONFIG_ENV_SIZE_REDUND=0x4000
16 +CONFIG_ENV_SIZE=0x4000
17 +CONFIG_ENV_OFFSET=0xc0000
18 +CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
19 +CONFIG_BOARD_LATE_INIT=y
20 +CONFIG_RESET_BUTTON_SETTLE_DELAY=400
21 +CONFIG_BOOTP_SEND_HOSTNAME=y
22 +CONFIG_DEFAULT_ENV_FILE="ubnt_unifi-6-lr_env"
23 +CONFIG_DEBUG_UART_BASE=0x11002000
24 +CONFIG_DEBUG_UART_CLOCK=25000000
25 +CONFIG_DEFAULT_DEVICE_TREE="mt7622-ubnt-unifi-6-lr"
26 +CONFIG_DEBUG_UART=y
27 +CONFIG_SMBIOS_PRODUCT_NAME=""
28 +CONFIG_AUTOBOOT_KEYED=y
29 +CONFIG_BOOTDELAY=30
30 +CONFIG_AUTOBOOT_MENU_SHOW=y
31 +CONFIG_CFB_CONSOLE_ANSI=y
32 +CONFIG_BUTTON=y
33 +CONFIG_BUTTON_GPIO=y
34 +CONFIG_GPIO_HOG=y
35 +CONFIG_CMD_ENV_FLAGS=y
36 +CONFIG_FIT=y
37 +CONFIG_FIT_ENABLE_SHA256_SUPPORT=y
38 +CONFIG_LOGLEVEL=7
39 +CONFIG_LOG=y
40 +CONFIG_DEFAULT_FDT_FILE="mt7622-ubnt-unifi-6-lr"
41 +CONFIG_SYS_PROMPT="MT7622> "
42 +# CONFIG_LEGACY_IMAGE_FORMAT is not set
43 +# CONFIG_BOOTM_PLAN9 is not set
44 +# CONFIG_BOOTM_RTEMS is not set
45 +# CONFIG_BOOTM_VXWORKS is not set
46 +# CONFIG_EFI is not set
47 +# CONFIG_EFI_LOADER is not set
48 +CONFIG_CMD_BOOTMENU=y
49 +# CONFIG_CMD_BOOTEFI is not set
50 +CONFIG_CMD_BOOTP=y
51 +CONFIG_CMD_BUTTON=y
52 +CONFIG_CMD_CDP=y
53 +CONFIG_CMD_DHCP=y
54 +CONFIG_CMD_DNS=y
55 +CONFIG_CMD_ECHO=y
56 +# CONFIG_CMD_ELF is not set
57 +# CONFIG_CMD_BOOTEFI_BOOTMGR is not set
58 +CONFIG_CMD_ENV_READMEM=y
59 +CONFIG_CMD_ERASEENV=y
60 +CONFIG_CMD_GPIO=y
61 +CONFIG_CMD_HASH=y
62 +CONFIG_CMD_ITEST=y
63 +CONFIG_CMD_LED=y
64 +CONFIG_CMD_LINK_LOCAL=y
65 +# CONFIG_CMD_MBR is not set
66 +CONFIG_CMD_MTD=y
67 +CONFIG_CMD_MTDPARTS=y
68 +# CONFIG_CMD_PCI is not set
69 +CONFIG_CMD_SF_TEST=y
70 +CONFIG_CMD_PING=y
71 +CONFIG_CMD_PXE=y
72 +CONFIG_CMD_SMC=y
73 +CONFIG_CMD_TFTPBOOT=y
74 +CONFIG_CMD_TFTPSRV=y
75 +# CONFIG_CMD_UNLZ4 is not set
76 +CONFIG_CMD_ASKENV=y
77 +CONFIG_CMD_PSTORE=y
78 +CONFIG_CMD_PSTORE_MEM_ADDR=0x42ff0000
79 +CONFIG_CMD_RARP=y
80 +CONFIG_CMD_SETEXPR=y
81 +CONFIG_CMD_SLEEP=y
82 +CONFIG_CMD_SOURCE=y
83 +CONFIG_CMD_UUID=y
84 +CONFIG_DISPLAY_CPUINFO=y
85 +CONFIG_DM_ETH=y
86 +CONFIG_DM_ETH_PHY=y
87 +CONFIG_DM_GPIO=y
88 +CONFIG_DM_MDIO=y
89 +CONFIG_DM_MTD=y
90 +CONFIG_DM_REGULATOR=y
91 +CONFIG_DM_REGULATOR_FIXED=y
92 +CONFIG_DM_REGULATOR_GPIO=y
93 +# CONFIG_DM_MMC is not set
94 +CONFIG_DM_SERIAL=y
95 +CONFIG_DM_SPI=y
96 +CONFIG_DM_SPI_FLASH=y
97 +CONFIG_HUSH_PARSER=y
98 +# CONFIG_PARTITION_UUIDS is not set
99 +CONFIG_SYS_RELOC_GD_ENV_ADDR=y
100 +# CONFIG_LED is not set
101 +# CONFIG_LZ4 is not set
102 +CONFIG_VERSION_VARIABLE=y
103 +CONFIG_NETCONSOLE=y
104 +CONFIG_REGMAP=y
105 +CONFIG_SYSCON=y
106 +CONFIG_CLK=y
107 +CONFIG_PHY=y
108 +CONFIG_PHY_FIXED=y
109 +CONFIG_PHYLIB_10G=y
110 +CONFIG_PHY_AQUANTIA=y
111 +CONFIG_PHY_ADDR_ENABLE=y
112 +CONFIG_PHY_ADDR=8
113 +CONFIG_MEDIATEK_ETH=y
114 +CONFIG_MTD=y
115 +# CONFIG_MMC is not set
116 +CONFIG_PINCTRL=y
117 +CONFIG_PINCONF=y
118 +CONFIG_PINCTRL_MT7622=y
119 +CONFIG_POWER_DOMAIN=y
120 +CONFIG_PRE_CONSOLE_BUFFER=y
121 +CONFIG_PRE_CON_BUF_ADDR=0x4007EF00
122 +CONFIG_MTK_POWER_DOMAIN=y
123 +CONFIG_RAM=y
124 +CONFIG_MTK_SERIAL=y
125 +CONFIG_SPI=y
126 +CONFIG_MTK_SNFI_SPI=y
127 +CONFIG_MTK_SNOR=y
128 +CONFIG_SYSRESET_WATCHDOG=y
129 +CONFIG_WDT_MTK=y
130 +CONFIG_HEXDUMP=y
131 +CONFIG_RANDOM_UUID=y
132 +CONFIG_REGEX=y
133 +CONFIG_SPI_FLASH=y
134 +CONFIG_SPI_FLASH_BAR=y
135 +CONFIG_SPI_FLASH_MTD=y
136 +CONFIG_SPI_FLASH_UNLOCK_ALL=y
137 +CONFIG_SPI_FLASH_EON=y
138 +CONFIG_SPI_FLASH_GIGADEVICE=y
139 +CONFIG_SPI_FLASH_MACRONIX=y
140 +CONFIG_SPI_FLASH_SPANSION=y
141 +CONFIG_SPI_FLASH_STMICRO=y
142 +CONFIG_SPI_FLASH_SST=y
143 +CONFIG_SPI_FLASH_WINBOND=y
144 +CONFIG_SPI_FLASH_XMC=y
145 +CONFIG_SPI_FLASH_USE_4K_SECTORS=y
146 +CONFIG_SYS_HAS_NONCACHED_MEMORY=y
147 --- /dev/null
148 +++ b/arch/arm/dts/mt7622-ubnt-unifi-6-lr.dts
149 @@ -0,0 +1,187 @@
150 +// SPDX-License-Identifier: GPL-2.0
151 +/*
152 + * Copyright (c) 2019 MediaTek Inc.
153 + * Author: Sam Shih <sam.shih@mediatek.com>
154 + */
155 +
156 +/dts-v1/;
157 +#include "mt7622.dtsi"
158 +#include "mt7622-u-boot.dtsi"
159 +
160 +/ {
161 + #address-cells = <1>;
162 + #size-cells = <1>;
163 + model = "mt7622-ubnt-unifi-6-lr";
164 + compatible = "mediatek,mt7622", "ubnt,unifi-6-lr";
165 +
166 + chosen {
167 + stdout-path = &uart0;
168 + tick-timer = &timer0;
169 + };
170 +
171 + aliases {
172 + spi0 = &snor;
173 + };
174 +
175 + gpio-keys {
176 + compatible = "gpio-keys";
177 + u-boot,dm-pre-reloc;
178 +
179 + reset {
180 + label = "reset";
181 + gpios = <&gpio 62 GPIO_ACTIVE_LOW>;
182 + u-boot,dm-pre-reloc;
183 + };
184 + };
185 +
186 + memory@40000000 {
187 + device_type = "memory";
188 + reg = <0x40000000 0x20000000>;
189 + };
190 +
191 + reg_1p8v: regulator-1p8v {
192 + compatible = "regulator-fixed";
193 + regulator-name = "fixed-1.8V";
194 + regulator-min-microvolt = <1800000>;
195 + regulator-max-microvolt = <1800000>;
196 + regulator-boot-on;
197 + regulator-always-on;
198 + };
199 +
200 + reg_3p3v: regulator-3p3v {
201 + compatible = "regulator-fixed";
202 + regulator-name = "fixed-3.3V";
203 + regulator-min-microvolt = <3300000>;
204 + regulator-max-microvolt = <3300000>;
205 + regulator-boot-on;
206 + regulator-always-on;
207 + };
208 +
209 + reg_5v: regulator-5v {
210 + compatible = "regulator-fixed";
211 + regulator-name = "fixed-5V";
212 + regulator-min-microvolt = <5000000>;
213 + regulator-max-microvolt = <5000000>;
214 + regulator-boot-on;
215 + regulator-always-on;
216 + };
217 +};
218 +
219 +&pcie {
220 + pinctrl-names = "default";
221 + pinctrl-0 = <&pcie0_pins>, <&pcie1_pins>;
222 + status = "okay";
223 +
224 + pcie@0,0 {
225 + status = "okay";
226 + };
227 +
228 + pcie@1,0 {
229 + status = "okay";
230 + };
231 +};
232 +
233 +&pinctrl {
234 + eth_pins: eth-pins {
235 + mux {
236 + function = "eth";
237 + groups = "mdc_mdio", "rgmii_via_gmac2";
238 + };
239 + };
240 +
241 + pcie0_pins: pcie0-pins {
242 + mux {
243 + function = "pcie";
244 + groups = "pcie0_pad_perst",
245 + "pcie0_1_waken",
246 + "pcie0_1_clkreq";
247 + };
248 + };
249 +
250 + pcie1_pins: pcie1-pins {
251 + mux {
252 + function = "pcie";
253 + groups = "pcie1_pad_perst",
254 + "pcie1_0_waken",
255 + "pcie1_0_clkreq";
256 + };
257 + };
258 +
259 + snfi_pins: snfi-pins {
260 + mux {
261 + function = "flash";
262 + groups = "snfi";
263 + };
264 + };
265 +
266 + snor_pins: snor-pins {
267 + mux {
268 + function = "flash";
269 + groups = "spi_nor";
270 + };
271 + };
272 +
273 + uart0_pins: uart0 {
274 + mux {
275 + function = "uart";
276 + groups = "uart0_0_tx_rx" ;
277 + };
278 + };
279 +
280 + watchdog_pins: watchdog-default {
281 + mux {
282 + function = "watchdog";
283 + groups = "watchdog";
284 + };
285 + };
286 +};
287 +
288 +&snor {
289 + pinctrl-names = "default";
290 + pinctrl-0 = <&snor_pins>;
291 + status = "okay";
292 +
293 + spi-flash@0 {
294 + compatible = "jedec,spi-nor";
295 + reg = <0>;
296 + spi-tx-bus-width = <1>;
297 + spi-rx-bus-width = <4>;
298 + u-boot,dm-pre-reloc;
299 + };
300 +};
301 +
302 +&uart0 {
303 + status = "okay";
304 +};
305 +
306 +&watchdog {
307 + pinctrl-names = "default";
308 + pinctrl-0 = <&watchdog_pins>;
309 + status = "okay";
310 +};
311 +
312 +&eth {
313 + status = "okay";
314 + pinctrl-names = "default";
315 + pinctrl-0 = <&eth_pins>;
316 +
317 + mediatek,gmac-id = <0>;
318 + phy-mode = "sgmii";
319 + phy-handle = <&gphy>;
320 +
321 + fixed-link {
322 + speed = <1000>;
323 + full-duplex;
324 + };
325 +
326 + mdio-bus {
327 + #address-cells = <1>;
328 + #size-cells = <0>;
329 +
330 + gphy: ethernet-phy@8 {
331 + /* Marvell AQRate AQR112W - no driver */
332 + compatible = "ethernet-phy-ieee802.3-c45";
333 + reg = <0x8>;
334 + };
335 + };
336 +};
337 --- a/arch/arm/dts/Makefile
338 +++ b/arch/arm/dts/Makefile
339 @@ -1264,6 +1264,7 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += \
340 mt7623a-unielec-u7623-02-emmc.dtb \
341 mt7622-bananapi-bpi-r64.dtb \
342 mt7622-linksys-e8450-ubi.dtb \
343 + mt7622-ubnt-unifi-6-lr.dtb \
344 mt7623n-bananapi-bpi-r2.dtb \
345 mt7629-rfb.dtb \
346 mt7981-rfb.dtb \
347 --- /dev/null
348 +++ b/ubnt_unifi-6-lr_env
349 @@ -0,0 +1,50 @@
350 +ethaddr_factory=mtd read nor0 $loadaddr 0x110000 0x10000 && env readmem -b ethaddr $loadaddr 0x6 ; setenv ethaddr_factory
351 +ipaddr=192.168.1.1
352 +serverip=192.168.1.254
353 +loadaddr=0x48000000
354 +bootcmd=if pstore check ; then run boot_recovery ; else run boot_nor ; fi
355 +bootdelay=0
356 +bootfile=openwrt-mediatek-mt7622-ubnt_unifi-6-lr-v1-ubootmod-initramfs-recovery.itb
357 +bootfile_bl2=openwrt-mediatek-mt7622-ubnt_unifi-6-lr-v1-ubootmod-preloader.bin
358 +bootfile_fip=openwrt-mediatek-mt7622-ubnt_unifi-6-lr-v1-ubootmod-bl31-uboot.fip
359 +bootfile_upg=openwrt-mediatek-mt7622-ubnt_unifi-6-lr-v1-ubootmod-squashfs-sysupgrade.itb
360 +bootmenu_confirm_return=askenv - Press ENTER to return to menu ; bootmenu 60
361 +bootmenu_default=0
362 +bootmenu_delay=0
363 +bootmenu_title= \e[0;34m( ( ( \e[1;39mOpenWrt\e[0;34m ) ) )\e[0m
364 +bootmenu_0=Initialize environment.=run _firstboot
365 +bootmenu_0d=Run default boot command.=run boot_default
366 +bootmenu_1=Boot system via TFTP.=run boot_tftp ; run bootmenu_confirm_return
367 +bootmenu_2=Boot production system from flash.=run boot_production ; run bootmenu_confirm_return
368 +bootmenu_3=Boot recovery system from flash.=run boot_recovery ; run bootmenu_confirm_return
369 +bootmenu_4=Load production system via TFTP then write to flash.=setenv noboot 1 ; setenv replacevol 1 ; run boot_tftp_production ; setenv noboot ; setenv replacevol ; run bootmenu_confirm_return
370 +bootmenu_5=Load recovery system via TFTP then write to flash.=setenv noboot 1 ; setenv replacevol 1 ; run boot_tftp_recovery ; setenv noboot ; setenv replacevol ; run bootmenu_confirm_return
371 +bootmenu_6=\e[31mLoad BL31+U-Boot FIP via TFTP then write to flash.\e[0m=run boot_tftp_write_fip ; run bootmenu_confirm_return
372 +bootmenu_7=\e[31mLoad BL2 preloader via TFTP then write to flash.\e[0m=run boot_tftp_write_preloader ; run bootmenu_confirm_return
373 +bootmenu_8=Reboot.=reset
374 +bootmenu_9=Reset all settings to factory defaults.=run reset_factory ; reset
375 +boot_first=if button reset ; then run boot_tftp_recovery ; setenv flag_recover 1 ; run boot_default ; fi ; bootmenu
376 +boot_default=if env exists flag_recover ; then else run bootcmd ; fi ; run boot_recovery ; setenv replacevol 1 ; run boot_tftp_forever
377 +boot_production=run nor_read_production && bootm $loadaddr
378 +boot_recovery=run nor_read_recovery ; bootm $loadaddr
379 +boot_serial_write_fip=loadx $loadaddr 115200 && run boot_write_fip
380 +boot_serial_write_preloader=loadx $loadaddr 115200 && run boot_write_preloader
381 +boot_tftp_forever=while true ; do run boot_tftp_recovery ; sleep 1 ; done
382 +boot_tftp_production=tftpboot $loadaddr $bootfile_upg && env exists replacevol && iminfo $loadaddr && run nor_write_production ; if env exists noboot ; then else bootm $loadaddr ; fi
383 +boot_tftp_recovery=tftpboot $loadaddr $bootfile && env exists replacevol && iminfo $loadaddr && run nor_write_recovery ; if env exists noboot ; then else bootm $loadaddr ; fi
384 +boot_tftp=tftpboot $loadaddr $bootfile && bootm $loadaddr
385 +boot_tftp_write_fip=tftpboot $loadaddr $bootfile_fip && run boot_write_fip
386 +boot_tftp_write_preloader=tftpboot $loadaddr $bootfile_bl2 && run boot_write_preloader
387 +boot_nor=run boot_production ; run boot_recovery
388 +boot_write_fip=mtd erase nor0 0x20000 0x80000 && mtd write nor0 $loadaddr 0x20000 0x80000
389 +boot_write_preloader=mtd erase nor0 0x0 0x20000 && mtd write nor0 $loadaddr 0x0 0x20000
390 +reset_factory=mtd erase nor0 0xc0000 0x10000 && reset
391 +nor_read_production=mtd read nor0 $loadaddr 0x1000000 0x1000 && imsz $loadaddr image_size && mtd read nor0 $loadaddr 0x1000000 $image_size
392 +nor_read_recovery=mtd read nor0 $loadaddr 0x120000 0x1000 && imsz $loadaddr image_size && mtd read nor0 $loadaddr 0x120000 $image_size
393 +nor_pad_size=imsz $loadaddr image_size ; setexpr image_eb 0x$image_size / 0x1000 ; setexpr tmp1 0x$image_size % 0x1000 ; test 0x$tmp1 -gt 0 && setexpr image_eb 0x$image_eb + 1 ; setexpr image_eb 0x$image_eb * 0x1000
394 +nor_write_production=run nor_pad_size ; test 0x$image_eb -le 0x3000000 && mtd erase nor0 0x1000000 0x$image_eb && mtd write nor0 $loadaddr 0x1000000 $filesize
395 +nor_write_recovery=run nor_pad_size ; test 0x$image_eb -le 0xee0000 && mtd erase nor0 0x120000 0x$image_eb && mtd write nor0 $loadaddr 0x120000 $filesize
396 +_init_env=setenv _init_env ; saveenv
397 +_firstboot=setenv _firstboot ; run _switch_to_menu ; run ethaddr_factory ; run _init_env ; run boot_first
398 +_switch_to_menu=setenv _switch_to_menu ; setenv bootdelay 3 ; setenv bootmenu_delay 3 ; setenv bootmenu_0 $bootmenu_0d ; setenv bootmenu_0d ; run _bootmenu_update_title
399 +_bootmenu_update_title=setenv _bootmenu_update_title ; setenv bootmenu_title "$bootmenu_title \e[33m$ver\e[0m"
400 --- a/common/board_r.c
401 +++ b/common/board_r.c
402 @@ -66,6 +66,7 @@
403 #include <asm-generic/gpio.h>
404 #include <efi_loader.h>
405 #include <relocate.h>
406 +#include <spi_flash.h>
407
408 DECLARE_GLOBAL_DATA_PTR;
409
410 @@ -412,6 +413,20 @@ static int initr_onenand(void)
411 }
412 #endif
413
414 +#if defined(CONFIG_SPI_FLASH)
415 +/* probe SPI FLASH */
416 +static int initr_spiflash(void)
417 +{
418 + struct udevice *new;
419 +
420 +spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS,
421 + CONFIG_SF_DEFAULT_CS,
422 + &new);
423 +
424 + return 0;
425 +}
426 +#endif
427 +
428 #ifdef CONFIG_MMC
429 static int initr_mmc(void)
430 {
431 @@ -720,6 +735,9 @@ static init_fnc_t init_sequence_r[] = {
432 #ifdef CONFIG_NMBM_MTD
433 initr_nmbm,
434 #endif
435 +#ifdef CONFIG_SPI_FLASH
436 + initr_spiflash,
437 +#endif
438 #ifdef CONFIG_MMC
439 initr_mmc,
440 #endif