sandbox.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2011 The Chromium OS Authors.
  4. */
  5. #include <common.h>
  6. #include <cpu_func.h>
  7. #include <cros_ec.h>
  8. #include <dm.h>
  9. #include <env_internal.h>
  10. #include <init.h>
  11. #include <led.h>
  12. #include <os.h>
  13. #include <asm/global_data.h>
  14. #include <asm/test.h>
  15. #include <asm/u-boot-sandbox.h>
  16. #include <malloc.h>
  17. #include <extension_board.h>
  18. /*
  19. * Pointer to initial global data area
  20. *
  21. * Here we initialize it.
  22. */
  23. gd_t *gd;
  24. #if !CONFIG_IS_ENABLED(OF_PLATDATA)
  25. /* Add a simple GPIO device */
  26. U_BOOT_DRVINFO(gpio_sandbox) = {
  27. .name = "sandbox_gpio",
  28. };
  29. #endif
  30. #ifndef CONFIG_TIMER
  31. /* system timer offset in ms */
  32. static unsigned long sandbox_timer_offset;
  33. void timer_test_add_offset(unsigned long offset)
  34. {
  35. sandbox_timer_offset += offset;
  36. }
  37. unsigned long timer_read_counter(void)
  38. {
  39. return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
  40. }
  41. #endif
  42. /* specific order for sandbox: nowhere is the first value, used by default */
  43. static enum env_location env_locations[] = {
  44. ENVL_NOWHERE,
  45. ENVL_EXT4,
  46. ENVL_FAT,
  47. };
  48. enum env_location env_get_location(enum env_operation op, int prio)
  49. {
  50. if (prio >= ARRAY_SIZE(env_locations))
  51. return ENVL_UNKNOWN;
  52. return env_locations[prio];
  53. }
  54. int dram_init(void)
  55. {
  56. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  57. return 0;
  58. }
  59. int board_init(void)
  60. {
  61. if (IS_ENABLED(CONFIG_LED))
  62. led_default_state();
  63. return 0;
  64. }
  65. int ft_board_setup(void *fdt, struct bd_info *bd)
  66. {
  67. /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
  68. return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
  69. }
  70. #ifdef CONFIG_CMD_EXTENSION
  71. int extension_board_scan(struct list_head *extension_list)
  72. {
  73. struct extension *extension;
  74. int i;
  75. for (i = 0; i < 2; i++) {
  76. extension = calloc(1, sizeof(struct extension));
  77. snprintf(extension->overlay, sizeof(extension->overlay), "overlay%d.dtbo", i);
  78. snprintf(extension->name, sizeof(extension->name), "extension board %d", i);
  79. snprintf(extension->owner, sizeof(extension->owner), "sandbox");
  80. snprintf(extension->version, sizeof(extension->version), "1.1");
  81. snprintf(extension->other, sizeof(extension->other), "Fictionnal extension board");
  82. list_add_tail(&extension->list, extension_list);
  83. }
  84. return i;
  85. }
  86. #endif
  87. #ifdef CONFIG_BOARD_LATE_INIT
  88. int board_late_init(void)
  89. {
  90. struct udevice *dev;
  91. int ret;
  92. ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
  93. if (ret && ret != -ENODEV) {
  94. /* Force console on */
  95. gd->flags &= ~GD_FLG_SILENT;
  96. printf("cros-ec communications failure %d\n", ret);
  97. puts("\nPlease reset with Power+Refresh\n\n");
  98. panic("Cannot init cros-ec device");
  99. return -1;
  100. }
  101. return 0;
  102. }
  103. #endif