blob: 7ceba7cede85c6e8bca409823a3ee488cbb569b6 [file] [log] [blame]
Jerome Brunetf897c4b2018-10-05 17:00:37 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
4 */
5
6#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -07007#include <cpu_func.h>
Roman Kovalivskyi1bb13422020-07-28 23:35:32 +03008#include <fastboot.h>
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <net.h>
Neil Armstrong2fbfcbb2018-07-27 14:10:00 +020011#include <asm/arch/boot.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060012#include <env.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060015#include <asm/ptrace.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +020016#include <linux/libfdt.h>
17#include <linux/err.h>
18#include <asm/arch/mem.h>
19#include <asm/arch/sm.h>
20#include <asm/armv8/mmu.h>
21#include <asm/unaligned.h>
22#include <efi_loader.h>
Simon Glass48b6c6b2019-11-14 12:57:16 -070023#include <u-boot/crc.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +020024
Neil Armstrong1a5ed9c2019-05-22 13:30:25 +020025#include <asm/psci.h>
Neil Armstrong1a5ed9c2019-05-22 13:30:25 +020026
Jerome Brunetf897c4b2018-10-05 17:00:37 +020027DECLARE_GLOBAL_DATA_PTR;
28
Jerome Brunet5c6fa8e2018-10-24 14:57:54 +020029__weak int board_init(void)
30{
31 return 0;
32}
33
Jerome Brunetf897c4b2018-10-05 17:00:37 +020034int dram_init(void)
35{
36 const fdt64_t *val;
37 int offset;
38 int len;
39
40 offset = fdt_path_offset(gd->fdt_blob, "/memory");
41 if (offset < 0)
42 return -EINVAL;
43
44 val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
45 if (len < sizeof(*val) * 2)
46 return -EINVAL;
47
48 /* Use unaligned access since cache is still disabled */
49 gd->ram_size = get_unaligned_be64(&val[1]);
50
51 return 0;
52}
53
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090054__weak int meson_ft_board_setup(void *blob, struct bd_info *bd)
Jerome Brunet5c6fa8e2018-10-24 14:57:54 +020055{
56 return 0;
57}
58
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090059int ft_board_setup(void *blob, struct bd_info *bd)
Jerome Brunet5c6fa8e2018-10-24 14:57:54 +020060{
61 meson_init_reserved_memory(blob);
62
63 return meson_ft_board_setup(blob, bd);
64}
65
Jerome Brunetf897c4b2018-10-05 17:00:37 +020066void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
67{
68 int ret;
69
70 ret = fdt_add_mem_rsv(fdt, start, size);
71 if (ret)
72 printf("Could not reserve zone @ 0x%llx\n", start);
73
Michael Walle282d3862020-05-17 12:29:19 +020074 if (IS_ENABLED(CONFIG_EFI_LOADER))
75 efi_add_memory_map(start, size, EFI_RESERVED_MEMORY_TYPE);
Jerome Brunetf897c4b2018-10-05 17:00:37 +020076}
77
Neil Armstrongb4acf5a2019-06-12 11:49:07 +020078int meson_generate_serial_ethaddr(void)
79{
80 u8 mac_addr[ARP_HLEN];
81 char serial[SM_SERIAL_SIZE];
82 u32 sid;
83 u16 sid16;
84
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);
88
89 /* Ensure the NIC specific bytes of the mac are not all 0 */
90 if ((sid & 0xffffff) == 0)
91 sid |= 0x800000;
92
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;
100
101 eth_env_set_enetaddr("ethaddr", mac_addr);
102 } else
103 return -EINVAL;
104
105 return 0;
106}
107
Neil Armstrong2fbfcbb2018-07-27 14:10:00 +0200108static void meson_set_boot_source(void)
109{
110 const char *source;
111
112 switch (meson_get_boot_device()) {
113 case BOOT_DEVICE_EMMC:
114 source = "emmc";
115 break;
116
117 case BOOT_DEVICE_NAND:
118 source = "nand";
119 break;
120
121 case BOOT_DEVICE_SPI:
122 source = "spi";
123 break;
124
125 case BOOT_DEVICE_SD:
126 source = "sd";
127 break;
128
129 case BOOT_DEVICE_USB:
130 source = "usb";
131 break;
132
133 default:
134 source = "unknown";
135 }
136
137 env_set("boot_source", source);
138}
139
140__weak int meson_board_late_init(void)
141{
142 return 0;
143}
144
145int board_late_init(void)
146{
147 meson_set_boot_source();
148
149 return meson_board_late_init();
150}
151
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100152void reset_cpu(void)
Neil Armstrong1a5ed9c2019-05-22 13:30:25 +0200153{
Jerome Brunetf897c4b2018-10-05 17:00:37 +0200154 psci_system_reset();
155}