]> Git Repo - u-boot.git/blob - arch/arm/mach-meson/board-common.c
crc32: Use the crc.h header for crc functions
[u-boot.git] / arch / arm / mach-meson / board-common.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2016 Beniamino Galvani <[email protected]>
4  */
5
6 #include <common.h>
7 #include <asm/arch/boot.h>
8 #include <env.h>
9 #include <linux/libfdt.h>
10 #include <linux/err.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>
16 #include <u-boot/crc.h>
17
18 #if CONFIG_IS_ENABLED(FASTBOOT)
19 #include <asm/psci.h>
20 #include <fastboot.h>
21 #endif
22
23 DECLARE_GLOBAL_DATA_PTR;
24
25 __weak int board_init(void)
26 {
27         return 0;
28 }
29
30 int dram_init(void)
31 {
32         const fdt64_t *val;
33         int offset;
34         int len;
35
36         offset = fdt_path_offset(gd->fdt_blob, "/memory");
37         if (offset < 0)
38                 return -EINVAL;
39
40         val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
41         if (len < sizeof(*val) * 2)
42                 return -EINVAL;
43
44         /* Use unaligned access since cache is still disabled */
45         gd->ram_size = get_unaligned_be64(&val[1]);
46
47         return 0;
48 }
49
50 __weak int meson_ft_board_setup(void *blob, bd_t *bd)
51 {
52         return 0;
53 }
54
55 int ft_board_setup(void *blob, bd_t *bd)
56 {
57         meson_init_reserved_memory(blob);
58
59         return meson_ft_board_setup(blob, bd);
60 }
61
62 void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
63 {
64         int ret;
65
66         ret = fdt_add_mem_rsv(fdt, start, size);
67         if (ret)
68                 printf("Could not reserve zone @ 0x%llx\n", start);
69
70         if (IS_ENABLED(CONFIG_EFI_LOADER)) {
71                 efi_add_memory_map(start,
72                                    ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT,
73                                    EFI_RESERVED_MEMORY_TYPE, false);
74         }
75 }
76
77 int meson_generate_serial_ethaddr(void)
78 {
79         u8 mac_addr[ARP_HLEN];
80         char serial[SM_SERIAL_SIZE];
81         u32 sid;
82         u16 sid16;
83
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);
87
88                 /* Ensure the NIC specific bytes of the mac are not all 0 */
89                 if ((sid & 0xffffff) == 0)
90                         sid |= 0x800000;
91
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;
99
100                 eth_env_set_enetaddr("ethaddr", mac_addr);
101         } else
102                 return -EINVAL;
103
104         return 0;
105 }
106
107 static void meson_set_boot_source(void)
108 {
109         const char *source;
110
111         switch (meson_get_boot_device()) {
112         case BOOT_DEVICE_EMMC:
113                 source = "emmc";
114                 break;
115
116         case BOOT_DEVICE_NAND:
117                 source = "nand";
118                 break;
119
120         case BOOT_DEVICE_SPI:
121                 source = "spi";
122                 break;
123
124         case BOOT_DEVICE_SD:
125                 source = "sd";
126                 break;
127
128         case BOOT_DEVICE_USB:
129                 source = "usb";
130                 break;
131
132         default:
133                 source = "unknown";
134         }
135
136         env_set("boot_source", source);
137 }
138
139 __weak int meson_board_late_init(void)
140 {
141         return 0;
142 }
143
144 int board_late_init(void)
145 {
146         meson_set_boot_source();
147
148         return meson_board_late_init();
149 }
150
151 #if CONFIG_IS_ENABLED(FASTBOOT)
152 static unsigned int reboot_reason = REBOOT_REASON_NORMAL;
153
154 int fastboot_set_reboot_flag()
155 {
156         reboot_reason = REBOOT_REASON_BOOTLOADER;
157
158         printf("Using reboot reason: 0x%x\n", reboot_reason);
159
160         return 0;
161 }
162
163 void reset_cpu(ulong addr)
164 {
165         struct pt_regs regs;
166
167         regs.regs[0] = ARM_PSCI_0_2_FN_SYSTEM_RESET;
168         regs.regs[1] = reboot_reason;
169
170         printf("Rebooting with reason: 0x%lx\n", regs.regs[1]);
171
172         smc_call(&regs);
173
174         while (1)
175                 ;
176 }
177 #else
178 void reset_cpu(ulong addr)
179 {
180         psci_system_reset();
181 }
182 #endif
This page took 0.033258 seconds and 4 git commands to generate.