sandbox: typo Fictionnal
[platform/kernel/u-boot.git] / board / sandbox / sandbox.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2011 The Chromium OS Authors.
4  */
5
6 #include <common.h>
7 #include <addr_map.h>
8 #include <cpu_func.h>
9 #include <cros_ec.h>
10 #include <dm.h>
11 #include <efi.h>
12 #include <efi_loader.h>
13 #include <env_internal.h>
14 #include <init.h>
15 #include <led.h>
16 #include <os.h>
17 #include <asm/global_data.h>
18 #include <asm/test.h>
19 #include <asm/u-boot-sandbox.h>
20 #include <linux/kernel.h>
21 #include <malloc.h>
22
23 #include <extension_board.h>
24
25 /*
26  * Pointer to initial global data area
27  *
28  * Here we initialize it.
29  */
30 gd_t *gd;
31
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
63 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
64 /*
65  * Add a simple GPIO device (don't use with of-platdata as it interferes with
66  * the auto-generated devices)
67  */
68 U_BOOT_DRVINFO(gpio_sandbox) = {
69         .name = "sandbox_gpio",
70 };
71 #endif
72
73 #ifndef CONFIG_TIMER
74 /* system timer offset in ms */
75 static unsigned long sandbox_timer_offset;
76
77 void timer_test_add_offset(unsigned long offset)
78 {
79         sandbox_timer_offset += offset;
80 }
81
82 unsigned long timer_read_counter(void)
83 {
84         return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
85 }
86 #endif
87
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,
92         ENVL_FAT,
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
103 int dram_init(void)
104 {
105         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
106         return 0;
107 }
108
109 int board_init(void)
110 {
111         return 0;
112 }
113
114 int ft_board_setup(void *fdt, struct bd_info *bd)
115 {
116         /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
117         return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
118 }
119
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");
132                 snprintf(extension->other, sizeof(extension->other), "Fictional extension board");
133                 list_add_tail(&extension->list, extension_list);
134         }
135
136         return i;
137 }
138 #endif
139
140 #ifdef CONFIG_BOARD_LATE_INIT
141 int board_late_init(void)
142 {
143         struct udevice *dev;
144         int ret;
145
146         ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
147         if (ret && ret != -ENODEV) {
148                 /* Force console on */
149                 gd->flags &= ~GD_FLG_SILENT;
150
151                 printf("cros-ec communications failure %d\n", ret);
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
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 }