bootm.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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(bootm_headers_t *images)
  57. {
  58. if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
  59. #ifdef CONFIG_OF_LIBFDT
  60. debug("using: FDT\n");
  61. if (image_setup_linux(images)) {
  62. printf("FDT creation failed! hanging...");
  63. hang();
  64. }
  65. #endif
  66. } else {
  67. printf("Device tree not found or missing FDT support\n");
  68. hang();
  69. }
  70. }
  71. static void boot_jump_linux(bootm_headers_t *images, int flag)
  72. {
  73. void (*kernel)(ulong hart, void *dtb);
  74. int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
  75. #ifdef CONFIG_SMP
  76. int ret;
  77. #endif
  78. kernel = (void (*)(ulong, void *))images->ep;
  79. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  80. debug("## Transferring control to kernel (at address %08lx) ...\n",
  81. (ulong)kernel);
  82. announce_and_cleanup(fake);
  83. if (!fake) {
  84. if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
  85. #ifdef CONFIG_SMP
  86. ret = smp_call_function(images->ep,
  87. (ulong)images->ft_addr, 0, 0);
  88. if (ret)
  89. hang();
  90. #endif
  91. kernel(gd->arch.boot_hart, images->ft_addr);
  92. }
  93. }
  94. }
  95. int do_bootm_linux(int flag, int argc, char *const argv[],
  96. bootm_headers_t *images)
  97. {
  98. /* No need for those on RISC-V */
  99. if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
  100. return -1;
  101. if (flag & BOOTM_STATE_OS_PREP) {
  102. boot_prep_linux(images);
  103. return 0;
  104. }
  105. if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
  106. boot_jump_linux(images, flag);
  107. return 0;
  108. }
  109. boot_prep_linux(images);
  110. boot_jump_linux(images, flag);
  111. return 0;
  112. }
  113. int do_bootm_vxworks(int flag, int argc, char *const argv[],
  114. bootm_headers_t *images)
  115. {
  116. return do_bootm_linux(flag, argc, argv, images);
  117. }