bootm.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 <dm/root.h>
  15. #include <image.h>
  16. #include <asm/byteorder.h>
  17. #include <asm/csr.h>
  18. #include <asm/smp.h>
  19. #include <dm/device.h>
  20. #include <dm/root.h>
  21. #include <u-boot/zlib.h>
  22. DECLARE_GLOBAL_DATA_PTR;
  23. __weak void board_quiesce_devices(void)
  24. {
  25. }
  26. /**
  27. * announce_and_cleanup() - Print message and prepare for kernel boot
  28. *
  29. * @fake: non-zero to do everything except actually boot
  30. */
  31. static void announce_and_cleanup(int fake)
  32. {
  33. printf("\nStarting kernel ...%s\n\n", fake ?
  34. "(fake run for tracing)" : "");
  35. bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
  36. #ifdef CONFIG_BOOTSTAGE_FDT
  37. bootstage_fdt_add_report();
  38. #endif
  39. #ifdef CONFIG_BOOTSTAGE_REPORT
  40. bootstage_report();
  41. #endif
  42. #ifdef CONFIG_USB_DEVICE
  43. udc_disconnect();
  44. #endif
  45. board_quiesce_devices();
  46. /*
  47. * Call remove function of all devices with a removal flag set.
  48. * This may be useful for last-stage operations, like cancelling
  49. * of DMA operation or releasing device internal buffers.
  50. */
  51. dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
  52. cleanup_before_linux();
  53. }
  54. static void boot_prep_linux(bootm_headers_t *images)
  55. {
  56. if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
  57. #ifdef CONFIG_OF_LIBFDT
  58. debug("using: FDT\n");
  59. if (image_setup_linux(images)) {
  60. printf("FDT creation failed! hanging...");
  61. hang();
  62. }
  63. #endif
  64. } else {
  65. printf("Device tree not found or missing FDT support\n");
  66. hang();
  67. }
  68. }
  69. static void boot_jump_linux(bootm_headers_t *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 (IMAGE_ENABLE_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. bootm_headers_t *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. bootm_headers_t *images)
  113. {
  114. return do_bootm_linux(flag, argc, argv, images);
  115. }