1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
10 #include <asm/arch/boot.h>
12 #include <asm/cache.h>
13 #include <asm/global_data.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>
26 DECLARE_GLOBAL_DATA_PTR;
28 __weak int board_init(void)
39 offset = fdt_path_offset(gd->fdt_blob, "/memory");
43 val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
44 if (len < sizeof(*val) * 2)
47 /* Use unaligned access since cache is still disabled */
48 gd->ram_size = get_unaligned_be64(&val[1]);
53 __weak int meson_ft_board_setup(void *blob, struct bd_info *bd)
58 int ft_board_setup(void *blob, struct bd_info *bd)
60 meson_init_reserved_memory(blob);
62 return meson_ft_board_setup(blob, bd);
65 void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
69 ret = fdt_add_mem_rsv(fdt, start, size);
71 printf("Could not reserve zone @ 0x%llx\n", start);
73 if (IS_ENABLED(CONFIG_EFI_LOADER))
74 efi_add_memory_map(start, size, EFI_RESERVED_MEMORY_TYPE);
77 int meson_generate_serial_ethaddr(void)
79 u8 mac_addr[ARP_HLEN];
80 char serial[SM_SERIAL_SIZE];
84 if (!meson_sm_get_serial(serial, SM_SERIAL_SIZE)) {
85 sid = crc32(0, (unsigned char *)serial, SM_SERIAL_SIZE);
86 sid16 = crc16_ccitt(0, (unsigned char *)serial, SM_SERIAL_SIZE);
88 /* Ensure the NIC specific bytes of the mac are not all 0 */
89 if ((sid & 0xffffff) == 0)
92 /* Non OUI / registered MAC address */
93 mac_addr[0] = ((sid16 >> 8) & 0xfc) | 0x02;
94 mac_addr[1] = (sid16 >> 0) & 0xff;
95 mac_addr[2] = (sid >> 24) & 0xff;
96 mac_addr[3] = (sid >> 16) & 0xff;
97 mac_addr[4] = (sid >> 8) & 0xff;
98 mac_addr[5] = (sid >> 0) & 0xff;
100 eth_env_set_enetaddr("ethaddr", mac_addr);
107 static void meson_set_boot_source(void)
111 switch (meson_get_boot_device()) {
112 case BOOT_DEVICE_EMMC:
116 case BOOT_DEVICE_NAND:
120 case BOOT_DEVICE_SPI:
128 case BOOT_DEVICE_USB:
136 env_set("boot_source", source);
139 __weak int meson_board_late_init(void)
144 int board_late_init(void)
146 meson_set_boot_source();
148 return meson_board_late_init();