blob: 4d89f9be1cd91f013643f534fde244083b5f7f1e [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)
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 Glassc1473292020-10-03 11:31:23 -060063#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass95397382021-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 Glass20e442a2020-12-28 20:34:54 -070068U_BOOT_DRVINFO(gpio_sandbox) = {
Walter Lozanoe3e24702020-06-25 01:10:04 -030069 .name = "sandbox_gpio",
Simon Glasse2d8a712014-02-26 15:59:25 -070070};
Simon Glassc1473292020-10-03 11:31:23 -060071#endif
Simon Glasse2d8a712014-02-26 15:59:25 -070072
Thomas Chou9961a0b2015-10-30 15:35:52 +080073#ifndef CONFIG_TIMER
Joe Hershberger909bd6d2015-04-21 13:57:18 -050074/* system timer offset in ms */
75static unsigned long sandbox_timer_offset;
76
Neil Armstrongd0a9b822019-04-11 17:01:23 +020077void timer_test_add_offset(unsigned long offset)
Joe Hershberger909bd6d2015-04-21 13:57:18 -050078{
79 sandbox_timer_offset += offset;
80}
81
Rob Herring28c860b2013-11-08 08:40:44 -060082unsigned long timer_read_counter(void)
Mike Frysinger6994ccf2012-02-21 00:21:17 -050083{
Joe Hershberger909bd6d2015-04-21 13:57:18 -050084 return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
Simon Glass43bd1942011-10-07 13:53:38 +000085}
Thomas Chou9961a0b2015-10-30 15:35:52 +080086#endif
Simon Glass43bd1942011-10-07 13:53:38 +000087
Patrick Delaunay4df087c2020-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 Schuchardt2a38e712021-03-04 18:28:37 +000092 ENVL_FAT,
Patrick Delaunay4df087c2020-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 Glass43bd1942011-10-07 13:53:38 +0000103int dram_init(void)
104{
Simon Glassa733b062013-04-26 02:53:43 +0000105 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
Simon Glass43bd1942011-10-07 13:53:38 +0000106 return 0;
107}
Simon Glass86bf6012014-02-27 13:26:13 -0700108
Patrick Delaunay17585e22018-07-27 16:37:09 +0200109int board_init(void)
110{
Patrick Delaunay17585e22018-07-27 16:37:09 +0200111 return 0;
112}
113
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900114int ft_board_setup(void *fdt, struct bd_info *bd)
Heinrich Schuchardt1c0bc802020-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 Maincent95300f22021-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 Schuchardtf29f98d2022-10-16 22:17:46 +0200132 snprintf(extension->other, sizeof(extension->other), "Fictional extension board");
Kory Maincent95300f22021-05-04 19:31:23 +0200133 list_add_tail(&extension->list, extension_list);
134 }
135
136 return i;
137}
138#endif
139
Simon Glass86bf6012014-02-27 13:26:13 -0700140#ifdef CONFIG_BOARD_LATE_INIT
141int board_late_init(void)
142{
Simon Glassa2a63a32018-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 Glass86bf6012014-02-27 13:26:13 -0700148 /* Force console on */
149 gd->flags &= ~GD_FLG_SILENT;
150
Simon Glassa2a63a32018-11-06 15:21:26 -0700151 printf("cros-ec communications failure %d\n", ret);
Simon Glass86bf6012014-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 Glass28199612022-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 Ganu873cf8a2022-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