blob: d97945e58fcf8ba53ad3aa0b483bd6ea7d637275 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassf1a6c762011-10-07 13:53:38 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glassf1a6c762011-10-07 13:53:38 +00004 */
5
Simon Glassf2d59c02022-07-13 06:06:58 -06006#include <addr_map.h>
Tom Riniada64ac2023-12-14 13:16:46 -05007#include <config.h>
Simon Glass63334482019-11-14 12:57:39 -07008#include <cpu_func.h>
Simon Glassfd173402014-02-27 13:26:13 -07009#include <cros_ec.h>
Simon Glassb4d70702014-02-26 15:59:25 -070010#include <dm.h>
Sughosh Ganuccb36462022-04-15 11:29:34 +053011#include <efi.h>
12#include <efi_loader.h>
Patrick Delaunayd34a6a22020-07-28 11:51:22 +020013#include <env_internal.h>
Simon Glassd68bf672023-07-15 21:39:15 -060014#include <extension_board.h>
Simon Glassa7b51302019-11-14 12:57:46 -070015#include <init.h>
Patrick Delaunay29bf6032018-07-27 16:37:09 +020016#include <led.h>
Simon Glassd68bf672023-07-15 21:39:15 -060017#include <malloc.h>
Simon Glass4d658312023-07-15 21:39:16 -060018#include <mapmem.h>
Matthias Weisser0d3dd142011-11-29 12:16:40 +010019#include <os.h>
Simon Glass4d658312023-07-15 21:39:16 -060020#include <acpi/acpi_table.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060021#include <asm/global_data.h>
Joe Hershberger74961352015-04-21 13:57:18 -050022#include <asm/test.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070023#include <asm/u-boot-sandbox.h>
Sughosh Ganuccb36462022-04-15 11:29:34 +053024#include <linux/kernel.h>
Simon Glassd68bf672023-07-15 21:39:15 -060025#include <linux/sizes.h>
Matthias Weisser0d3dd142011-11-29 12:16:40 +010026
Simon Glassf1a6c762011-10-07 13:53:38 +000027/*
28 * Pointer to initial global data area
29 *
30 * Here we initialize it.
31 */
32gd_t *gd;
33
Simon Glassb8196212023-02-05 15:39:42 -070034#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
Sughosh Ganuccb36462022-04-15 11:29:34 +053035struct efi_fw_image fw_images[] = {
36#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)
37 {
Sughosh Ganuccb36462022-04-15 11:29:34 +053038 .fw_name = u"SANDBOX-UBOOT",
39 .image_index = 1,
40 },
41 {
Sughosh Ganuccb36462022-04-15 11:29:34 +053042 .fw_name = u"SANDBOX-UBOOT-ENV",
43 .image_index = 2,
44 },
45#elif defined(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)
46 {
Sughosh Ganuccb36462022-04-15 11:29:34 +053047 .fw_name = u"SANDBOX-FIT",
48 .image_index = 1,
49 },
50#endif
51};
52
53struct 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",
Masahisa Kojima5d2438b2023-06-07 14:41:51 +090056 .num_images = ARRAY_SIZE(fw_images),
Sughosh Ganuccb36462022-04-15 11:29:34 +053057 .images = fw_images,
58};
59
Sughosh Ganuccb36462022-04-15 11:29:34 +053060#endif /* EFI_HAVE_CAPSULE_SUPPORT */
61
Simon Glasscb90bd32020-10-03 11:31:23 -060062#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass92882652021-08-07 07:24:04 -060063/*
64 * Add a simple GPIO device (don't use with of-platdata as it interferes with
65 * the auto-generated devices)
66 */
Simon Glass1d8364a2020-12-28 20:34:54 -070067U_BOOT_DRVINFO(gpio_sandbox) = {
Walter Lozano2901ac62020-06-25 01:10:04 -030068 .name = "sandbox_gpio",
Simon Glassb4d70702014-02-26 15:59:25 -070069};
Simon Glasscb90bd32020-10-03 11:31:23 -060070#endif
Simon Glassb4d70702014-02-26 15:59:25 -070071
Thomas Chou7b059dc2015-10-30 15:35:52 +080072#ifndef CONFIG_TIMER
Joe Hershberger74961352015-04-21 13:57:18 -050073/* system timer offset in ms */
74static unsigned long sandbox_timer_offset;
75
Neil Armstrong77c0dbc2019-04-11 17:01:23 +020076void timer_test_add_offset(unsigned long offset)
Joe Hershberger74961352015-04-21 13:57:18 -050077{
78 sandbox_timer_offset += offset;
79}
80
Rob Herring86bd4e82013-11-08 08:40:44 -060081unsigned long timer_read_counter(void)
Simon Glassf1a6c762011-10-07 13:53:38 +000082{
Joe Hershberger74961352015-04-21 13:57:18 -050083 return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
Simon Glassf1a6c762011-10-07 13:53:38 +000084}
Thomas Chou7b059dc2015-10-30 15:35:52 +080085#endif
Simon Glassf1a6c762011-10-07 13:53:38 +000086
Patrick Delaunayd34a6a22020-07-28 11:51:22 +020087/* specific order for sandbox: nowhere is the first value, used by default */
88static enum env_location env_locations[] = {
89 ENVL_NOWHERE,
90 ENVL_EXT4,
Heinrich Schuchardt55cbdf82021-03-04 18:28:37 +000091 ENVL_FAT,
Patrick Delaunayd34a6a22020-07-28 11:51:22 +020092};
93
94enum 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
Simon Glassf1a6c762011-10-07 13:53:38 +0000102int dram_init(void)
103{
Tom Rinibb4dd962022-11-16 13:10:37 -0500104 gd->ram_size = CFG_SYS_SDRAM_SIZE;
Simon Glassf1a6c762011-10-07 13:53:38 +0000105 return 0;
106}
Simon Glassfd173402014-02-27 13:26:13 -0700107
Patrick Delaunay29bf6032018-07-27 16:37:09 +0200108int board_init(void)
109{
Patrick Delaunay29bf6032018-07-27 16:37:09 +0200110 return 0;
111}
112
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900113int ft_board_setup(void *fdt, struct bd_info *bd)
Heinrich Schuchardta3fc9a42020-03-14 12:13:40 +0100114{
115 /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
116 return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
117}
118
Kory Maincent965a34f2021-05-04 19:31:23 +0200119#ifdef CONFIG_CMD_EXTENSION
120int extension_board_scan(struct list_head *extension_list)
121{
122 struct extension *extension;
123 int i;
124
125 for (i = 0; i < 2; i++) {
126 extension = calloc(1, sizeof(struct extension));
127 snprintf(extension->overlay, sizeof(extension->overlay), "overlay%d.dtbo", i);
128 snprintf(extension->name, sizeof(extension->name), "extension board %d", i);
129 snprintf(extension->owner, sizeof(extension->owner), "sandbox");
130 snprintf(extension->version, sizeof(extension->version), "1.1");
Heinrich Schuchardt4fae5582022-10-16 22:17:46 +0200131 snprintf(extension->other, sizeof(extension->other), "Fictional extension board");
Kory Maincent965a34f2021-05-04 19:31:23 +0200132 list_add_tail(&extension->list, extension_list);
133 }
134
135 return i;
136}
137#endif
138
Simon Glassfd173402014-02-27 13:26:13 -0700139#ifdef CONFIG_BOARD_LATE_INIT
140int board_late_init(void)
141{
Simon Glassfe3f6432018-11-06 15:21:26 -0700142 struct udevice *dev;
Simon Glass4d658312023-07-15 21:39:16 -0600143 ulong addr, end;
144 void *ptr;
Simon Glassfe3f6432018-11-06 15:21:26 -0700145 int ret;
146
147 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
148 if (ret && ret != -ENODEV) {
Simon Glassfd173402014-02-27 13:26:13 -0700149 /* Force console on */
150 gd->flags &= ~GD_FLG_SILENT;
151
Simon Glassfe3f6432018-11-06 15:21:26 -0700152 printf("cros-ec communications failure %d\n", ret);
Simon Glassfd173402014-02-27 13:26:13 -0700153 puts("\nPlease reset with Power+Refresh\n\n");
154 panic("Cannot init cros-ec device");
155 return -1;
156 }
Simon Glass4d658312023-07-15 21:39:16 -0600157
158 if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
159 /* Reserve 64K for ACPI tables, aligned to a 4K boundary */
160 ptr = memalign(SZ_4K, SZ_64K);
161 addr = map_to_sysmem(ptr);
162
163 /* Generate ACPI tables */
164 end = write_acpi_tables(addr);
165 gd->arch.table_start = addr;
166 gd->arch.table_end = addr;
167 }
168
Simon Glassfd173402014-02-27 13:26:13 -0700169 return 0;
170}
171#endif
Simon Glassf2d59c02022-07-13 06:06:58 -0600172
173int init_addr_map(void)
174{
175 if (IS_ENABLED(CONFIG_ADDR_MAP))
Tom Rinibb4dd962022-11-16 13:10:37 -0500176 addrmap_set_entry(0, 0, CFG_SYS_SDRAM_SIZE, 0);
Simon Glassf2d59c02022-07-13 06:06:58 -0600177
178 return 0;
179}
Sughosh Ganu77079e72022-10-21 18:16:05 +0530180
181#if defined(CONFIG_FWU_MULTI_BANK_UPDATE)
182void fwu_plat_get_bootidx(uint *boot_idx)
183{
184 /* Dummy value */
185 *boot_idx = 0;
186}
187#endif