bootm.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2011 Andes Technology Corporation
  4. * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
  5. * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
  6. * Rick Chen, Andes Technology Corporation <rick@andestech.com>
  7. */
  8. #include <common.h>
  9. #include <bootstage.h>
  10. #include <command.h>
  11. #include <dm.h>
  12. #include <fdt_support.h>
  13. #include <hang.h>
  14. #include <log.h>
  15. #include <asm/global_data.h>
  16. #include <dm/root.h>
  17. #include <image.h>
  18. #include <asm/byteorder.h>
  19. #include <asm/csr.h>
  20. #include <asm/smp.h>
  21. #include <dm/device.h>
  22. #include <dm/root.h>
  23. #include <u-boot/zlib.h>
  24. DECLARE_GLOBAL_DATA_PTR;
  25. __weak void board_quiesce_devices(void)
  26. {
  27. }
  28. /**
  29. * announce_and_cleanup() - Print message and prepare for kernel boot
  30. *
  31. * @fake: non-zero to do everything except actually boot
  32. */
  33. static void announce_and_cleanup(int fake)
  34. {
  35. printf("\nStarting kernel ...%s\n\n", fake ?
  36. "(fake run for tracing)" : "");
  37. bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
  38. #ifdef CONFIG_BOOTSTAGE_FDT
  39. bootstage_fdt_add_report();
  40. #endif
  41. #ifdef CONFIG_BOOTSTAGE_REPORT
  42. bootstage_report();
  43. #endif
  44. #ifdef CONFIG_USB_DEVICE
  45. udc_disconnect();
  46. #endif
  47. board_quiesce_devices();
  48. /*
  49. * Call remove function of all devices with a removal flag set.
  50. * This may be useful for last-stage operations, like cancelling
  51. * of DMA operation or releasing device internal buffers.
  52. */
  53. dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
  54. cleanup_before_linux();
  55. }
  56. static void boot_prep_linux(struct bootm_headers *images)
  57. {
  58. if (CONFIG_IS_ENABLED(OF_LIBFDT) && IS_ENABLED(CONFIG_LMB) && images->ft_len) {
  59. debug("using: FDT\n");
  60. if (image_setup_linux(images)) {
  61. printf("FDT creation failed! hanging...");
  62. hang();
  63. }
  64. } else {
  65. printf("Device tree not found or missing FDT support\n");
  66. hang();
  67. }
  68. }
  69. static void boot_jump_linux(struct bootm_headers *images, int flag)
  70. {
  71. void (*kernel)(ulong hart, void *dtb);
  72. int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
  73. #ifdef CONFIG_SMP
  74. int ret;
  75. #endif
  76. kernel = (void (*)(ulong, void *))images->ep;
  77. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  78. debug("## Transferring control to kernel (at address %08lx) ...\n",
  79. (ulong)kernel);
  80. announce_and_cleanup(fake);
  81. if (!fake) {
  82. if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
  83. #ifdef CONFIG_SMP
  84. ret = smp_call_function(images->ep,
  85. (ulong)images->ft_addr, 0, 0);
  86. if (ret)
  87. hang();
  88. #endif
  89. kernel(gd->arch.boot_hart, images->ft_addr);
  90. }
  91. }
  92. }
  93. int do_bootm_linux(int flag, int argc, char *const argv[],
  94. struct bootm_headers *images)
  95. {
  96. /* No need for those on RISC-V */
  97. if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
  98. return -1;
  99. if (flag & BOOTM_STATE_OS_PREP) {
  100. boot_prep_linux(images);
  101. return 0;
  102. }
  103. if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
  104. boot_jump_linux(images, flag);
  105. return 0;
  106. }
  107. boot_prep_linux(images);
  108. boot_jump_linux(images, flag);
  109. return 0;
  110. }
  111. int do_bootm_vxworks(int flag, int argc, char *const argv[],
  112. struct bootm_headers *images)
  113. {
  114. return do_bootm_linux(flag, argc, argv, images);
  115. }
  116. static ulong get_sp(void)
  117. {
  118. ulong ret;
  119. asm("mv %0, sp" : "=r"(ret) : );
  120. return ret;
  121. }
  122. void arch_lmb_reserve(struct lmb *lmb)
  123. {
  124. arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
  125. }