bootm.c 2.7 KB

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