bootm.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
  4. */
  5. #include <common.h>
  6. #include <bootstage.h>
  7. #include <env.h>
  8. #include <image.h>
  9. #include <irq_func.h>
  10. #include <lmb.h>
  11. #include <log.h>
  12. #include <asm/cache.h>
  13. #include <asm/global_data.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. static ulong get_sp(void)
  16. {
  17. ulong ret;
  18. asm("mov %0, sp" : "=r"(ret) : );
  19. return ret;
  20. }
  21. void arch_lmb_reserve(struct lmb *lmb)
  22. {
  23. ulong sp;
  24. /*
  25. * Booting a (Linux) kernel image
  26. *
  27. * Allocate space for command line and board info - the
  28. * address should be as high as possible within the reach of
  29. * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
  30. * memory, which means far enough below the current stack
  31. * pointer.
  32. */
  33. sp = get_sp();
  34. debug("## Current stack ends at 0x%08lx ", sp);
  35. /* adjust sp by 4K to be safe */
  36. sp -= 4096;
  37. lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
  38. }
  39. static int cleanup_before_linux(void)
  40. {
  41. disable_interrupts();
  42. sync_n_cleanup_cache_all();
  43. return 0;
  44. }
  45. __weak int board_prep_linux(bootm_headers_t *images) { return 0; }
  46. /* Subcommand: PREP */
  47. static int boot_prep_linux(bootm_headers_t *images)
  48. {
  49. int ret;
  50. ret = image_setup_linux(images);
  51. if (ret)
  52. return ret;
  53. return board_prep_linux(images);
  54. }
  55. /* Generic implementation for single core CPU */
  56. __weak void board_jump_and_run(ulong entry, int zero, int arch, uint params)
  57. {
  58. void (*kernel_entry)(int zero, int arch, uint params);
  59. kernel_entry = (void (*)(int, int, uint))entry;
  60. kernel_entry(zero, arch, params);
  61. }
  62. /* Subcommand: GO */
  63. static void boot_jump_linux(bootm_headers_t *images, int flag)
  64. {
  65. ulong kernel_entry;
  66. unsigned int r0, r2;
  67. int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
  68. kernel_entry = images->ep;
  69. debug("## Transferring control to Linux (at address %08lx)...\n",
  70. kernel_entry);
  71. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  72. printf("\nStarting kernel ...%s\n\n", fake ?
  73. "(fake run for tracing)" : "");
  74. bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
  75. if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
  76. r0 = 2;
  77. r2 = (unsigned int)images->ft_addr;
  78. } else {
  79. r0 = 1;
  80. r2 = (unsigned int)env_get("bootargs");
  81. }
  82. cleanup_before_linux();
  83. if (!fake)
  84. board_jump_and_run(kernel_entry, r0, 0, r2);
  85. }
  86. int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
  87. {
  88. /* No need for those on ARC */
  89. if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
  90. return -1;
  91. if (flag & BOOTM_STATE_OS_PREP)
  92. return boot_prep_linux(images);
  93. if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
  94. boot_jump_linux(images, flag);
  95. return 0;
  96. }
  97. return -1;
  98. }