bootm.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <image.h>
  10. #include <u-boot/zlib.h>
  11. #include <bzlib.h>
  12. #include <watchdog.h>
  13. #include <environment.h>
  14. #include <asm/byteorder.h>
  15. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  16. # include <status_led.h>
  17. #endif
  18. DECLARE_GLOBAL_DATA_PTR;
  19. #define PHYSADDR(x) x
  20. #define LINUX_MAX_ENVS 256
  21. #define LINUX_MAX_ARGS 256
  22. static ulong get_sp (void);
  23. static void set_clocks_in_mhz (bd_t *kbd);
  24. void arch_lmb_reserve(struct lmb *lmb)
  25. {
  26. ulong sp;
  27. /*
  28. * Booting a (Linux) kernel image
  29. *
  30. * Allocate space for command line and board info - the
  31. * address should be as high as possible within the reach of
  32. * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
  33. * memory, which means far enough below the current stack
  34. * pointer.
  35. */
  36. sp = get_sp();
  37. debug ("## Current stack ends at 0x%08lx ", sp);
  38. /* adjust sp by 1K to be safe */
  39. sp -= 1024;
  40. lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
  41. }
  42. int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images)
  43. {
  44. ulong rd_len;
  45. ulong initrd_start, initrd_end;
  46. int ret;
  47. ulong cmd_start, cmd_end;
  48. bd_t *kbd;
  49. void (*kernel) (bd_t *, 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 (*)(bd_t *, 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, initrd_start, initrd_end, cmd_start, cmd_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. if ((s = getenv("clocks_in_mhz")) != NULL) {
  97. /* convert all clock information to MHz */
  98. kbd->bi_intfreq /= 1000000L;
  99. kbd->bi_busfreq /= 1000000L;
  100. }
  101. }