Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | f1a6c76 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | f1a6c76 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | f2d59c0 | 2022-07-13 06:06:58 -0600 | [diff] [blame] | 7 | #include <addr_map.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | fd17340 | 2014-02-27 13:26:13 -0700 | [diff] [blame] | 9 | #include <cros_ec.h> |
Simon Glass | b4d7070 | 2014-02-26 15:59:25 -0700 | [diff] [blame] | 10 | #include <dm.h> |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 11 | #include <efi.h> |
| 12 | #include <efi_loader.h> |
Patrick Delaunay | d34a6a2 | 2020-07-28 11:51:22 +0200 | [diff] [blame] | 13 | #include <env_internal.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 14 | #include <init.h> |
Patrick Delaunay | 29bf603 | 2018-07-27 16:37:09 +0200 | [diff] [blame] | 15 | #include <led.h> |
Matthias Weisser | 0d3dd14 | 2011-11-29 12:16:40 +0100 | [diff] [blame] | 16 | #include <os.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Joe Hershberger | 7496135 | 2015-04-21 13:57:18 -0500 | [diff] [blame] | 18 | #include <asm/test.h> |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 19 | #include <asm/u-boot-sandbox.h> |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 20 | #include <linux/kernel.h> |
Kory Maincent | 965a34f | 2021-05-04 19:31:23 +0200 | [diff] [blame] | 21 | #include <malloc.h> |
| 22 | |
| 23 | #include <extension_board.h> |
Matthias Weisser | 0d3dd14 | 2011-11-29 12:16:40 +0100 | [diff] [blame] | 24 | |
Simon Glass | f1a6c76 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 25 | /* |
| 26 | * Pointer to initial global data area |
| 27 | * |
| 28 | * Here we initialize it. |
| 29 | */ |
| 30 | gd_t *gd; |
| 31 | |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 32 | #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) |
| 33 | struct 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 | |
| 54 | struct 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 | |
| 60 | u8 num_image_type_guids = ARRAY_SIZE(fw_images); |
| 61 | #endif /* EFI_HAVE_CAPSULE_SUPPORT */ |
| 62 | |
Simon Glass | cb90bd3 | 2020-10-03 11:31:23 -0600 | [diff] [blame] | 63 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | 9288265 | 2021-08-07 07:24:04 -0600 | [diff] [blame] | 64 | /* |
| 65 | * Add a simple GPIO device (don't use with of-platdata as it interferes with |
| 66 | * the auto-generated devices) |
| 67 | */ |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 68 | U_BOOT_DRVINFO(gpio_sandbox) = { |
Walter Lozano | 2901ac6 | 2020-06-25 01:10:04 -0300 | [diff] [blame] | 69 | .name = "sandbox_gpio", |
Simon Glass | b4d7070 | 2014-02-26 15:59:25 -0700 | [diff] [blame] | 70 | }; |
Simon Glass | cb90bd3 | 2020-10-03 11:31:23 -0600 | [diff] [blame] | 71 | #endif |
Simon Glass | b4d7070 | 2014-02-26 15:59:25 -0700 | [diff] [blame] | 72 | |
Thomas Chou | 7b059dc | 2015-10-30 15:35:52 +0800 | [diff] [blame] | 73 | #ifndef CONFIG_TIMER |
Joe Hershberger | 7496135 | 2015-04-21 13:57:18 -0500 | [diff] [blame] | 74 | /* system timer offset in ms */ |
| 75 | static unsigned long sandbox_timer_offset; |
| 76 | |
Neil Armstrong | 77c0dbc | 2019-04-11 17:01:23 +0200 | [diff] [blame] | 77 | void timer_test_add_offset(unsigned long offset) |
Joe Hershberger | 7496135 | 2015-04-21 13:57:18 -0500 | [diff] [blame] | 78 | { |
| 79 | sandbox_timer_offset += offset; |
| 80 | } |
| 81 | |
Rob Herring | 86bd4e8 | 2013-11-08 08:40:44 -0600 | [diff] [blame] | 82 | unsigned long timer_read_counter(void) |
Simon Glass | f1a6c76 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 83 | { |
Joe Hershberger | 7496135 | 2015-04-21 13:57:18 -0500 | [diff] [blame] | 84 | return os_get_nsec() / 1000 + sandbox_timer_offset * 1000; |
Simon Glass | f1a6c76 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 85 | } |
Thomas Chou | 7b059dc | 2015-10-30 15:35:52 +0800 | [diff] [blame] | 86 | #endif |
Simon Glass | f1a6c76 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 87 | |
Patrick Delaunay | d34a6a2 | 2020-07-28 11:51:22 +0200 | [diff] [blame] | 88 | /* specific order for sandbox: nowhere is the first value, used by default */ |
| 89 | static enum env_location env_locations[] = { |
| 90 | ENVL_NOWHERE, |
| 91 | ENVL_EXT4, |
Heinrich Schuchardt | 55cbdf8 | 2021-03-04 18:28:37 +0000 | [diff] [blame] | 92 | ENVL_FAT, |
Patrick Delaunay | d34a6a2 | 2020-07-28 11:51:22 +0200 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | enum 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 Glass | f1a6c76 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 103 | int dram_init(void) |
| 104 | { |
Simon Glass | 62cf912 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 105 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
Simon Glass | f1a6c76 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 106 | return 0; |
| 107 | } |
Simon Glass | fd17340 | 2014-02-27 13:26:13 -0700 | [diff] [blame] | 108 | |
Patrick Delaunay | 29bf603 | 2018-07-27 16:37:09 +0200 | [diff] [blame] | 109 | int board_init(void) |
| 110 | { |
Patrick Delaunay | 29bf603 | 2018-07-27 16:37:09 +0200 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 114 | int ft_board_setup(void *fdt, struct bd_info *bd) |
Heinrich Schuchardt | a3fc9a4 | 2020-03-14 12:13:40 +0100 | [diff] [blame] | 115 | { |
| 116 | /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/ |
| 117 | return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000); |
| 118 | } |
| 119 | |
Kory Maincent | 965a34f | 2021-05-04 19:31:23 +0200 | [diff] [blame] | 120 | #ifdef CONFIG_CMD_EXTENSION |
| 121 | int 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 Schuchardt | 4fae558 | 2022-10-16 22:17:46 +0200 | [diff] [blame] | 132 | snprintf(extension->other, sizeof(extension->other), "Fictional extension board"); |
Kory Maincent | 965a34f | 2021-05-04 19:31:23 +0200 | [diff] [blame] | 133 | list_add_tail(&extension->list, extension_list); |
| 134 | } |
| 135 | |
| 136 | return i; |
| 137 | } |
| 138 | #endif |
| 139 | |
Simon Glass | fd17340 | 2014-02-27 13:26:13 -0700 | [diff] [blame] | 140 | #ifdef CONFIG_BOARD_LATE_INIT |
| 141 | int board_late_init(void) |
| 142 | { |
Simon Glass | fe3f643 | 2018-11-06 15:21:26 -0700 | [diff] [blame] | 143 | struct udevice *dev; |
| 144 | int ret; |
| 145 | |
| 146 | ret = uclass_first_device_err(UCLASS_CROS_EC, &dev); |
| 147 | if (ret && ret != -ENODEV) { |
Simon Glass | fd17340 | 2014-02-27 13:26:13 -0700 | [diff] [blame] | 148 | /* Force console on */ |
| 149 | gd->flags &= ~GD_FLG_SILENT; |
| 150 | |
Simon Glass | fe3f643 | 2018-11-06 15:21:26 -0700 | [diff] [blame] | 151 | printf("cros-ec communications failure %d\n", ret); |
Simon Glass | fd17340 | 2014-02-27 13:26:13 -0700 | [diff] [blame] | 152 | 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 Glass | f2d59c0 | 2022-07-13 06:06:58 -0600 | [diff] [blame] | 159 | |
| 160 | int 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 Ganu | 77079e7 | 2022-10-21 18:16:05 +0530 | [diff] [blame] | 167 | |
| 168 | #if defined(CONFIG_FWU_MULTI_BANK_UPDATE) |
| 169 | void fwu_plat_get_bootidx(uint *boot_idx) |
| 170 | { |
| 171 | /* Dummy value */ |
| 172 | *boot_idx = 0; |
| 173 | } |
| 174 | #endif |