sandbox.c 1.8 KB

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