spl.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2016 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <hang.h>
  8. #include <init.h>
  9. #include <log.h>
  10. #include <os.h>
  11. #include <spl.h>
  12. #include <asm/global_data.h>
  13. #include <asm/spl.h>
  14. #include <asm/state.h>
  15. #include <test/ut.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. int sandbox_find_next_phase(char *fname, int maxlen, bool use_img)
  18. {
  19. const char *cur_prefix, *next_prefix;
  20. int ret;
  21. cur_prefix = spl_phase_prefix(spl_phase());
  22. next_prefix = spl_phase_prefix(spl_next_phase());
  23. ret = os_find_u_boot(fname, maxlen, use_img, cur_prefix, next_prefix);
  24. if (ret)
  25. return log_msg_ret("find", ret);
  26. return 0;
  27. }
  28. /* SPL / TPL init function */
  29. void board_init_f(ulong flag)
  30. {
  31. struct sandbox_state *state = state_get_current();
  32. gd->arch.ram_buf = state->ram_buf;
  33. gd->ram_size = state->ram_size;
  34. }
  35. u32 spl_boot_device(void)
  36. {
  37. return BOOT_DEVICE_BOARD;
  38. }
  39. static int spl_board_load_image(struct spl_image_info *spl_image,
  40. struct spl_boot_device *bootdev)
  41. {
  42. char fname[256];
  43. int ret;
  44. ret = sandbox_find_next_phase(fname, sizeof(fname), false);
  45. if (ret) {
  46. printf("(%s not found, error %d)\n", fname, ret);
  47. return ret;
  48. }
  49. /*
  50. * Set up spl_image to boot from jump_to_image_no_args(). Allocate this
  51. * outsdide the RAM buffer (i.e. don't use strdup()).
  52. */
  53. spl_image->arg = os_malloc(strlen(fname) + 1);
  54. if (!spl_image->arg)
  55. return log_msg_ret("exec", -ENOMEM);
  56. strcpy(spl_image->arg, fname);
  57. return 0;
  58. }
  59. SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
  60. void spl_board_init(void)
  61. {
  62. struct sandbox_state *state = state_get_current();
  63. preloader_console_init();
  64. if (state->run_unittests) {
  65. struct unit_test *tests = UNIT_TEST_ALL_START();
  66. const int count = UNIT_TEST_ALL_COUNT();
  67. int ret;
  68. ret = ut_run_list("spl", NULL, tests, count,
  69. state->select_unittests);
  70. /* continue execution into U-Boot */
  71. }
  72. }
  73. void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
  74. {
  75. const char *fname = spl_image->arg;
  76. if (fname) {
  77. os_fd_restore();
  78. os_spl_to_uboot(fname);
  79. } else {
  80. printf("No filename provided for U-Boot\n");
  81. }
  82. hang();
  83. }
  84. int handoff_arch_save(struct spl_handoff *ho)
  85. {
  86. ho->arch.magic = TEST_HANDOFF_MAGIC;
  87. return 0;
  88. }