Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 43bd194 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | 43bd194 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 2819961 | 2022-07-13 06:06:58 -0600 | [diff] [blame] | 7 | #include <addr_map.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | 86bf601 | 2014-02-27 13:26:13 -0700 | [diff] [blame] | 9 | #include <cros_ec.h> |
Simon Glass | e2d8a71 | 2014-02-26 15:59:25 -0700 | [diff] [blame] | 10 | #include <dm.h> |
Sughosh Ganu | 741ef86 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 11 | #include <efi.h> |
| 12 | #include <efi_loader.h> |
Patrick Delaunay | 4df087c | 2020-07-28 11:51:22 +0200 | [diff] [blame] | 13 | #include <env_internal.h> |
Simon Glass | f52a7f0 | 2023-07-15 21:39:15 -0600 | [diff] [blame] | 14 | #include <extension_board.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 15 | #include <init.h> |
Patrick Delaunay | 17585e2 | 2018-07-27 16:37:09 +0200 | [diff] [blame] | 16 | #include <led.h> |
Simon Glass | f52a7f0 | 2023-07-15 21:39:15 -0600 | [diff] [blame] | 17 | #include <malloc.h> |
Simon Glass | 92ccaf7 | 2023-07-15 21:39:16 -0600 | [diff] [blame] | 18 | #include <mapmem.h> |
Matthias Weisser | d99a687 | 2011-11-29 12:16:40 +0100 | [diff] [blame] | 19 | #include <os.h> |
Simon Glass | 92ccaf7 | 2023-07-15 21:39:16 -0600 | [diff] [blame] | 20 | #include <acpi/acpi_table.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 21 | #include <asm/global_data.h> |
Joe Hershberger | 909bd6d | 2015-04-21 13:57:18 -0500 | [diff] [blame] | 22 | #include <asm/test.h> |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 23 | #include <asm/u-boot-sandbox.h> |
Sughosh Ganu | 741ef86 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 24 | #include <linux/kernel.h> |
Simon Glass | f52a7f0 | 2023-07-15 21:39:15 -0600 | [diff] [blame] | 25 | #include <linux/sizes.h> |
Matthias Weisser | d99a687 | 2011-11-29 12:16:40 +0100 | [diff] [blame] | 26 | |
Simon Glass | 43bd194 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 27 | /* |
| 28 | * Pointer to initial global data area |
| 29 | * |
| 30 | * Here we initialize it. |
| 31 | */ |
| 32 | gd_t *gd; |
| 33 | |
Simon Glass | 71aa806 | 2023-02-05 15:39:42 -0700 | [diff] [blame] | 34 | #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) |
Sughosh Ganu | 0524bfc | 2022-11-10 22:34:30 +0530 | [diff] [blame] | 35 | /* GUIDs for capsule updatable firmware images */ |
| 36 | #define SANDBOX_UBOOT_IMAGE_GUID \ |
| 37 | EFI_GUID(0x09d7cf52, 0x0720, 0x4710, 0x91, 0xd1, \ |
| 38 | 0x08, 0x46, 0x9b, 0x7f, 0xe9, 0xc8) |
| 39 | |
| 40 | #define SANDBOX_UBOOT_ENV_IMAGE_GUID \ |
| 41 | EFI_GUID(0x5a7021f5, 0xfef2, 0x48b4, 0xaa, 0xba, \ |
| 42 | 0x83, 0x2e, 0x77, 0x74, 0x18, 0xc0) |
| 43 | |
| 44 | #define SANDBOX_FIT_IMAGE_GUID \ |
| 45 | EFI_GUID(0x3673b45d, 0x6a7c, 0x46f3, 0x9e, 0x60, \ |
| 46 | 0xad, 0xab, 0xb0, 0x3f, 0x79, 0x37) |
| 47 | |
Sughosh Ganu | 741ef86 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 48 | struct efi_fw_image fw_images[] = { |
| 49 | #if defined(CONFIG_EFI_CAPSULE_FIRMWARE_RAW) |
| 50 | { |
| 51 | .image_type_id = SANDBOX_UBOOT_IMAGE_GUID, |
| 52 | .fw_name = u"SANDBOX-UBOOT", |
| 53 | .image_index = 1, |
| 54 | }, |
| 55 | { |
| 56 | .image_type_id = SANDBOX_UBOOT_ENV_IMAGE_GUID, |
| 57 | .fw_name = u"SANDBOX-UBOOT-ENV", |
| 58 | .image_index = 2, |
| 59 | }, |
| 60 | #elif defined(CONFIG_EFI_CAPSULE_FIRMWARE_FIT) |
| 61 | { |
| 62 | .image_type_id = SANDBOX_FIT_IMAGE_GUID, |
| 63 | .fw_name = u"SANDBOX-FIT", |
| 64 | .image_index = 1, |
| 65 | }, |
| 66 | #endif |
| 67 | }; |
| 68 | |
| 69 | struct efi_capsule_update_info update_info = { |
| 70 | .dfu_string = "sf 0:0=u-boot-bin raw 0x100000 0x50000;" |
| 71 | "u-boot-env raw 0x150000 0x200000", |
Masahisa Kojima | cccea18 | 2023-06-07 14:41:51 +0900 | [diff] [blame] | 72 | .num_images = ARRAY_SIZE(fw_images), |
Sughosh Ganu | 741ef86 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 73 | .images = fw_images, |
| 74 | }; |
| 75 | |
Sughosh Ganu | 741ef86 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 76 | #endif /* EFI_HAVE_CAPSULE_SUPPORT */ |
| 77 | |
Simon Glass | c147329 | 2020-10-03 11:31:23 -0600 | [diff] [blame] | 78 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | 9539738 | 2021-08-07 07:24:04 -0600 | [diff] [blame] | 79 | /* |
| 80 | * Add a simple GPIO device (don't use with of-platdata as it interferes with |
| 81 | * the auto-generated devices) |
| 82 | */ |
Simon Glass | 20e442a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 83 | U_BOOT_DRVINFO(gpio_sandbox) = { |
Walter Lozano | e3e2470 | 2020-06-25 01:10:04 -0300 | [diff] [blame] | 84 | .name = "sandbox_gpio", |
Simon Glass | e2d8a71 | 2014-02-26 15:59:25 -0700 | [diff] [blame] | 85 | }; |
Simon Glass | c147329 | 2020-10-03 11:31:23 -0600 | [diff] [blame] | 86 | #endif |
Simon Glass | e2d8a71 | 2014-02-26 15:59:25 -0700 | [diff] [blame] | 87 | |
Thomas Chou | 9961a0b | 2015-10-30 15:35:52 +0800 | [diff] [blame] | 88 | #ifndef CONFIG_TIMER |
Joe Hershberger | 909bd6d | 2015-04-21 13:57:18 -0500 | [diff] [blame] | 89 | /* system timer offset in ms */ |
| 90 | static unsigned long sandbox_timer_offset; |
| 91 | |
Neil Armstrong | d0a9b82 | 2019-04-11 17:01:23 +0200 | [diff] [blame] | 92 | void timer_test_add_offset(unsigned long offset) |
Joe Hershberger | 909bd6d | 2015-04-21 13:57:18 -0500 | [diff] [blame] | 93 | { |
| 94 | sandbox_timer_offset += offset; |
| 95 | } |
| 96 | |
Rob Herring | 28c860b | 2013-11-08 08:40:44 -0600 | [diff] [blame] | 97 | unsigned long timer_read_counter(void) |
Mike Frysinger | 6994ccf | 2012-02-21 00:21:17 -0500 | [diff] [blame] | 98 | { |
Joe Hershberger | 909bd6d | 2015-04-21 13:57:18 -0500 | [diff] [blame] | 99 | return os_get_nsec() / 1000 + sandbox_timer_offset * 1000; |
Simon Glass | 43bd194 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 100 | } |
Thomas Chou | 9961a0b | 2015-10-30 15:35:52 +0800 | [diff] [blame] | 101 | #endif |
Simon Glass | 43bd194 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 102 | |
Patrick Delaunay | 4df087c | 2020-07-28 11:51:22 +0200 | [diff] [blame] | 103 | /* specific order for sandbox: nowhere is the first value, used by default */ |
| 104 | static enum env_location env_locations[] = { |
| 105 | ENVL_NOWHERE, |
| 106 | ENVL_EXT4, |
Heinrich Schuchardt | 2a38e71 | 2021-03-04 18:28:37 +0000 | [diff] [blame] | 107 | ENVL_FAT, |
Patrick Delaunay | 4df087c | 2020-07-28 11:51:22 +0200 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | enum env_location env_get_location(enum env_operation op, int prio) |
| 111 | { |
| 112 | if (prio >= ARRAY_SIZE(env_locations)) |
| 113 | return ENVL_UNKNOWN; |
| 114 | |
| 115 | return env_locations[prio]; |
| 116 | } |
| 117 | |
Simon Glass | 43bd194 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 118 | int dram_init(void) |
| 119 | { |
Tom Rini | aa6e94d | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 120 | gd->ram_size = CFG_SYS_SDRAM_SIZE; |
Simon Glass | 43bd194 | 2011-10-07 13:53:38 +0000 | [diff] [blame] | 121 | return 0; |
| 122 | } |
Simon Glass | 86bf601 | 2014-02-27 13:26:13 -0700 | [diff] [blame] | 123 | |
Patrick Delaunay | 17585e2 | 2018-07-27 16:37:09 +0200 | [diff] [blame] | 124 | int board_init(void) |
| 125 | { |
Patrick Delaunay | 17585e2 | 2018-07-27 16:37:09 +0200 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 129 | int ft_board_setup(void *fdt, struct bd_info *bd) |
Heinrich Schuchardt | 1c0bc80 | 2020-03-14 12:13:40 +0100 | [diff] [blame] | 130 | { |
| 131 | /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/ |
| 132 | return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000); |
| 133 | } |
| 134 | |
Kory Maincent | 95300f2 | 2021-05-04 19:31:23 +0200 | [diff] [blame] | 135 | #ifdef CONFIG_CMD_EXTENSION |
| 136 | int extension_board_scan(struct list_head *extension_list) |
| 137 | { |
| 138 | struct extension *extension; |
| 139 | int i; |
| 140 | |
| 141 | for (i = 0; i < 2; i++) { |
| 142 | extension = calloc(1, sizeof(struct extension)); |
| 143 | snprintf(extension->overlay, sizeof(extension->overlay), "overlay%d.dtbo", i); |
| 144 | snprintf(extension->name, sizeof(extension->name), "extension board %d", i); |
| 145 | snprintf(extension->owner, sizeof(extension->owner), "sandbox"); |
| 146 | snprintf(extension->version, sizeof(extension->version), "1.1"); |
Heinrich Schuchardt | f29f98d | 2022-10-16 22:17:46 +0200 | [diff] [blame] | 147 | snprintf(extension->other, sizeof(extension->other), "Fictional extension board"); |
Kory Maincent | 95300f2 | 2021-05-04 19:31:23 +0200 | [diff] [blame] | 148 | list_add_tail(&extension->list, extension_list); |
| 149 | } |
| 150 | |
| 151 | return i; |
| 152 | } |
| 153 | #endif |
| 154 | |
Simon Glass | 86bf601 | 2014-02-27 13:26:13 -0700 | [diff] [blame] | 155 | #ifdef CONFIG_BOARD_LATE_INIT |
| 156 | int board_late_init(void) |
| 157 | { |
Simon Glass | a2a63a3 | 2018-11-06 15:21:26 -0700 | [diff] [blame] | 158 | struct udevice *dev; |
Simon Glass | 92ccaf7 | 2023-07-15 21:39:16 -0600 | [diff] [blame] | 159 | ulong addr, end; |
| 160 | void *ptr; |
Simon Glass | a2a63a3 | 2018-11-06 15:21:26 -0700 | [diff] [blame] | 161 | int ret; |
| 162 | |
| 163 | ret = uclass_first_device_err(UCLASS_CROS_EC, &dev); |
| 164 | if (ret && ret != -ENODEV) { |
Simon Glass | 86bf601 | 2014-02-27 13:26:13 -0700 | [diff] [blame] | 165 | /* Force console on */ |
| 166 | gd->flags &= ~GD_FLG_SILENT; |
| 167 | |
Simon Glass | a2a63a3 | 2018-11-06 15:21:26 -0700 | [diff] [blame] | 168 | printf("cros-ec communications failure %d\n", ret); |
Simon Glass | 86bf601 | 2014-02-27 13:26:13 -0700 | [diff] [blame] | 169 | puts("\nPlease reset with Power+Refresh\n\n"); |
| 170 | panic("Cannot init cros-ec device"); |
| 171 | return -1; |
| 172 | } |
Simon Glass | 92ccaf7 | 2023-07-15 21:39:16 -0600 | [diff] [blame] | 173 | |
| 174 | if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) { |
| 175 | /* Reserve 64K for ACPI tables, aligned to a 4K boundary */ |
| 176 | ptr = memalign(SZ_4K, SZ_64K); |
| 177 | addr = map_to_sysmem(ptr); |
| 178 | |
| 179 | /* Generate ACPI tables */ |
| 180 | end = write_acpi_tables(addr); |
| 181 | gd->arch.table_start = addr; |
| 182 | gd->arch.table_end = addr; |
| 183 | } |
| 184 | |
Simon Glass | 86bf601 | 2014-02-27 13:26:13 -0700 | [diff] [blame] | 185 | return 0; |
| 186 | } |
| 187 | #endif |
Simon Glass | 2819961 | 2022-07-13 06:06:58 -0600 | [diff] [blame] | 188 | |
| 189 | int init_addr_map(void) |
| 190 | { |
| 191 | if (IS_ENABLED(CONFIG_ADDR_MAP)) |
Tom Rini | aa6e94d | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 192 | addrmap_set_entry(0, 0, CFG_SYS_SDRAM_SIZE, 0); |
Simon Glass | 2819961 | 2022-07-13 06:06:58 -0600 | [diff] [blame] | 193 | |
| 194 | return 0; |
| 195 | } |
Sughosh Ganu | 873cf8a | 2022-10-21 18:16:05 +0530 | [diff] [blame] | 196 | |
| 197 | #if defined(CONFIG_FWU_MULTI_BANK_UPDATE) |
| 198 | void fwu_plat_get_bootidx(uint *boot_idx) |
| 199 | { |
| 200 | /* Dummy value */ |
| 201 | *boot_idx = 0; |
| 202 | } |
| 203 | #endif |