bootm.c 2.6 KB

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