blob: e054f300c4a5dadf7064ebf3ced81f7a3ddfaad8 [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 Glass1eb69ae2019-11-14 12:57:39 -07007#include <cpu_func.h>
Simon Glass86bf6012014-02-27 13:26:13 -07008#include <cros_ec.h>
Simon Glasse2d8a712014-02-26 15:59:25 -07009#include <dm.h>
Sughosh Ganu741ef862022-04-15 11:29:34 +053010#include <efi.h>
11#include <efi_loader.h>
Patrick Delaunay4df087c2020-07-28 11:51:22 +020012#include <env_internal.h>
Simon Glass52559322019-11-14 12:57:46 -070013#include <init.h>
Patrick Delaunay17585e22018-07-27 16:37:09 +020014#include <led.h>
Matthias Weisserd99a6872011-11-29 12:16:40 +010015#include <os.h>
Simon Glass401d1c42020-10-30 21:38:53 -060016#include <asm/global_data.h>
Joe Hershberger909bd6d2015-04-21 13:57:18 -050017#include <asm/test.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070018#include <asm/u-boot-sandbox.h>
Sughosh Ganu741ef862022-04-15 11:29:34 +053019#include <linux/kernel.h>
Kory Maincent95300f22021-05-04 19:31:23 +020020#include <malloc.h>
21
22#include <extension_board.h>
Matthias Weisserd99a6872011-11-29 12:16:40 +010023
Simon Glass43bd1942011-10-07 13:53:38 +000024/*
25 * Pointer to initial global data area
26 *
27 * Here we initialize it.
28 */
29gd_t *gd;
30
Sughosh Ganu741ef862022-04-15 11:29:34 +053031#if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
32struct efi_fw_image fw_images[] = {
33#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)
34 {
35 .image_type_id = SANDBOX_UBOOT_IMAGE_GUID,
36 .fw_name = u"SANDBOX-UBOOT",
37 .image_index = 1,
38 },
39 {
40 .image_type_id = SANDBOX_UBOOT_ENV_IMAGE_GUID,
41 .fw_name = u"SANDBOX-UBOOT-ENV",
42 .image_index = 2,
43 },
44#elif defined(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)
45 {
46 .image_type_id = SANDBOX_FIT_IMAGE_GUID,
47 .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",
56 .images = fw_images,
57};
58
59u8 num_image_type_guids = ARRAY_SIZE(fw_images);
60#endif /* EFI_HAVE_CAPSULE_SUPPORT */
61
Simon Glassc1473292020-10-03 11:31:23 -060062#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass95397382021-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 Glass20e442a2020-12-28 20:34:54 -070067U_BOOT_DRVINFO(gpio_sandbox) = {
Walter Lozanoe3e24702020-06-25 01:10:04 -030068 .name = "sandbox_gpio",
Simon Glasse2d8a712014-02-26 15:59:25 -070069};
Simon Glassc1473292020-10-03 11:31:23 -060070#endif
Simon Glasse2d8a712014-02-26 15:59:25 -070071
Thomas Chou9961a0b2015-10-30 15:35:52 +080072#ifndef CONFIG_TIMER
Joe Hershberger909bd6d2015-04-21 13:57:18 -050073/* system timer offset in ms */
74static unsigned long sandbox_timer_offset;
75
Neil Armstrongd0a9b822019-04-11 17:01:23 +020076void timer_test_add_offset(unsigned long offset)
Joe Hershberger909bd6d2015-04-21 13:57:18 -050077{
78 sandbox_timer_offset += offset;
79}
80
Rob Herring28c860b2013-11-08 08:40:44 -060081unsigned long timer_read_counter(void)
Mike Frysinger6994ccf2012-02-21 00:21:17 -050082{
Joe Hershberger909bd6d2015-04-21 13:57:18 -050083 return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
Simon Glass43bd1942011-10-07 13:53:38 +000084}
Thomas Chou9961a0b2015-10-30 15:35:52 +080085#endif
Simon Glass43bd1942011-10-07 13:53:38 +000086
Patrick Delaunay4df087c2020-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 Schuchardt2a38e712021-03-04 18:28:37 +000091 ENVL_FAT,
Patrick Delaunay4df087c2020-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 Glass43bd1942011-10-07 13:53:38 +0000102int dram_init(void)
103{
Simon Glassa733b062013-04-26 02:53:43 +0000104 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
Simon Glass43bd1942011-10-07 13:53:38 +0000105 return 0;
106}
Simon Glass86bf6012014-02-27 13:26:13 -0700107
Patrick Delaunay17585e22018-07-27 16:37:09 +0200108int board_init(void)
109{
Patrick Delaunay17585e22018-07-27 16:37:09 +0200110 return 0;
111}
112
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900113int ft_board_setup(void *fdt, struct bd_info *bd)
Heinrich Schuchardt1c0bc802020-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 Maincent95300f22021-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");
131 snprintf(extension->other, sizeof(extension->other), "Fictionnal extension board");
132 list_add_tail(&extension->list, extension_list);
133 }
134
135 return i;
136}
137#endif
138
Simon Glass86bf6012014-02-27 13:26:13 -0700139#ifdef CONFIG_BOARD_LATE_INIT
140int board_late_init(void)
141{
Simon Glassa2a63a32018-11-06 15:21:26 -0700142 struct udevice *dev;
143 int ret;
144
145 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
146 if (ret && ret != -ENODEV) {
Simon Glass86bf6012014-02-27 13:26:13 -0700147 /* Force console on */
148 gd->flags &= ~GD_FLG_SILENT;
149
Simon Glassa2a63a32018-11-06 15:21:26 -0700150 printf("cros-ec communications failure %d\n", ret);
Simon Glass86bf6012014-02-27 13:26:13 -0700151 puts("\nPlease reset with Power+Refresh\n\n");
152 panic("Cannot init cros-ec device");
153 return -1;
154 }
155 return 0;
156}
157#endif