bootm.c 2.8 KB

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