sandbox.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/test.h>
  14. #include <asm/u-boot-sandbox.h>
  15. /*
  16. * Pointer to initial global data area
  17. *
  18. * Here we initialize it.
  19. */
  20. gd_t *gd;
  21. /* Add a simple GPIO device */
  22. U_BOOT_DEVICE(gpio_sandbox) = {
  23. .name = "sandbox_gpio",
  24. };
  25. void flush_cache(unsigned long start, unsigned long size)
  26. {
  27. }
  28. #ifndef CONFIG_TIMER
  29. /* system timer offset in ms */
  30. static unsigned long sandbox_timer_offset;
  31. void timer_test_add_offset(unsigned long offset)
  32. {
  33. sandbox_timer_offset += offset;
  34. }
  35. unsigned long timer_read_counter(void)
  36. {
  37. return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
  38. }
  39. #endif
  40. /* specific order for sandbox: nowhere is the first value, used by default */
  41. static enum env_location env_locations[] = {
  42. ENVL_NOWHERE,
  43. ENVL_EXT4,
  44. };
  45. enum env_location env_get_location(enum env_operation op, int prio)
  46. {
  47. if (prio >= ARRAY_SIZE(env_locations))
  48. return ENVL_UNKNOWN;
  49. return env_locations[prio];
  50. }
  51. int dram_init(void)
  52. {
  53. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  54. return 0;
  55. }
  56. int board_init(void)
  57. {
  58. if (IS_ENABLED(CONFIG_LED))
  59. led_default_state();
  60. return 0;
  61. }
  62. int ft_board_setup(void *fdt, struct bd_info *bd)
  63. {
  64. /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
  65. return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
  66. }
  67. #ifdef CONFIG_BOARD_LATE_INIT
  68. int board_late_init(void)
  69. {
  70. struct udevice *dev;
  71. int ret;
  72. ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
  73. if (ret && ret != -ENODEV) {
  74. /* Force console on */
  75. gd->flags &= ~GD_FLG_SILENT;
  76. printf("cros-ec communications failure %d\n", ret);
  77. puts("\nPlease reset with Power+Refresh\n\n");
  78. panic("Cannot init cros-ec device");
  79. return -1;
  80. }
  81. return 0;
  82. }
  83. #endif