bootm.c 3.1 KB

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