bootm.c 2.5 KB

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