blob: 8b953f9b397ef67f319b296fcd43b8b059692e03 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass43bd1942011-10-07 13:53:38 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glass43bd1942011-10-07 13:53:38 +00004 */
5
6#include <common.h>
Simon Glass28199612022-07-13 06:06:58 -06007#include <addr_map.h>
Simon Glass1eb69ae2019-11-14 12:57:39 -07008#include <cpu_func.h>
Simon Glass86bf6012014-02-27 13:26:13 -07009#include <cros_ec.h>
Simon Glasse2d8a712014-02-26 15:59:25 -070010#include <dm.h>
Sughosh Ganu741ef862022-04-15 11:29:34 +053011#include <efi.h>
12#include <efi_loader.h>
Patrick Delaunay4df087c2020-07-28 11:51:22 +020013#include <env_internal.h>
Simon Glass52559322019-11-14 12:57:46 -070014#include <init.h>
Patrick Delaunay17585e22018-07-27 16:37:09 +020015#include <led.h>
Matthias Weisserd99a6872011-11-29 12:16:40 +010016#include <os.h>
Simon Glass401d1c42020-10-30 21:38:53 -060017#include <asm/global_data.h>
Joe Hershberger909bd6d2015-04-21 13:57:18 -050018#include <asm/test.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070019#include <asm/u-boot-sandbox.h>
Sughosh Ganu741ef862022-04-15 11:29:34 +053020#include <linux/kernel.h>
Kory Maincent95300f22021-05-04 19:31:23 +020021#include <malloc.h>
22
23#include <extension_board.h>
Matthias Weisserd99a6872011-11-29 12:16:40 +010024
Simon Glass43bd1942011-10-07 13:53:38 +000025/*
26 * Pointer to initial global data area
27 *
28 * Here we initialize it.
29 */
30gd_t *gd;
31
Sughosh Ganu741ef862022-04-15 11:29:34 +053032#if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
Sughosh Ganu0524bfc2022-11-10 22:34:30 +053033/* GUIDs for capsule updatable firmware images */
34#define SANDBOX_UBOOT_IMAGE_GUID \
35 EFI_GUID(0x09d7cf52, 0x0720, 0x4710, 0x91, 0xd1, \
36 0x08, 0x46, 0x9b, 0x7f, 0xe9, 0xc8)
37
38#define SANDBOX_UBOOT_ENV_IMAGE_GUID \
39 EFI_GUID(0x5a7021f5, 0xfef2, 0x48b4, 0xaa, 0xba, \
40 0x83, 0x2e, 0x77, 0x74, 0x18, 0xc0)
41
42#define SANDBOX_FIT_IMAGE_GUID \
43 EFI_GUID(0x3673b45d, 0x6a7c, 0x46f3, 0x9e, 0x60, \
44 0xad, 0xab, 0xb0, 0x3f, 0x79, 0x37)
45
Sughosh Ganu741ef862022-04-15 11:29:34 +053046struct efi_fw_image fw_images[] = {
47#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)
48 {
49 .image_type_id = SANDBOX_UBOOT_IMAGE_GUID,
50 .fw_name = u"SANDBOX-UBOOT",
51 .image_index = 1,
52 },
53 {
54 .image_type_id = SANDBOX_UBOOT_ENV_IMAGE_GUID,
55 .fw_name = u"SANDBOX-UBOOT-ENV",
56 .image_index = 2,
57 },
58#elif defined(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)
59 {
60 .image_type_id = SANDBOX_FIT_IMAGE_GUID,
61 .fw_name = u"SANDBOX-FIT",
62 .image_index = 1,
63 },
64#endif
65};
66
67struct efi_capsule_update_info update_info = {
68 .dfu_string = "sf 0:0=u-boot-bin raw 0x100000 0x50000;"
69 "u-boot-env raw 0x150000 0x200000",
70 .images = fw_images,
71};
72
73u8 num_image_type_guids = ARRAY_SIZE(fw_images);
74#endif /* EFI_HAVE_CAPSULE_SUPPORT */
75
Simon Glassc1473292020-10-03 11:31:23 -060076#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass95397382021-08-07 07:24:04 -060077/*
78 * Add a simple GPIO device (don't use with of-platdata as it interferes with
79 * the auto-generated devices)
80 */
Simon Glass20e442a2020-12-28 20:34:54 -070081U_BOOT_DRVINFO(gpio_sandbox) = {
Walter Lozanoe3e24702020-06-25 01:10:04 -030082 .name = "sandbox_gpio",
Simon Glasse2d8a712014-02-26 15:59:25 -070083};
Simon Glassc1473292020-10-03 11:31:23 -060084#endif
Simon Glasse2d8a712014-02-26 15:59:25 -070085
Thomas Chou9961a0b2015-10-30 15:35:52 +080086#ifndef CONFIG_TIMER
Joe Hershberger909bd6d2015-04-21 13:57:18 -050087/* system timer offset in ms */
88static unsigned long sandbox_timer_offset;
89
Neil Armstrongd0a9b822019-04-11 17:01:23 +020090void timer_test_add_offset(unsigned long offset)
Joe Hershberger909bd6d2015-04-21 13:57:18 -050091{
92 sandbox_timer_offset += offset;
93}
94
Rob Herring28c860b2013-11-08 08:40:44 -060095unsigned long timer_read_counter(void)
Mike Frysinger6994ccf2012-02-21 00:21:17 -050096{
Joe Hershberger909bd6d2015-04-21 13:57:18 -050097 return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
Simon Glass43bd1942011-10-07 13:53:38 +000098}
Thomas Chou9961a0b2015-10-30 15:35:52 +080099#endif
Simon Glass43bd1942011-10-07 13:53:38 +0000100
Patrick Delaunay4df087c2020-07-28 11:51:22 +0200101/* specific order for sandbox: nowhere is the first value, used by default */
102static enum env_location env_locations[] = {
103 ENVL_NOWHERE,
104 ENVL_EXT4,
Heinrich Schuchardt2a38e712021-03-04 18:28:37 +0000105 ENVL_FAT,
Patrick Delaunay4df087c2020-07-28 11:51:22 +0200106};
107
108enum env_location env_get_location(enum env_operation op, int prio)
109{
110 if (prio >= ARRAY_SIZE(env_locations))
111 return ENVL_UNKNOWN;
112
113 return env_locations[prio];
114}
115
Simon Glass43bd1942011-10-07 13:53:38 +0000116int dram_init(void)
117{
Tom Riniaa6e94d2022-11-16 13:10:37 -0500118 gd->ram_size = CFG_SYS_SDRAM_SIZE;
Simon Glass43bd1942011-10-07 13:53:38 +0000119 return 0;
120}
Simon Glass86bf6012014-02-27 13:26:13 -0700121
Patrick Delaunay17585e22018-07-27 16:37:09 +0200122int board_init(void)
123{
Patrick Delaunay17585e22018-07-27 16:37:09 +0200124 return 0;
125}
126
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900127int ft_board_setup(void *fdt, struct bd_info *bd)
Heinrich Schuchardt1c0bc802020-03-14 12:13:40 +0100128{
129 /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
130 return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
131}
132
Kory Maincent95300f22021-05-04 19:31:23 +0200133#ifdef CONFIG_CMD_EXTENSION
134int extension_board_scan(struct list_head *extension_list)
135{
136 struct extension *extension;
137 int i;
138
139 for (i = 0; i < 2; i++) {
140 extension = calloc(1, sizeof(struct extension));
141 snprintf(extension->overlay, sizeof(extension->overlay), "overlay%d.dtbo", i);
142 snprintf(extension->name, sizeof(extension->name), "extension board %d", i);
143 snprintf(extension->owner, sizeof(extension->owner), "sandbox");
144 snprintf(extension->version, sizeof(extension->version), "1.1");
Heinrich Schuchardtf29f98d2022-10-16 22:17:46 +0200145 snprintf(extension->other, sizeof(extension->other), "Fictional extension board");
Kory Maincent95300f22021-05-04 19:31:23 +0200146 list_add_tail(&extension->list, extension_list);
147 }
148
149 return i;
150}
151#endif
152
Simon Glass86bf6012014-02-27 13:26:13 -0700153#ifdef CONFIG_BOARD_LATE_INIT
154int board_late_init(void)
155{
Simon Glassa2a63a32018-11-06 15:21:26 -0700156 struct udevice *dev;
157 int ret;
158
159 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
160 if (ret && ret != -ENODEV) {
Simon Glass86bf6012014-02-27 13:26:13 -0700161 /* Force console on */
162 gd->flags &= ~GD_FLG_SILENT;
163
Simon Glassa2a63a32018-11-06 15:21:26 -0700164 printf("cros-ec communications failure %d\n", ret);
Simon Glass86bf6012014-02-27 13:26:13 -0700165 puts("\nPlease reset with Power+Refresh\n\n");
166 panic("Cannot init cros-ec device");
167 return -1;
168 }
169 return 0;
170}
171#endif
Simon Glass28199612022-07-13 06:06:58 -0600172
173int init_addr_map(void)
174{
175 if (IS_ENABLED(CONFIG_ADDR_MAP))
Tom Riniaa6e94d2022-11-16 13:10:37 -0500176 addrmap_set_entry(0, 0, CFG_SYS_SDRAM_SIZE, 0);
Simon Glass28199612022-07-13 06:06:58 -0600177
178 return 0;
179}
Sughosh Ganu873cf8a2022-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