bootm.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2003
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. #include <common.h>
  7. #include <bootstage.h>
  8. #include <command.h>
  9. #include <env.h>
  10. #include <image.h>
  11. #include <lmb.h>
  12. #include <u-boot/zlib.h>
  13. #include <bzlib.h>
  14. #include <watchdog.h>
  15. #include <asm/byteorder.h>
  16. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  17. # include <status_led.h>
  18. #endif
  19. DECLARE_GLOBAL_DATA_PTR;
  20. #define PHYSADDR(x) x
  21. #define LINUX_MAX_ENVS 256
  22. #define LINUX_MAX_ARGS 256
  23. static ulong get_sp (void);
  24. static void set_clocks_in_mhz (bd_t *kbd);
  25. void arch_lmb_reserve(struct lmb *lmb)
  26. {
  27. ulong sp;
  28. /*
  29. * Booting a (Linux) kernel image
  30. *
  31. * Allocate space for command line and board info - the
  32. * address should be as high as possible within the reach of
  33. * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
  34. * memory, which means far enough below the current stack
  35. * pointer.
  36. */
  37. sp = get_sp();
  38. debug ("## Current stack ends at 0x%08lx ", sp);
  39. /* adjust sp by 1K to be safe */
  40. sp -= 1024;
  41. lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
  42. }
  43. int do_bootm_linux(int flag, int argc, char *const argv[],
  44. bootm_headers_t *images)
  45. {
  46. int ret;
  47. bd_t *kbd;
  48. void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
  49. struct lmb *lmb = &images->lmb;
  50. /*
  51. * allow the PREP bootm subcommand, it is required for bootm to work
  52. */
  53. if (flag & BOOTM_STATE_OS_PREP)
  54. return 0;
  55. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  56. return 1;
  57. /* allocate space for kernel copy of board info */
  58. ret = boot_get_kbd (lmb, &kbd);
  59. if (ret) {
  60. puts("ERROR with allocation of kernel bd\n");
  61. goto error;
  62. }
  63. set_clocks_in_mhz(kbd);
  64. ret = image_setup_linux(images);
  65. if (ret)
  66. goto error;
  67. kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
  68. debug("## Transferring control to Linux (at address %08lx) ...\n",
  69. (ulong) kernel);
  70. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  71. /*
  72. * Linux Kernel Parameters (passing board info data):
  73. * sp+00: Ignore, side effect of using jsr to jump to kernel
  74. * sp+04: ptr to board info data
  75. * sp+08: initrd_start or 0 if no initrd
  76. * sp+12: initrd_end - unused if initrd_start is 0
  77. * sp+16: Start of command line string
  78. * sp+20: End of command line string
  79. */
  80. (*kernel)(kbd, images->initrd_start, images->initrd_end,
  81. images->cmdline_start, images->cmdline_end);
  82. /* does not return */
  83. error:
  84. return 1;
  85. }
  86. static ulong get_sp (void)
  87. {
  88. ulong sp;
  89. asm("movel %%a7, %%d0\n"
  90. "movel %%d0, %0\n": "=d"(sp): :"%d0");
  91. return sp;
  92. }
  93. static void set_clocks_in_mhz (bd_t *kbd)
  94. {
  95. char *s;
  96. s = env_get("clocks_in_mhz");
  97. if (s) {
  98. /* convert all clock information to MHz */
  99. kbd->bi_intfreq /= 1000000L;
  100. kbd->bi_busfreq /= 1000000L;
  101. }
  102. }