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