uboot-d1: add bootloader for upcoming d1 target
[openwrt/staging/981213.git] / package / boot / uboot-d1 / patches / 0087-sunxi-Add-temporary-RISC-V-version-of-board-code.patch
1 From e3152c690732fb141500379f32fbe2203fa47059 Mon Sep 17 00:00:00 2001
2 From: Samuel Holland <samuel@sholland.org>
3 Date: Sat, 6 Aug 2022 00:48:38 -0500
4 Subject: [PATCH 87/90] sunxi: Add temporary RISC-V version of board code
5
6 Signed-off-by: Samuel Holland <samuel@sholland.org>
7 ---
8 board/sunxi/Makefile | 3 +-
9 board/sunxi/board-riscv.c | 687 +++++++++++++++++++++++++++++++++
10 include/configs/sunxi-common.h | 1 -
11 3 files changed, 689 insertions(+), 2 deletions(-)
12 create mode 100644 board/sunxi/board-riscv.c
13
14 --- a/board/sunxi/Makefile
15 +++ b/board/sunxi/Makefile
16 @@ -6,7 +6,8 @@
17 #
18 # (C) Copyright 2000-2003
19 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
20 -obj-y += board.o
21 +obj-$(CONFIG_ARM) += board.o
22 +obj-$(CONFIG_RISCV) += board-riscv.o
23 obj-$(CONFIG_SUN7I_GMAC) += gmac.o
24 obj-$(CONFIG_MACH_SUN4I) += dram_sun4i_auto.o
25 obj-$(CONFIG_MACH_SUN5I) += dram_sun5i_auto.o
26 --- /dev/null
27 +++ b/board/sunxi/board-riscv.c
28 @@ -0,0 +1,687 @@
29 +// SPDX-License-Identifier: GPL-2.0+
30 +/*
31 + * (C) Copyright 2012-2013 Henrik Nordstrom <henrik@henriknordstrom.net>
32 + * (C) Copyright 2013 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
33 + *
34 + * (C) Copyright 2007-2011
35 + * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
36 + * Tom Cubie <tangliang@allwinnertech.com>
37 + *
38 + * Some board init for the Allwinner A10-evb board.
39 + */
40 +
41 +#include <dm.h>
42 +#include <cpu.h>
43 +#include <env.h>
44 +#include <env_internal.h>
45 +#include <fdt_support.h>
46 +#include <generic-phy.h>
47 +#include <image.h>
48 +#include <init.h>
49 +#include <net.h>
50 +#include <phy-sun4i-usb.h>
51 +#include <ram.h>
52 +#include <remoteproc.h>
53 +#include <spl.h>
54 +#include <status_led.h>
55 +#include <sunxi_image.h>
56 +#include <u-boot/crc.h>
57 +#include <asm/csr.h>
58 +#include <asm/global_data.h>
59 +#include <asm/io.h>
60 +
61 +#ifdef CONFIG_RISCV
62 +int board_init(void)
63 +{
64 + /* https://lore.kernel.org/u-boot/31587574-4cd1-02da-9761-0134ac82b94b@sholland.org/ */
65 + return cpu_probe_all();
66 +}
67 +
68 +int sunxi_get_sid(unsigned int *sid)
69 +{
70 + return -ENODEV;
71 +}
72 +
73 +#define SPL_ADDR CONFIG_SUNXI_SRAM_ADDRESS
74 +
75 +/* The low 8-bits of the 'boot_media' field in the SPL header */
76 +#define SUNXI_BOOTED_FROM_MMC0 0
77 +#define SUNXI_BOOTED_FROM_NAND 1
78 +#define SUNXI_BOOTED_FROM_MMC2 2
79 +#define SUNXI_BOOTED_FROM_SPI 3
80 +#define SUNXI_BOOTED_FROM_MMC0_HIGH 0x10
81 +#define SUNXI_BOOTED_FROM_MMC2_HIGH 0x12
82 +
83 +#define SUNXI_INVALID_BOOT_SOURCE -1
84 +
85 +static int sunxi_egon_valid(struct boot_file_head *egon_head)
86 +{
87 + return !memcmp(egon_head->magic, BOOT0_MAGIC, 8); /* eGON.BT0 */
88 +}
89 +
90 +static int sunxi_toc0_valid(struct toc0_main_info *toc0_info)
91 +{
92 + return !memcmp(toc0_info->name, TOC0_MAIN_INFO_NAME, 8); /* TOC0.GLH */
93 +}
94 +
95 +static int sunxi_get_boot_source(void)
96 +{
97 + struct boot_file_head *egon_head = (void *)SPL_ADDR;
98 + struct toc0_main_info *toc0_info = (void *)SPL_ADDR;
99 +
100 + /*
101 + * On the ARMv5 SoCs, the SPL header in SRAM is overwritten by the
102 + * exception vectors in U-Boot proper, so we won't find any
103 + * information there. Also the FEL stash is only valid in the SPL,
104 + * so we can't use that either. So if this is called from U-Boot
105 + * proper, just return MMC0 as a placeholder, for now.
106 + */
107 + if (IS_ENABLED(CONFIG_MACH_SUNIV) &&
108 + !IS_ENABLED(CONFIG_SPL_BUILD))
109 + return SUNXI_BOOTED_FROM_MMC0;
110 +
111 + if (sunxi_egon_valid(egon_head))
112 + return readb(&egon_head->boot_media);
113 + if (sunxi_toc0_valid(toc0_info))
114 + return readb(&toc0_info->platform[0]);
115 +
116 + /* Not a valid image, so we must have been booted via FEL. */
117 + return SUNXI_INVALID_BOOT_SOURCE;
118 +}
119 +
120 +/* The sunxi internal brom will try to loader external bootloader
121 + * from mmc0, nand flash, mmc2.
122 + */
123 +uint32_t sunxi_get_boot_device(void)
124 +{
125 + int boot_source = sunxi_get_boot_source();
126 +
127 + /*
128 + * When booting from the SD card or NAND memory, the "eGON.BT0"
129 + * signature is expected to be found in memory at the address 0x0004
130 + * (see the "mksunxiboot" tool, which generates this header).
131 + *
132 + * When booting in the FEL mode over USB, this signature is patched in
133 + * memory and replaced with something else by the 'fel' tool. This other
134 + * signature is selected in such a way, that it can't be present in a
135 + * valid bootable SD card image (because the BROM would refuse to
136 + * execute the SPL in this case).
137 + *
138 + * This checks for the signature and if it is not found returns to
139 + * the FEL code in the BROM to wait and receive the main u-boot
140 + * binary over USB. If it is found, it determines where SPL was
141 + * read from.
142 + */
143 + switch (boot_source) {
144 + case SUNXI_INVALID_BOOT_SOURCE:
145 + return BOOT_DEVICE_BOARD;
146 + case SUNXI_BOOTED_FROM_MMC0:
147 + case SUNXI_BOOTED_FROM_MMC0_HIGH:
148 + return BOOT_DEVICE_MMC1;
149 + case SUNXI_BOOTED_FROM_NAND:
150 + return BOOT_DEVICE_NAND;
151 + case SUNXI_BOOTED_FROM_MMC2:
152 + case SUNXI_BOOTED_FROM_MMC2_HIGH:
153 + return BOOT_DEVICE_MMC2;
154 + case SUNXI_BOOTED_FROM_SPI:
155 + return BOOT_DEVICE_SPI;
156 + }
157 +
158 + panic("Unknown boot source %d\n", boot_source);
159 + return -1; /* Never reached */
160 +}
161 +
162 +uint32_t sunxi_get_spl_size(void)
163 +{
164 + struct boot_file_head *egon_head = (void *)SPL_ADDR;
165 + struct toc0_main_info *toc0_info = (void *)SPL_ADDR;
166 +
167 + if (sunxi_egon_valid(egon_head))
168 + return readl(&egon_head->length);
169 + if (sunxi_toc0_valid(toc0_info))
170 + return readl(&toc0_info->length);
171 +
172 + /* Not a valid image, so use the default U-Boot offset. */
173 + return 0;
174 +}
175 +
176 +/*
177 + * The eGON SPL image can be located at 8KB or at 128KB into an SD card or
178 + * an eMMC device. The boot source has bit 4 set in the latter case.
179 + * By adding 120KB to the normal offset when booting from a "high" location
180 + * we can support both cases.
181 + * Also U-Boot proper is located at least 32KB after the SPL, but will
182 + * immediately follow the SPL if that is bigger than that.
183 + */
184 +unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
185 + unsigned long raw_sect)
186 +{
187 + unsigned long spl_size = sunxi_get_spl_size();
188 + unsigned long sector;
189 +
190 + sector = max(raw_sect, spl_size / 512);
191 +
192 + switch (sunxi_get_boot_source()) {
193 + case SUNXI_BOOTED_FROM_MMC0_HIGH:
194 + case SUNXI_BOOTED_FROM_MMC2_HIGH:
195 + sector += (128 - 8) * 2;
196 + break;
197 + }
198 +
199 + printf("SPL size = %lu, sector = %lu\n", spl_size, sector);
200 +
201 + return sector;
202 +}
203 +
204 +u32 spl_boot_device(void)
205 +{
206 + return sunxi_get_boot_device();
207 +}
208 +
209 +#define CSR_MXSTATUS 0x7c0
210 +#define CSR_MHCR 0x7c1
211 +#define CSR_MCOR 0x7c2
212 +#define CSR_MHINT 0x7c5
213 +
214 +int spl_board_init_f(void)
215 +{
216 + int ret;
217 + struct udevice *dev;
218 +
219 + /* DDR init */
220 + ret = uclass_get_device(UCLASS_RAM, 0, &dev);
221 + if (ret) {
222 + debug("DRAM init failed: %d\n", ret);
223 + return ret;
224 + }
225 +
226 + /* Initialize extension CSRs. */
227 + printf("mxstatus=0x%08lx mhcr=0x%08lx mcor=0x%08lx mhint=0x%08lx\n",
228 + csr_read(CSR_MXSTATUS),
229 + csr_read(CSR_MHCR),
230 + csr_read(CSR_MCOR),
231 + csr_read(CSR_MHINT));
232 +
233 + csr_set(CSR_MXSTATUS, 0x638000);
234 + csr_write(CSR_MCOR, 0x70013);
235 + csr_write(CSR_MHCR, 0x11ff);
236 + csr_write(CSR_MHINT, 0x16e30c);
237 +
238 + return 0;
239 +}
240 +
241 +#ifdef CONFIG_SPL_BUILD
242 +void spl_perform_fixups(struct spl_image_info *spl_image)
243 +{
244 + struct ram_info info;
245 + struct udevice *dev;
246 + int ret;
247 +
248 + ret = uclass_get_device(UCLASS_RAM, 0, &dev);
249 + if (ret)
250 + panic("No RAM device");
251 +
252 + ret = ram_get_info(dev, &info);
253 + if (ret)
254 + panic("No RAM info");
255 +
256 + ret = fdt_fixup_memory(spl_image->fdt_addr, info.base, info.size);
257 + if (ret)
258 + panic("Failed to update DTB");
259 +}
260 +#endif
261 +#endif
262 +
263 +DECLARE_GLOBAL_DATA_PTR;
264 +
265 +/*
266 + * Try to use the environment from the boot source first.
267 + * For MMC, this means a FAT partition on the boot device (SD or eMMC).
268 + * If the raw MMC environment is also enabled, this is tried next.
269 + * When booting from NAND we try UBI first, then NAND directly.
270 + * SPI flash falls back to FAT (on SD card).
271 + */
272 +enum env_location env_get_location(enum env_operation op, int prio)
273 +{
274 + if (prio > 1)
275 + return ENVL_UNKNOWN;
276 +
277 + /* NOWHERE is exclusive, no other option can be defined. */
278 + if (IS_ENABLED(CONFIG_ENV_IS_NOWHERE))
279 + return ENVL_NOWHERE;
280 +
281 + switch (sunxi_get_boot_device()) {
282 + case BOOT_DEVICE_MMC1:
283 + case BOOT_DEVICE_MMC2:
284 + if (prio == 0 && IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
285 + return ENVL_FAT;
286 + if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC))
287 + return ENVL_MMC;
288 + break;
289 + case BOOT_DEVICE_NAND:
290 + if (prio == 0 && IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
291 + return ENVL_UBI;
292 + if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
293 + return ENVL_NAND;
294 + break;
295 + case BOOT_DEVICE_SPI:
296 + if (prio == 0 && IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
297 + return ENVL_SPI_FLASH;
298 + if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
299 + return ENVL_FAT;
300 + break;
301 + case BOOT_DEVICE_BOARD:
302 + break;
303 + default:
304 + break;
305 + }
306 +
307 + /*
308 + * If we come here for the first time, we *must* return a valid
309 + * environment location other than ENVL_UNKNOWN, or the setup sequence
310 + * in board_f() will silently hang. This is arguably a bug in
311 + * env_init(), but for now pick one environment for which we know for
312 + * sure to have a driver for. For all defconfigs this is either FAT
313 + * or UBI, or NOWHERE, which is already handled above.
314 + */
315 + if (prio == 0) {
316 + if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
317 + return ENVL_FAT;
318 + if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
319 + return ENVL_UBI;
320 + }
321 +
322 + return ENVL_UNKNOWN;
323 +}
324 +
325 +/*
326 + * On older SoCs the SPL is actually at address zero, so using NULL as
327 + * an error value does not work.
328 + */
329 +#define INVALID_SPL_HEADER ((void *)~0UL)
330 +
331 +static struct boot_file_head * get_spl_header(uint8_t req_version)
332 +{
333 + struct boot_file_head *spl = (void *)(ulong)SPL_ADDR;
334 + uint8_t spl_header_version = spl->spl_signature[3];
335 +
336 + /* Is there really the SPL header (still) there? */
337 + if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) != 0)
338 + return INVALID_SPL_HEADER;
339 +
340 + if (spl_header_version < req_version) {
341 + printf("sunxi SPL version mismatch: expected %u, got %u\n",
342 + req_version, spl_header_version);
343 + return INVALID_SPL_HEADER;
344 + }
345 +
346 + return spl;
347 +}
348 +
349 +static const char *get_spl_dt_name(void)
350 +{
351 + struct boot_file_head *spl = get_spl_header(SPL_DT_HEADER_VERSION);
352 +
353 + /* Check if there is a DT name stored in the SPL header. */
354 + if (spl != INVALID_SPL_HEADER && spl->dt_name_offset)
355 + return (char *)spl + spl->dt_name_offset;
356 +
357 + return NULL;
358 +}
359 +
360 +#if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
361 +int mmc_get_env_dev(void)
362 +{
363 + switch (sunxi_get_boot_device()) {
364 + case BOOT_DEVICE_MMC1:
365 + return 0;
366 + case BOOT_DEVICE_MMC2:
367 + return 1;
368 + default:
369 + return CONFIG_SYS_MMC_ENV_DEV;
370 + }
371 +}
372 +#endif
373 +
374 +#ifdef CONFIG_SPL_BUILD
375 +void sunxi_board_init(void)
376 +{
377 +#ifdef CONFIG_LED_STATUS
378 + if (IS_ENABLED(CONFIG_SPL_DRIVERS_MISC))
379 + status_led_init();
380 +#endif
381 +}
382 +#endif
383 +
384 +#ifdef CONFIG_USB_GADGET
385 +int g_dnl_board_usb_cable_connected(void)
386 +{
387 + struct udevice *dev;
388 + struct phy phy;
389 + int ret;
390 +
391 + ret = uclass_get_device(UCLASS_USB_GADGET_GENERIC, 0, &dev);
392 + if (ret) {
393 + pr_err("%s: Cannot find USB device\n", __func__);
394 + return ret;
395 + }
396 +
397 + ret = generic_phy_get_by_name(dev, "usb", &phy);
398 + if (ret) {
399 + pr_err("failed to get %s USB PHY\n", dev->name);
400 + return ret;
401 + }
402 +
403 + ret = generic_phy_init(&phy);
404 + if (ret) {
405 + pr_debug("failed to init %s USB PHY\n", dev->name);
406 + return ret;
407 + }
408 +
409 + return sun4i_usb_phy_vbus_detect(&phy);
410 +}
411 +#endif
412 +
413 +#ifdef CONFIG_SERIAL_TAG
414 +void get_board_serial(struct tag_serialnr *serialnr)
415 +{
416 + char *serial_string;
417 + unsigned long long serial;
418 +
419 + serial_string = env_get("serial#");
420 +
421 + if (serial_string) {
422 + serial = simple_strtoull(serial_string, NULL, 16);
423 +
424 + serialnr->high = (unsigned int) (serial >> 32);
425 + serialnr->low = (unsigned int) (serial & 0xffffffff);
426 + } else {
427 + serialnr->high = 0;
428 + serialnr->low = 0;
429 + }
430 +}
431 +#endif
432 +
433 +/*
434 + * Check the SPL header for the "sunxi" variant. If found: parse values
435 + * that might have been passed by the loader ("fel" utility), and update
436 + * the environment accordingly.
437 + */
438 +static void parse_spl_header(const uint32_t spl_addr)
439 +{
440 + struct boot_file_head *spl = get_spl_header(SPL_ENV_HEADER_VERSION);
441 +
442 + if (spl == INVALID_SPL_HEADER)
443 + return;
444 +
445 + if (!spl->fel_script_address)
446 + return;
447 +
448 + if (spl->fel_uEnv_length != 0) {
449 + /*
450 + * data is expected in uEnv.txt compatible format, so "env
451 + * import -t" the string(s) at fel_script_address right away.
452 + */
453 + himport_r(&env_htab, (char *)(uintptr_t)spl->fel_script_address,
454 + spl->fel_uEnv_length, '\n', H_NOCLEAR, 0, 0, NULL);
455 + return;
456 + }
457 + /* otherwise assume .scr format (mkimage-type script) */
458 + env_set_hex("fel_scriptaddr", spl->fel_script_address);
459 +}
460 +
461 +static bool get_unique_sid(unsigned int *sid)
462 +{
463 + if (sunxi_get_sid(sid) != 0)
464 + return false;
465 +
466 + if (!sid[0])
467 + return false;
468 +
469 + /*
470 + * The single words 1 - 3 of the SID have quite a few bits
471 + * which are the same on many models, so we take a crc32
472 + * of all 3 words, to get a more unique value.
473 + *
474 + * Note we only do this on newer SoCs as we cannot change
475 + * the algorithm on older SoCs since those have been using
476 + * fixed mac-addresses based on only using word 3 for a
477 + * long time and changing a fixed mac-address with an
478 + * u-boot update is not good.
479 + */
480 +#if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \
481 + !defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \
482 + !defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33)
483 + sid[3] = crc32(0, (unsigned char *)&sid[1], 12);
484 +#endif
485 +
486 + /* Ensure the NIC specific bytes of the mac are not all 0 */
487 + if ((sid[3] & 0xffffff) == 0)
488 + sid[3] |= 0x800000;
489 +
490 + return true;
491 +}
492 +
493 +/*
494 + * Note this function gets called multiple times.
495 + * It must not make any changes to env variables which already exist.
496 + */
497 +static void setup_environment(const void *fdt)
498 +{
499 + char serial_string[17] = { 0 };
500 + unsigned int sid[4];
501 + uint8_t mac_addr[6];
502 + char ethaddr[16];
503 + int i;
504 +
505 + if (!get_unique_sid(sid))
506 + return;
507 +
508 + for (i = 0; i < 4; i++) {
509 + sprintf(ethaddr, "ethernet%d", i);
510 + if (!fdt_get_alias(fdt, ethaddr))
511 + continue;
512 +
513 + if (i == 0)
514 + strcpy(ethaddr, "ethaddr");
515 + else
516 + sprintf(ethaddr, "eth%daddr", i);
517 +
518 + if (env_get(ethaddr))
519 + continue;
520 +
521 + /* Non OUI / registered MAC address */
522 + mac_addr[0] = (i << 4) | 0x02;
523 + mac_addr[1] = (sid[0] >> 0) & 0xff;
524 + mac_addr[2] = (sid[3] >> 24) & 0xff;
525 + mac_addr[3] = (sid[3] >> 16) & 0xff;
526 + mac_addr[4] = (sid[3] >> 8) & 0xff;
527 + mac_addr[5] = (sid[3] >> 0) & 0xff;
528 +
529 + eth_env_set_enetaddr(ethaddr, mac_addr);
530 + }
531 +
532 + if (!env_get("serial#")) {
533 + snprintf(serial_string, sizeof(serial_string),
534 + "%08x%08x", sid[0], sid[3]);
535 +
536 + env_set("serial#", serial_string);
537 + }
538 +}
539 +
540 +int misc_init_r(void)
541 +{
542 + const char *spl_dt_name;
543 + uint boot;
544 +
545 + env_set("fel_booted", NULL);
546 + env_set("fel_scriptaddr", NULL);
547 + env_set("mmc_bootdev", NULL);
548 +
549 + boot = sunxi_get_boot_device();
550 + /* determine if we are running in FEL mode */
551 + if (boot == BOOT_DEVICE_BOARD) {
552 + env_set("fel_booted", "1");
553 + parse_spl_header(SPL_ADDR);
554 + /* or if we booted from MMC, and which one */
555 + } else if (boot == BOOT_DEVICE_MMC1) {
556 + env_set("mmc_bootdev", "0");
557 + } else if (boot == BOOT_DEVICE_MMC2) {
558 + env_set("mmc_bootdev", "1");
559 + }
560 +
561 + /* Set fdtfile to match the FIT configuration chosen in SPL. */
562 + spl_dt_name = get_spl_dt_name();
563 + if (spl_dt_name) {
564 + char *prefix = IS_ENABLED(CONFIG_ARM64) ? "allwinner/" : "";
565 + char str[64];
566 +
567 + snprintf(str, sizeof(str), "%s%s.dtb", prefix, spl_dt_name);
568 + env_set("fdtfile", str);
569 + }
570 +
571 + setup_environment(gd->fdt_blob);
572 +
573 + return 0;
574 +}
575 +
576 +int board_late_init(void)
577 +{
578 +#ifdef CONFIG_USB_ETHER
579 + usb_ether_init();
580 +#endif
581 +
582 +#ifdef SUNXI_SCP_BASE
583 + if (!rproc_load(0, SUNXI_SCP_BASE, SUNXI_SCP_MAX_SIZE)) {
584 + puts("Starting SCP...\n");
585 + rproc_start(0);
586 + }
587 +#endif
588 +
589 + return 0;
590 +}
591 +
592 +static void bluetooth_dt_fixup(void *blob)
593 +{
594 + /* Some devices ship with a Bluetooth controller default address.
595 + * Set a valid address through the device tree.
596 + */
597 + uchar tmp[ETH_ALEN], bdaddr[ETH_ALEN];
598 + unsigned int sid[4];
599 + int i;
600 +
601 + if (!CONFIG_BLUETOOTH_DT_DEVICE_FIXUP[0])
602 + return;
603 +
604 + if (eth_env_get_enetaddr("bdaddr", tmp)) {
605 + /* Convert between the binary formats of the corresponding stacks */
606 + for (i = 0; i < ETH_ALEN; ++i)
607 + bdaddr[i] = tmp[ETH_ALEN - i - 1];
608 + } else {
609 + if (!get_unique_sid(sid))
610 + return;
611 +
612 + bdaddr[0] = ((sid[3] >> 0) & 0xff) ^ 1;
613 + bdaddr[1] = (sid[3] >> 8) & 0xff;
614 + bdaddr[2] = (sid[3] >> 16) & 0xff;
615 + bdaddr[3] = (sid[3] >> 24) & 0xff;
616 + bdaddr[4] = (sid[0] >> 0) & 0xff;
617 + bdaddr[5] = 0x02;
618 + }
619 +
620 + do_fixup_by_compat(blob, CONFIG_BLUETOOTH_DT_DEVICE_FIXUP,
621 + "local-bd-address", bdaddr, ETH_ALEN, 1);
622 +}
623 +
624 +int ft_board_setup(void *blob, struct bd_info *bd)
625 +{
626 + int __maybe_unused r;
627 +
628 + /*
629 + * Call setup_environment and fdt_fixup_ethernet again
630 + * in case the boot fdt has ethernet aliases the u-boot
631 + * copy does not have.
632 + */
633 + setup_environment(blob);
634 + fdt_fixup_ethernet(blob);
635 +
636 + bluetooth_dt_fixup(blob);
637 +
638 +#ifdef CONFIG_VIDEO_DT_SIMPLEFB
639 + r = sunxi_simplefb_setup(blob);
640 + if (r)
641 + return r;
642 +#endif
643 + return 0;
644 +}
645 +
646 +#ifdef CONFIG_SPL_LOAD_FIT
647 +
648 +static void set_spl_dt_name(const char *name)
649 +{
650 + struct boot_file_head *spl = get_spl_header(SPL_ENV_HEADER_VERSION);
651 +
652 + if (spl == INVALID_SPL_HEADER)
653 + return;
654 +
655 + /* Promote the header version for U-Boot proper, if needed. */
656 + if (spl->spl_signature[3] < SPL_DT_HEADER_VERSION)
657 + spl->spl_signature[3] = SPL_DT_HEADER_VERSION;
658 +
659 + strcpy((char *)&spl->string_pool, name);
660 + spl->dt_name_offset = offsetof(struct boot_file_head, string_pool);
661 +}
662 +
663 +int board_fit_config_name_match(const char *name)
664 +{
665 + const char *best_dt_name = get_spl_dt_name();
666 + int ret;
667 +
668 +#ifdef CONFIG_DEFAULT_DEVICE_TREE
669 + if (best_dt_name == NULL)
670 + best_dt_name = CONFIG_DEFAULT_DEVICE_TREE;
671 +#endif
672 +
673 + if (best_dt_name == NULL) {
674 + /* No DT name was provided, so accept the first config. */
675 + return 0;
676 + }
677 +#ifdef CONFIG_PINE64_DT_SELECTION
678 + if (strstr(best_dt_name, "-pine64-plus")) {
679 + /* Differentiate the Pine A64 boards by their DRAM size. */
680 + if ((gd->ram_size == 512 * 1024 * 1024))
681 + best_dt_name = "sun50i-a64-pine64";
682 + }
683 +#endif
684 +#ifdef CONFIG_PINEPHONE_DT_SELECTION
685 + if (strstr(best_dt_name, "-pinephone")) {
686 + /* Differentiate the PinePhone revisions by GPIO inputs. */
687 + prcm_apb0_enable(PRCM_APB0_GATE_PIO);
688 + sunxi_gpio_set_pull(SUNXI_GPL(6), SUNXI_GPIO_PULL_UP);
689 + sunxi_gpio_set_cfgpin(SUNXI_GPL(6), SUNXI_GPIO_INPUT);
690 + udelay(100);
691 +
692 + /* PL6 is pulled low by the modem on v1.2. */
693 + if (gpio_get_value(SUNXI_GPL(6)) == 0)
694 + best_dt_name = "sun50i-a64-pinephone-1.2";
695 + else
696 + best_dt_name = "sun50i-a64-pinephone-1.1";
697 +
698 + sunxi_gpio_set_cfgpin(SUNXI_GPL(6), SUNXI_GPIO_DISABLE);
699 + sunxi_gpio_set_pull(SUNXI_GPL(6), SUNXI_GPIO_PULL_DISABLE);
700 + prcm_apb0_disable(PRCM_APB0_GATE_PIO);
701 + }
702 +#endif
703 +
704 + ret = strcmp(name, best_dt_name);
705 +
706 + /*
707 + * If one of the FIT configurations matches the most accurate DT name,
708 + * update the SPL header to provide that DT name to U-Boot proper.
709 + */
710 + if (ret == 0)
711 + set_spl_dt_name(best_dt_name);
712 +
713 + return ret;
714 +}
715 +#endif
716 --- a/include/configs/sunxi-common.h
717 +++ b/include/configs/sunxi-common.h
718 @@ -12,7 +12,6 @@
719 #ifndef _SUNXI_COMMON_CONFIG_H
720 #define _SUNXI_COMMON_CONFIG_H
721
722 -#include <asm/arch/cpu.h>
723 #include <linux/stringify.h>
724
725 /* Serial & console */