bootm.c 2.4 KB

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