sandbox.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2011 The Chromium OS Authors.
  4. */
  5. #include <common.h>
  6. #include <addr_map.h>
  7. #include <cpu_func.h>
  8. #include <cros_ec.h>
  9. #include <dm.h>
  10. #include <efi.h>
  11. #include <efi_loader.h>
  12. #include <env_internal.h>
  13. #include <extension_board.h>
  14. #include <init.h>
  15. #include <led.h>
  16. #include <malloc.h>
  17. #include <mapmem.h>
  18. #include <os.h>
  19. #include <acpi/acpi_table.h>
  20. #include <asm/global_data.h>
  21. #include <asm/test.h>
  22. #include <asm/u-boot-sandbox.h>
  23. #include <linux/kernel.h>
  24. #include <linux/sizes.h>
  25. /*
  26. * Pointer to initial global data area
  27. *
  28. * Here we initialize it.
  29. */
  30. gd_t *gd;
  31. #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
  32. /* GUIDs for capsule updatable firmware images */
  33. #define SANDBOX_UBOOT_IMAGE_GUID \
  34. EFI_GUID(0x09d7cf52, 0x0720, 0x4710, 0x91, 0xd1, \
  35. 0x08, 0x46, 0x9b, 0x7f, 0xe9, 0xc8)
  36. #define SANDBOX_UBOOT_ENV_IMAGE_GUID \
  37. EFI_GUID(0x5a7021f5, 0xfef2, 0x48b4, 0xaa, 0xba, \
  38. 0x83, 0x2e, 0x77, 0x74, 0x18, 0xc0)
  39. #define SANDBOX_FIT_IMAGE_GUID \
  40. EFI_GUID(0x3673b45d, 0x6a7c, 0x46f3, 0x9e, 0x60, \
  41. 0xad, 0xab, 0xb0, 0x3f, 0x79, 0x37)
  42. struct efi_fw_image fw_images[] = {
  43. #if defined(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)
  44. {
  45. .image_type_id = SANDBOX_UBOOT_IMAGE_GUID,
  46. .fw_name = u"SANDBOX-UBOOT",
  47. .image_index = 1,
  48. },
  49. {
  50. .image_type_id = SANDBOX_UBOOT_ENV_IMAGE_GUID,
  51. .fw_name = u"SANDBOX-UBOOT-ENV",
  52. .image_index = 2,
  53. },
  54. #elif defined(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)
  55. {
  56. .image_type_id = SANDBOX_FIT_IMAGE_GUID,
  57. .fw_name = u"SANDBOX-FIT",
  58. .image_index = 1,
  59. },
  60. #endif
  61. };
  62. struct efi_capsule_update_info update_info = {
  63. .dfu_string = "sf 0:0=u-boot-bin raw 0x100000 0x50000;"
  64. "u-boot-env raw 0x150000 0x200000",
  65. .num_images = ARRAY_SIZE(fw_images),
  66. .images = fw_images,
  67. };
  68. #endif /* EFI_HAVE_CAPSULE_SUPPORT */
  69. #if !CONFIG_IS_ENABLED(OF_PLATDATA)
  70. /*
  71. * Add a simple GPIO device (don't use with of-platdata as it interferes with
  72. * the auto-generated devices)
  73. */
  74. U_BOOT_DRVINFO(gpio_sandbox) = {
  75. .name = "sandbox_gpio",
  76. };
  77. #endif
  78. #ifndef CONFIG_TIMER
  79. /* system timer offset in ms */
  80. static unsigned long sandbox_timer_offset;
  81. void timer_test_add_offset(unsigned long offset)
  82. {
  83. sandbox_timer_offset += offset;
  84. }
  85. unsigned long timer_read_counter(void)
  86. {
  87. return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
  88. }
  89. #endif
  90. /* specific order for sandbox: nowhere is the first value, used by default */
  91. static enum env_location env_locations[] = {
  92. ENVL_NOWHERE,
  93. ENVL_EXT4,
  94. ENVL_FAT,
  95. };
  96. enum env_location env_get_location(enum env_operation op, int prio)
  97. {
  98. if (prio >= ARRAY_SIZE(env_locations))
  99. return ENVL_UNKNOWN;
  100. return env_locations[prio];
  101. }
  102. int dram_init(void)
  103. {
  104. gd->ram_size = CFG_SYS_SDRAM_SIZE;
  105. return 0;
  106. }
  107. int board_init(void)
  108. {
  109. return 0;
  110. }
  111. int ft_board_setup(void *fdt, struct bd_info *bd)
  112. {
  113. /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
  114. return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
  115. }
  116. #ifdef CONFIG_CMD_EXTENSION
  117. int extension_board_scan(struct list_head *extension_list)
  118. {
  119. struct extension *extension;
  120. int i;
  121. for (i = 0; i < 2; i++) {
  122. extension = calloc(1, sizeof(struct extension));
  123. snprintf(extension->overlay, sizeof(extension->overlay), "overlay%d.dtbo", i);
  124. snprintf(extension->name, sizeof(extension->name), "extension board %d", i);
  125. snprintf(extension->owner, sizeof(extension->owner), "sandbox");
  126. snprintf(extension->version, sizeof(extension->version), "1.1");
  127. snprintf(extension->other, sizeof(extension->other), "Fictional extension board");
  128. list_add_tail(&extension->list, extension_list);
  129. }
  130. return i;
  131. }
  132. #endif
  133. #ifdef CONFIG_BOARD_LATE_INIT
  134. int board_late_init(void)
  135. {
  136. struct udevice *dev;
  137. ulong addr, end;
  138. void *ptr;
  139. int ret;
  140. ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
  141. if (ret && ret != -ENODEV) {
  142. /* Force console on */
  143. gd->flags &= ~GD_FLG_SILENT;
  144. printf("cros-ec communications failure %d\n", ret);
  145. puts("\nPlease reset with Power+Refresh\n\n");
  146. panic("Cannot init cros-ec device");
  147. return -1;
  148. }
  149. if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
  150. /* Reserve 64K for ACPI tables, aligned to a 4K boundary */
  151. ptr = memalign(SZ_4K, SZ_64K);
  152. addr = map_to_sysmem(ptr);
  153. /* Generate ACPI tables */
  154. end = write_acpi_tables(addr);
  155. gd->arch.table_start = addr;
  156. gd->arch.table_end = addr;
  157. }
  158. return 0;
  159. }
  160. #endif
  161. int init_addr_map(void)
  162. {
  163. if (IS_ENABLED(CONFIG_ADDR_MAP))
  164. addrmap_set_entry(0, 0, CFG_SYS_SDRAM_SIZE, 0);
  165. return 0;
  166. }
  167. #if defined(CONFIG_FWU_MULTI_BANK_UPDATE)
  168. void fwu_plat_get_bootidx(uint *boot_idx)
  169. {
  170. /* Dummy value */
  171. *boot_idx = 0;
  172. }
  173. #endif