bootm.c 3.0 KB

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