1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
7 #include <asm/arch/boot.h>
8 #include <linux/libfdt.h>
10 #include <environment.h>
11 #include <asm/arch/mem.h>
12 #include <asm/arch/sm.h>
13 #include <asm/armv8/mmu.h>
14 #include <asm/unaligned.h>
15 #include <efi_loader.h>
17 DECLARE_GLOBAL_DATA_PTR;
19 __weak int board_init(void)
30 offset = fdt_path_offset(gd->fdt_blob, "/memory");
34 val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
35 if (len < sizeof(*val) * 2)
38 /* Use unaligned access since cache is still disabled */
39 gd->ram_size = get_unaligned_be64(&val[1]);
44 __weak int meson_ft_board_setup(void *blob, bd_t *bd)
49 int ft_board_setup(void *blob, bd_t *bd)
51 meson_init_reserved_memory(blob);
53 return meson_ft_board_setup(blob, bd);
56 void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
60 ret = fdt_add_mem_rsv(fdt, start, size);
62 printf("Could not reserve zone @ 0x%llx\n", start);
64 if (IS_ENABLED(CONFIG_EFI_LOADER)) {
65 efi_add_memory_map(start,
66 ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT,
67 EFI_RESERVED_MEMORY_TYPE, false);
71 int meson_generate_serial_ethaddr(void)
73 u8 mac_addr[ARP_HLEN];
74 char serial[SM_SERIAL_SIZE];
78 if (!meson_sm_get_serial(serial, SM_SERIAL_SIZE)) {
79 sid = crc32(0, (unsigned char *)serial, SM_SERIAL_SIZE);
80 sid16 = crc16_ccitt(0, (unsigned char *)serial, SM_SERIAL_SIZE);
82 /* Ensure the NIC specific bytes of the mac are not all 0 */
83 if ((sid & 0xffffff) == 0)
86 /* Non OUI / registered MAC address */
87 mac_addr[0] = ((sid16 >> 8) & 0xfc) | 0x02;
88 mac_addr[1] = (sid16 >> 0) & 0xff;
89 mac_addr[2] = (sid >> 24) & 0xff;
90 mac_addr[3] = (sid >> 16) & 0xff;
91 mac_addr[4] = (sid >> 8) & 0xff;
92 mac_addr[5] = (sid >> 0) & 0xff;
94 eth_env_set_enetaddr("ethaddr", mac_addr);
101 static void meson_set_boot_source(void)
105 switch (meson_get_boot_device()) {
106 case BOOT_DEVICE_EMMC:
110 case BOOT_DEVICE_NAND:
114 case BOOT_DEVICE_SPI:
122 case BOOT_DEVICE_USB:
130 env_set("boot_source", source);
133 __weak int meson_board_late_init(void)
138 int board_late_init(void)
140 meson_set_boot_source();
142 return meson_board_late_init();
145 void reset_cpu(ulong addr)