1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 2011 The Chromium OS Authors.
4 */
5
6 #include <addr_map.h>
7 #include <config.h>
8 #include <cpu_func.h>
9 #include <cros_ec.h>
10 #include <dm.h>
11 #include <efi.h>
12 #include <efi_loader.h>
13 #include <env_internal.h>
14 #include <extension_board.h>
15 #include <init.h>
16 #include <led.h>
17 #include <malloc.h>
18 #include <mapmem.h>
19 #include <os.h>
20 #include <acpi/acpi_table.h>
21 #include <asm/global_data.h>
22 #include <asm/test.h>
23 #include <asm/u-boot-sandbox.h>
24 #include <linux/kernel.h>
25 #include <linux/sizes.h>
26
27 /*
28 * Pointer to initial global data area
29 *
30 * Here we initialize it.
31 */
32 gd_t *gd;
33
34 #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
35 struct efi_fw_image fw_images[] = {
36 #if defined(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)
37 {
38 .fw_name = u"SANDBOX-UBOOT",
39 .image_index = 1,
40 },
41 {
42 .fw_name = u"SANDBOX-UBOOT-ENV",
43 .image_index = 2,
44 },
45 #elif defined(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)
46 {
47 .fw_name = u"SANDBOX-FIT",
48 .image_index = 1,
49 },
50 #endif
51 };
52
53 struct efi_capsule_update_info update_info = {
54 .dfu_string = "sf 0:0=u-boot-bin raw 0x100000 0x50000;"
55 "u-boot-env raw 0x150000 0x200000",
56 .num_images = ARRAY_SIZE(fw_images),
57 .images = fw_images,
58 };
59
60 #endif /* EFI_HAVE_CAPSULE_SUPPORT */
61
62 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
63 /*
64 * Add a simple GPIO device (don't use with of-platdata as it interferes with
65 * the auto-generated devices)
66 */
67 U_BOOT_DRVINFO(gpio_sandbox) = {
68 .name = "sandbox_gpio",
69 };
70 #endif
71
72 #ifndef CONFIG_TIMER
73 /* system timer offset in ms */
74 static unsigned long sandbox_timer_offset;
75
timer_test_add_offset(unsigned long offset)76 void timer_test_add_offset(unsigned long offset)
77 {
78 sandbox_timer_offset += offset;
79 }
80
timer_read_counter(void)81 unsigned long timer_read_counter(void)
82 {
83 return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
84 }
85 #endif
86
87 /* specific order for sandbox: nowhere is the first value, used by default */
88 static enum env_location env_locations[] = {
89 ENVL_NOWHERE,
90 ENVL_EXT4,
91 ENVL_FAT,
92 };
93
env_get_location(enum env_operation op,int prio)94 enum env_location env_get_location(enum env_operation op, int prio)
95 {
96 if (prio >= ARRAY_SIZE(env_locations))
97 return ENVL_UNKNOWN;
98
99 return env_locations[prio];
100 }
101
dram_init(void)102 int dram_init(void)
103 {
104 return 0;
105 }
106
ft_board_setup(void * fdt,struct bd_info * bd)107 int ft_board_setup(void *fdt, struct bd_info *bd)
108 {
109 /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
110 return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
111 }
112
113 #ifdef CONFIG_CMD_EXTENSION
extension_board_scan(struct list_head * extension_list)114 int extension_board_scan(struct list_head *extension_list)
115 {
116 struct extension *extension;
117 int i;
118
119 for (i = 0; i < 2; i++) {
120 extension = calloc(1, sizeof(struct extension));
121 snprintf(extension->overlay, sizeof(extension->overlay), "overlay%d.dtbo", i);
122 snprintf(extension->name, sizeof(extension->name), "extension board %d", i);
123 snprintf(extension->owner, sizeof(extension->owner), "sandbox");
124 snprintf(extension->version, sizeof(extension->version), "1.1");
125 snprintf(extension->other, sizeof(extension->other), "Fictional extension board");
126 list_add_tail(&extension->list, extension_list);
127 }
128
129 return i;
130 }
131 #endif
132
133 #ifdef CONFIG_BOARD_LATE_INIT
board_late_init(void)134 int board_late_init(void)
135 {
136 struct udevice *dev;
137 ulong addr, end;
138 void *ptr;
139 int ret;
140
141 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
142 if (ret && ret != -ENODEV) {
143 /* Force console on */
144 gd->flags &= ~GD_FLG_SILENT;
145
146 printf("cros-ec communications failure %d\n", ret);
147 puts("\nPlease reset with Power+Refresh\n\n");
148 panic("Cannot init cros-ec device");
149 return -1;
150 }
151
152 if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
153 /* Reserve 64K for ACPI tables, aligned to a 4K boundary */
154 ptr = memalign(SZ_4K, SZ_64K);
155 addr = map_to_sysmem(ptr);
156
157 /* Generate ACPI tables */
158 end = write_acpi_tables(addr);
159 gd->arch.table_start = addr;
160 gd->arch.table_end = addr;
161 }
162
163 return 0;
164 }
165 #endif
166
init_addr_map(void)167 int init_addr_map(void)
168 {
169 if (IS_ENABLED(CONFIG_ADDR_MAP))
170 addrmap_set_entry(0, 0, CFG_SYS_SDRAM_SIZE, 0);
171
172 return 0;
173 }
174
175 #if defined(CONFIG_FWU_MULTI_BANK_UPDATE)
fwu_plat_get_bootidx(uint * boot_idx)176 void fwu_plat_get_bootidx(uint *boot_idx)
177 {
178 /* Dummy value */
179 *boot_idx = 0;
180 }
181 #endif
182