bootm.c 3.0 KB

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