1 // SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/boot.h>
12 #include <asm/cache.h>
13 #include <linux/libfdt.h>
14 #include <linux/err.h>
15 #include <asm/arch/mem.h>
16 #include <asm/arch/sm.h>
17 #include <asm/armv8/mmu.h>
18 #include <asm/unaligned.h>
19 #include <efi_loader.h>
20 #include <u-boot/crc.h>
22 #if CONFIG_IS_ENABLED(FASTBOOT)
27 DECLARE_GLOBAL_DATA_PTR;
29 __weak int board_init(void)
40 offset = fdt_path_offset(gd->fdt_blob, "/memory");
44 val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
45 if (len < sizeof(*val) * 2)
48 /* Use unaligned access since cache is still disabled */
49 gd->ram_size = get_unaligned_be64(&val[1]);
54 __weak int meson_ft_board_setup(void *blob, bd_t *bd)
59 int ft_board_setup(void *blob, bd_t *bd)
61 meson_init_reserved_memory(blob);
63 return meson_ft_board_setup(blob, bd);
66 void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
70 ret = fdt_add_mem_rsv(fdt, start, size);
72 printf("Could not reserve zone @ 0x%llx\n", start);
74 if (IS_ENABLED(CONFIG_EFI_LOADER))
75 efi_add_memory_map(start, size, EFI_RESERVED_MEMORY_TYPE);
78 int meson_generate_serial_ethaddr(void)
80 u8 mac_addr[ARP_HLEN];
81 char serial[SM_SERIAL_SIZE];
85 if (!meson_sm_get_serial(serial, SM_SERIAL_SIZE)) {
86 sid = crc32(0, (unsigned char *)serial, SM_SERIAL_SIZE);
87 sid16 = crc16_ccitt(0, (unsigned char *)serial, SM_SERIAL_SIZE);
89 /* Ensure the NIC specific bytes of the mac are not all 0 */
90 if ((sid & 0xffffff) == 0)
93 /* Non OUI / registered MAC address */
94 mac_addr[0] = ((sid16 >> 8) & 0xfc) | 0x02;
95 mac_addr[1] = (sid16 >> 0) & 0xff;
96 mac_addr[2] = (sid >> 24) & 0xff;
97 mac_addr[3] = (sid >> 16) & 0xff;
98 mac_addr[4] = (sid >> 8) & 0xff;
99 mac_addr[5] = (sid >> 0) & 0xff;
101 eth_env_set_enetaddr("ethaddr", mac_addr);
108 static void meson_set_boot_source(void)
112 switch (meson_get_boot_device()) {
113 case BOOT_DEVICE_EMMC:
117 case BOOT_DEVICE_NAND:
121 case BOOT_DEVICE_SPI:
129 case BOOT_DEVICE_USB:
137 env_set("boot_source", source);
140 __weak int meson_board_late_init(void)
145 int board_late_init(void)
147 meson_set_boot_source();
149 return meson_board_late_init();
152 #if CONFIG_IS_ENABLED(FASTBOOT)
153 static unsigned int reboot_reason = REBOOT_REASON_NORMAL;
155 int fastboot_set_reboot_flag()
157 reboot_reason = REBOOT_REASON_BOOTLOADER;
159 printf("Using reboot reason: 0x%x\n", reboot_reason);
164 void reset_cpu(ulong addr)
168 regs.regs[0] = ARM_PSCI_0_2_FN_SYSTEM_RESET;
169 regs.regs[1] = reboot_reason;
171 printf("Rebooting with reason: 0x%lx\n", regs.regs[1]);
179 void reset_cpu(ulong addr)