bootm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2007 Michal Simek
  4. * (C) Copyright 2004 Atmark Techno, Inc.
  5. *
  6. * Michal SIMEK <monstr@monstr.eu>
  7. * Yasushi SHOJI <yashi@atmark-techno.com>
  8. */
  9. #include <common.h>
  10. #include <bootstage.h>
  11. #include <command.h>
  12. #include <cpu_func.h>
  13. #include <env.h>
  14. #include <fdt_support.h>
  15. #include <hang.h>
  16. #include <image.h>
  17. #include <asm/cache.h>
  18. #include <u-boot/zlib.h>
  19. #include <asm/byteorder.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. static ulong get_sp(void)
  22. {
  23. ulong ret;
  24. asm("addik %0, r1, 0" : "=r"(ret) : );
  25. return ret;
  26. }
  27. void arch_lmb_reserve(struct lmb *lmb)
  28. {
  29. ulong sp, bank_end;
  30. int bank;
  31. /*
  32. * Booting a (Linux) kernel image
  33. *
  34. * Allocate space for command line and board info - the
  35. * address should be as high as possible within the reach of
  36. * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
  37. * memory, which means far enough below the current stack
  38. * pointer.
  39. */
  40. sp = get_sp();
  41. debug("## Current stack ends at 0x%08lx ", sp);
  42. /* adjust sp by 4K to be safe */
  43. sp -= 4096;
  44. for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
  45. if (sp < gd->bd->bi_dram[bank].start)
  46. continue;
  47. bank_end = gd->bd->bi_dram[bank].start +
  48. gd->bd->bi_dram[bank].size;
  49. if (sp >= bank_end)
  50. continue;
  51. lmb_reserve(lmb, sp, bank_end - sp);
  52. break;
  53. }
  54. }
  55. static void boot_jump_linux(bootm_headers_t *images, int flag)
  56. {
  57. void (*thekernel)(char *cmdline, ulong rd, ulong dt);
  58. ulong dt = (ulong)images->ft_addr;
  59. ulong rd_start = images->initrd_start;
  60. ulong cmdline = images->cmdline_start;
  61. int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
  62. thekernel = (void (*)(char *, ulong, ulong))images->ep;
  63. debug("## Transferring control to Linux (at address 0x%08lx) ",
  64. (ulong)thekernel);
  65. debug("cmdline 0x%08lx, ramdisk 0x%08lx, FDT 0x%08lx...\n",
  66. cmdline, rd_start, dt);
  67. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  68. printf("\nStarting kernel ...%s\n\n", fake ?
  69. "(fake run for tracing)" : "");
  70. bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
  71. #ifdef XILINX_USE_DCACHE
  72. flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
  73. #endif
  74. if (!fake) {
  75. /*
  76. * Linux Kernel Parameters (passing device tree):
  77. * r5: pointer to command line
  78. * r6: pointer to ramdisk
  79. * r7: pointer to the fdt, followed by the board info data
  80. */
  81. thekernel((char *)cmdline, rd_start, dt);
  82. /* does not return */
  83. }
  84. }
  85. static void boot_prep_linux(bootm_headers_t *images)
  86. {
  87. if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
  88. debug("using: FDT\n");
  89. if (image_setup_linux(images)) {
  90. printf("FDT creation failed! hanging...");
  91. hang();
  92. }
  93. }
  94. }
  95. int do_bootm_linux(int flag, int argc, char * const argv[],
  96. bootm_headers_t *images)
  97. {
  98. images->cmdline_start = (ulong)env_get("bootargs");
  99. /* cmdline init is the part of 'prep' and nothing to do for 'bdt' */
  100. if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
  101. return -1;
  102. if (flag & BOOTM_STATE_OS_PREP) {
  103. boot_prep_linux(images);
  104. return 0;
  105. }
  106. if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
  107. boot_jump_linux(images, flag);
  108. return 0;
  109. }
  110. boot_prep_linux(images);
  111. boot_jump_linux(images, flag);
  112. return 1;
  113. }