bootm.c 2.2 KB

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