bootm.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 <dm/root.h>
  12. #include <image.h>
  13. #include <asm/byteorder.h>
  14. #include <asm/csr.h>
  15. #include <dm/device.h>
  16. #include <dm/root.h>
  17. #include <u-boot/zlib.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. __weak void board_quiesce_devices(void)
  20. {
  21. }
  22. int arch_fixup_fdt(void *blob)
  23. {
  24. return 0;
  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. kernel = (void (*)(ulong, void *))images->ep;
  74. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  75. debug("## Transferring control to Linux (at address %08lx) ...\n",
  76. (ulong)kernel);
  77. announce_and_cleanup(fake);
  78. if (!fake) {
  79. if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
  80. kernel(csr_read(mhartid), images->ft_addr);
  81. }
  82. }
  83. int do_bootm_linux(int flag, int argc, char * const argv[],
  84. bootm_headers_t *images)
  85. {
  86. /* No need for those on RISC-V */
  87. if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
  88. return -1;
  89. if (flag & BOOTM_STATE_OS_PREP) {
  90. boot_prep_linux(images);
  91. return 0;
  92. }
  93. if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
  94. boot_jump_linux(images, flag);
  95. return 0;
  96. }
  97. boot_prep_linux(images);
  98. boot_jump_linux(images, flag);
  99. return 0;
  100. }