blob: 4d89f9be1cd91f013643f534fde244083b5f7f1e [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
6#include <common.h>
Simon Glassf2d59c02022-07-13 06:06:58 -06007#include <addr_map.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 Glassa7b51302019-11-14 12:57:46 -070014#include <init.h>
Patrick Delaunay29bf6032018-07-27 16:37:09 +020015#include <led.h>
Matthias Weisser0d3dd142011-11-29 12:16:40 +010016#include <os.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Joe Hershberger74961352015-04-21 13:57:18 -050018#include <asm/test.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070019#include <asm/u-boot-sandbox.h>
Sughosh Ganuccb36462022-04-15 11:29:34 +053020#include <linux/kernel.h>
Kory Maincent965a34f2021-05-04 19:31:23 +020021#include <malloc.h>
22
23#include <extension_board.h>
Matthias Weisser0d3dd142011-11-29 12:16:40 +010024
Simon Glassf1a6c762011-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 Ganuccb36462022-04-15 11:29:34 +053032#if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
33struct efi_fw_image fw_images[] = {
34#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)
35 {
36 .image_type_id = SANDBOX_UBOOT_IMAGE_GUID,
37 .fw_name = u"SANDBOX-UBOOT",
38 .image_index = 1,
39 },
40 {
41 .image_type_id = SANDBOX_UBOOT_ENV_IMAGE_GUID,
42 .fw_name = u"SANDBOX-UBOOT-ENV",
43 .image_index = 2,
44 },
45#elif defined(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)
46 {
47 .image_type_id = SANDBOX_FIT_IMAGE_GUID,
48 .fw_name = u"SANDBOX-FIT",
49 .image_index = 1,
50 },
51#endif
52};
53
54struct efi_capsule_update_info update_info = {
55 .dfu_string = "sf 0:0=u-boot-bin raw 0x100000 0x50000;"
56 "u-boot-env raw 0x150000 0x200000",
57 .images = fw_images,
58};
59
60u8 num_image_type_guids = ARRAY_SIZE(fw_images);
61#endif /* EFI_HAVE_CAPSULE_SUPPORT */
62
Simon Glasscb90bd32020-10-03 11:31:23 -060063#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass92882652021-08-07 07:24:04 -060064/*
65 * Add a simple GPIO device (don't use with of-platdata as it interferes with
66 * the auto-generated devices)
67 */
Simon Glass1d8364a2020-12-28 20:34:54 -070068U_BOOT_DRVINFO(gpio_sandbox) = {
Walter Lozano2901ac62020-06-25 01:10:04 -030069 .name = "sandbox_gpio",
Simon Glassb4d70702014-02-26 15:59:25 -070070};
Simon Glasscb90bd32020-10-03 11:31:23 -060071#endif
Simon Glassb4d70702014-02-26 15:59:25 -070072
Thomas Chou7b059dc2015-10-30 15:35:52 +080073#ifndef CONFIG_TIMER
Joe Hershberger74961352015-04-21 13:57:18 -050074/* system timer offset in ms */
75static unsigned long sandbox_timer_offset;
76
Neil Armstrong77c0dbc2019-04-11 17:01:23 +020077void timer_test_add_offset(unsigned long offset)
Joe Hershberger74961352015-04-21 13:57:18 -050078{
79 sandbox_timer_offset += offset;
80}
81
Rob Herring86bd4e82013-11-08 08:40:44 -060082unsigned long timer_read_counter(void)
Simon Glassf1a6c762011-10-07 13:53:38 +000083{
Joe Hershberger74961352015-04-21 13:57:18 -050084 return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
Simon Glassf1a6c762011-10-07 13:53:38 +000085}
Thomas Chou7b059dc2015-10-30 15:35:52 +080086#endif
Simon Glassf1a6c762011-10-07 13:53:38 +000087
Patrick Delaunayd34a6a22020-07-28 11:51:22 +020088/* specific order for sandbox: nowhere is the first value, used by default */
89static enum env_location env_locations[] = {
90 ENVL_NOWHERE,
91 ENVL_EXT4,
Heinrich Schuchardt55cbdf82021-03-04 18:28:37 +000092 ENVL_FAT,
Patrick Delaunayd34a6a22020-07-28 11:51:22 +020093};
94
95enum env_location env_get_location(enum env_operation op, int prio)
96{
97 if (prio >= ARRAY_SIZE(env_locations))
98 return ENVL_UNKNOWN;
99
100 return env_locations[prio];
101}
102
Simon Glassf1a6c762011-10-07 13:53:38 +0000103int dram_init(void)
104{
Simon Glass62cf9122013-04-26 02:53:43 +0000105 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
Simon Glassf1a6c762011-10-07 13:53:38 +0000106 return 0;
107}
Simon Glassfd173402014-02-27 13:26:13 -0700108
Patrick Delaunay29bf6032018-07-27 16:37:09 +0200109int board_init(void)
110{
Patrick Delaunay29bf6032018-07-27 16:37:09 +0200111 return 0;
112}
113
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900114int ft_board_setup(void *fdt, struct bd_info *bd)
Heinrich Schuchardta3fc9a42020-03-14 12:13:40 +0100115{
116 /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
117 return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
118}
119
Kory Maincent965a34f2021-05-04 19:31:23 +0200120#ifdef CONFIG_CMD_EXTENSION
121int extension_board_scan(struct list_head *extension_list)
122{
123 struct extension *extension;
124 int i;
125
126 for (i = 0; i < 2; i++) {
127 extension = calloc(1, sizeof(struct extension));
128 snprintf(extension->overlay, sizeof(extension->overlay), "overlay%d.dtbo", i);
129 snprintf(extension->name, sizeof(extension->name), "extension board %d", i);
130 snprintf(extension->owner, sizeof(extension->owner), "sandbox");
131 snprintf(extension->version, sizeof(extension->version), "1.1");
Heinrich Schuchardt4fae5582022-10-16 22:17:46 +0200132 snprintf(extension->other, sizeof(extension->other), "Fictional extension board");
Kory Maincent965a34f2021-05-04 19:31:23 +0200133 list_add_tail(&extension->list, extension_list);
134 }
135
136 return i;
137}
138#endif
139
Simon Glassfd173402014-02-27 13:26:13 -0700140#ifdef CONFIG_BOARD_LATE_INIT
141int board_late_init(void)
142{
Simon Glassfe3f6432018-11-06 15:21:26 -0700143 struct udevice *dev;
144 int ret;
145
146 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
147 if (ret && ret != -ENODEV) {
Simon Glassfd173402014-02-27 13:26:13 -0700148 /* Force console on */
149 gd->flags &= ~GD_FLG_SILENT;
150
Simon Glassfe3f6432018-11-06 15:21:26 -0700151 printf("cros-ec communications failure %d\n", ret);
Simon Glassfd173402014-02-27 13:26:13 -0700152 puts("\nPlease reset with Power+Refresh\n\n");
153 panic("Cannot init cros-ec device");
154 return -1;
155 }
156 return 0;
157}
158#endif
Simon Glassf2d59c02022-07-13 06:06:58 -0600159
160int init_addr_map(void)
161{
162 if (IS_ENABLED(CONFIG_ADDR_MAP))
163 addrmap_set_entry(0, 0, CONFIG_SYS_SDRAM_SIZE, 0);
164
165 return 0;
166}
Sughosh Ganu77079e72022-10-21 18:16:05 +0530167
168#if defined(CONFIG_FWU_MULTI_BANK_UPDATE)
169void fwu_plat_get_bootidx(uint *boot_idx)
170{
171 /* Dummy value */
172 *boot_idx = 0;
173}
174#endif