1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
11 #include <asm/arch/boot.h>
13 #include <asm/cache.h>
14 #include <asm/ptrace.h>
15 #include <linux/libfdt.h>
16 #include <linux/err.h>
17 #include <asm/arch/mem.h>
18 #include <asm/arch/sm.h>
19 #include <asm/armv8/mmu.h>
20 #include <asm/unaligned.h>
21 #include <efi_loader.h>
22 #include <u-boot/crc.h>
24 #if CONFIG_IS_ENABLED(FASTBOOT)
29 DECLARE_GLOBAL_DATA_PTR;
31 __weak int board_init(void)
42 offset = fdt_path_offset(gd->fdt_blob, "/memory");
46 val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
47 if (len < sizeof(*val) * 2)
50 /* Use unaligned access since cache is still disabled */
51 gd->ram_size = get_unaligned_be64(&val[1]);
56 __weak int meson_ft_board_setup(void *blob, struct bd_info *bd)
61 int ft_board_setup(void *blob, struct bd_info *bd)
63 meson_init_reserved_memory(blob);
65 return meson_ft_board_setup(blob, bd);
68 void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
72 ret = fdt_add_mem_rsv(fdt, start, size);
74 printf("Could not reserve zone @ 0x%llx\n", start);
76 if (IS_ENABLED(CONFIG_EFI_LOADER))
77 efi_add_memory_map(start, size, EFI_RESERVED_MEMORY_TYPE);
80 int meson_generate_serial_ethaddr(void)
82 u8 mac_addr[ARP_HLEN];
83 char serial[SM_SERIAL_SIZE];
87 if (!meson_sm_get_serial(serial, SM_SERIAL_SIZE)) {
88 sid = crc32(0, (unsigned char *)serial, SM_SERIAL_SIZE);
89 sid16 = crc16_ccitt(0, (unsigned char *)serial, SM_SERIAL_SIZE);
91 /* Ensure the NIC specific bytes of the mac are not all 0 */
92 if ((sid & 0xffffff) == 0)
95 /* Non OUI / registered MAC address */
96 mac_addr[0] = ((sid16 >> 8) & 0xfc) | 0x02;
97 mac_addr[1] = (sid16 >> 0) & 0xff;
98 mac_addr[2] = (sid >> 24) & 0xff;
99 mac_addr[3] = (sid >> 16) & 0xff;
100 mac_addr[4] = (sid >> 8) & 0xff;
101 mac_addr[5] = (sid >> 0) & 0xff;
103 eth_env_set_enetaddr("ethaddr", mac_addr);
110 static void meson_set_boot_source(void)
114 switch (meson_get_boot_device()) {
115 case BOOT_DEVICE_EMMC:
119 case BOOT_DEVICE_NAND:
123 case BOOT_DEVICE_SPI:
131 case BOOT_DEVICE_USB:
139 env_set("boot_source", source);
142 __weak int meson_board_late_init(void)
147 int board_late_init(void)
149 meson_set_boot_source();
151 return meson_board_late_init();
154 #if CONFIG_IS_ENABLED(FASTBOOT)
155 static unsigned int reboot_reason = REBOOT_REASON_NORMAL;
157 int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
159 if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
162 reboot_reason = REBOOT_REASON_BOOTLOADER;
164 printf("Using reboot reason: 0x%x\n", reboot_reason);
169 void reset_cpu(ulong addr)
173 regs.regs[0] = ARM_PSCI_0_2_FN_SYSTEM_RESET;
174 regs.regs[1] = reboot_reason;
176 printf("Rebooting with reason: 0x%lx\n", regs.regs[1]);
184 void reset_cpu(ulong addr)