bootm.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <image.h>
  26. #include <zlib.h>
  27. #include <bzlib.h>
  28. #include <watchdog.h>
  29. #include <environment.h>
  30. #include <asm/byteorder.h>
  31. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  32. # include <status_led.h>
  33. #endif
  34. DECLARE_GLOBAL_DATA_PTR;
  35. #define PHYSADDR(x) x
  36. #define LINUX_MAX_ENVS 256
  37. #define LINUX_MAX_ARGS 256
  38. static ulong get_sp (void);
  39. static void set_clocks_in_mhz (bd_t *kbd);
  40. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  41. void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
  42. int argc, char *argv[],
  43. bootm_headers_t *images)
  44. {
  45. ulong sp;
  46. ulong rd_data_start, rd_data_end, rd_len;
  47. ulong initrd_start, initrd_end;
  48. int ret;
  49. ulong cmd_start, cmd_end;
  50. ulong bootmap_base;
  51. bd_t *kbd;
  52. ulong ep = 0;
  53. void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
  54. struct lmb *lmb = images->lmb;
  55. bootmap_base = getenv_bootm_low();
  56. /*
  57. * Booting a (Linux) kernel image
  58. *
  59. * Allocate space for command line and board info - the
  60. * address should be as high as possible within the reach of
  61. * the kernel (see CFG_BOOTMAPSZ settings), but in unused
  62. * memory, which means far enough below the current stack
  63. * pointer.
  64. */
  65. sp = get_sp();
  66. debug ("## Current stack ends at 0x%08lx ", sp);
  67. /* adjust sp by 1K to be safe */
  68. sp -= 1024;
  69. lmb_reserve(lmb, sp, (CFG_SDRAM_BASE + gd->ram_size - sp));
  70. /* allocate space and init command line */
  71. ret = boot_get_cmdline (lmb, &cmd_start, &cmd_end, bootmap_base);
  72. if (ret) {
  73. puts("ERROR with allocation of cmdline\n");
  74. goto error;
  75. }
  76. /* allocate space for kernel copy of board info */
  77. ret = boot_get_kbd (lmb, &kbd, bootmap_base);
  78. if (ret) {
  79. puts("ERROR with allocation of kernel bd\n");
  80. goto error;
  81. }
  82. set_clocks_in_mhz(kbd);
  83. /* find kernel entry point */
  84. if (images->legacy_hdr_valid) {
  85. ep = image_get_ep (&images->legacy_hdr_os_copy);
  86. #if defined(CONFIG_FIT)
  87. } else if (images->fit_uname_os) {
  88. ret = fit_image_get_entry (images->fit_hdr_os,
  89. images->fit_noffset_os, &ep);
  90. if (ret) {
  91. puts ("Can't get entry point property!\n");
  92. goto error;
  93. }
  94. #endif
  95. } else {
  96. puts ("Could not find kernel entry point!\n");
  97. goto error;
  98. }
  99. kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ep;
  100. /* find ramdisk */
  101. ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_M68K,
  102. &rd_data_start, &rd_data_end);
  103. if (ret)
  104. goto error;
  105. rd_len = rd_data_end - rd_data_start;
  106. ret = boot_ramdisk_high (lmb, rd_data_start, rd_len,
  107. &initrd_start, &initrd_end);
  108. if (ret)
  109. goto error;
  110. debug("## Transferring control to Linux (at address %08lx) ...\n",
  111. (ulong) kernel);
  112. show_boot_progress (15);
  113. if (!images->autostart)
  114. return;
  115. /*
  116. * Linux Kernel Parameters (passing board info data):
  117. * r3: ptr to board info data
  118. * r4: initrd_start or 0 if no initrd
  119. * r5: initrd_end - unused if r4 is 0
  120. * r6: Start of command line string
  121. * r7: End of command line string
  122. */
  123. (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
  124. /* does not return */
  125. return ;
  126. error:
  127. if (images->autostart)
  128. do_reset (cmdtp, flag, argc, argv);
  129. return ;
  130. }
  131. static ulong get_sp (void)
  132. {
  133. ulong sp;
  134. asm("movel %%a7, %%d0\n"
  135. "movel %%d0, %0\n": "=d"(sp): :"%d0");
  136. return sp;
  137. }
  138. static void set_clocks_in_mhz (bd_t *kbd)
  139. {
  140. char *s;
  141. if ((s = getenv("clocks_in_mhz")) != NULL) {
  142. /* convert all clock information to MHz */
  143. kbd->bi_intfreq /= 1000000L;
  144. kbd->bi_busfreq /= 1000000L;
  145. }
  146. }