bootm.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. DECLARE_GLOBAL_DATA_PTR;
  32. #define PHYSADDR(x) x
  33. #define LINUX_MAX_ENVS 256
  34. #define LINUX_MAX_ARGS 256
  35. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  36. # include <status_led.h>
  37. # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
  38. #else
  39. # define SHOW_BOOT_PROGRESS(arg)
  40. #endif
  41. int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  42. void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
  43. int argc, char *argv[],
  44. image_header_t *hdr, int verify)
  45. {
  46. ulong sp;
  47. ulong rd_data, rd_len;
  48. ulong initrd_high;
  49. ulong initrd_start, initrd_end;
  50. image_header_t *rd_hdr;
  51. int initrd_copy_to_ram = 1;
  52. ulong cmd_start, cmd_end;
  53. char *cmdline;
  54. char *s;
  55. bd_t *kbd;
  56. void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
  57. if ((s = getenv("initrd_high")) != NULL) {
  58. /* a value of "no" or a similar string will act like 0,
  59. * turning the "load high" feature off. This is intentional.
  60. */
  61. initrd_high = simple_strtoul(s, NULL, 16);
  62. if (initrd_high == ~0)
  63. initrd_copy_to_ram = 0;
  64. } else { /* not set, no restrictions to load high */
  65. initrd_high = ~0;
  66. }
  67. #ifdef CONFIG_LOGBUFFER
  68. kbd = gd->bd;
  69. /* Prevent initrd from overwriting logbuffer */
  70. if (initrd_high < (kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD))
  71. initrd_high = kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD;
  72. debug("## Logbuffer at 0x%08lX ", kbd->bi_memsize - LOGBUFF_LEN);
  73. #endif
  74. /*
  75. * Booting a (Linux) kernel image
  76. *
  77. * Allocate space for command line and board info - the
  78. * address should be as high as possible within the reach of
  79. * the kernel (see CFG_BOOTMAPSZ settings), but in unused
  80. * memory, which means far enough below the current stack
  81. * pointer.
  82. */
  83. asm("movel %%a7, %%d0\n"
  84. "movel %%d0, %0\n": "=d"(sp): :"%d0");
  85. debug("## Current stack ends at 0x%08lX ", sp);
  86. sp -= 2048; /* just to be sure */
  87. if (sp > CFG_BOOTMAPSZ)
  88. sp = CFG_BOOTMAPSZ;
  89. sp &= ~0xF;
  90. debug("=> set upper limit to 0x%08lX\n", sp);
  91. cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
  92. kbd = (bd_t *) (((ulong) cmdline - sizeof(bd_t)) & ~0xF);
  93. if ((s = getenv("bootargs")) == NULL)
  94. s = "";
  95. strcpy(cmdline, s);
  96. cmd_start = (ulong) & cmdline[0];
  97. cmd_end = cmd_start + strlen(cmdline);
  98. *kbd = *(gd->bd);
  99. #ifdef DEBUG
  100. printf("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
  101. do_bdinfo(NULL, 0, 0, NULL);
  102. #endif
  103. if ((s = getenv("clocks_in_mhz")) != NULL) {
  104. /* convert all clock information to MHz */
  105. kbd->bi_intfreq /= 1000000L;
  106. kbd->bi_busfreq /= 1000000L;
  107. }
  108. kernel =
  109. (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
  110. /*
  111. * Check if there is an initrd image
  112. */
  113. if (argc >= 3) {
  114. debug("Not skipping initrd\n");
  115. SHOW_BOOT_PROGRESS(9);
  116. rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16);
  117. printf ("## Loading RAMDisk Image at %08lx ...\n", rd_hdr);
  118. if (!image_check_magic (rd_hdr)) {
  119. puts("Bad Magic Number\n");
  120. SHOW_BOOT_PROGRESS(-10);
  121. do_reset(cmdtp, flag, argc, argv);
  122. }
  123. if (!image_check_hcrc (rd_hdr)) {
  124. puts("Bad Header Checksum\n");
  125. SHOW_BOOT_PROGRESS(-11);
  126. do_reset(cmdtp, flag, argc, argv);
  127. }
  128. SHOW_BOOT_PROGRESS(10);
  129. print_image_hdr (rd_hdr);
  130. rd_data = image_get_data (rd_hdr);
  131. rd_len = image_get_data_size (rd_hdr);
  132. if (verify) {
  133. puts(" Verifying Checksum ... ");
  134. if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) {
  135. puts("Bad Data CRC\n");
  136. SHOW_BOOT_PROGRESS(-12);
  137. do_reset(cmdtp, flag, argc, argv);
  138. }
  139. puts("OK\n");
  140. }
  141. SHOW_BOOT_PROGRESS(11);
  142. if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
  143. !image_check_arch (rd_hdr, IH_ARCH_M68K) ||
  144. !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
  145. puts("No Linux ColdFire Ramdisk Image\n");
  146. SHOW_BOOT_PROGRESS(-13);
  147. do_reset(cmdtp, flag, argc, argv);
  148. }
  149. /*
  150. * Now check if we have a multifile image
  151. */
  152. } else if (image_check_type (hdr, IH_TYPE_MULTI)) {
  153. /*
  154. * Get second entry data start address and len
  155. */
  156. SHOW_BOOT_PROGRESS (13);
  157. image_multi_getimg (hdr, 1, &rd_data, &rd_len);
  158. } else {
  159. /*
  160. * no initrd image
  161. */
  162. SHOW_BOOT_PROGRESS(14);
  163. rd_len = rd_data = 0;
  164. }
  165. if (!rd_data) {
  166. debug("No initrd\n");
  167. }
  168. if (rd_data) {
  169. if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
  170. initrd_start = rd_data;
  171. initrd_end = initrd_start + rd_len;
  172. } else {
  173. initrd_start = (ulong) kbd - rd_len;
  174. initrd_start &= ~(4096 - 1); /* align on page */
  175. if (initrd_high) {
  176. ulong nsp;
  177. /*
  178. * the inital ramdisk does not need to be within
  179. * CFG_BOOTMAPSZ as it is not accessed until after
  180. * the mm system is initialised.
  181. *
  182. * do the stack bottom calculation again and see if
  183. * the initrd will fit just below the monitor stack
  184. * bottom without overwriting the area allocated
  185. * above for command line args and board info.
  186. */
  187. asm("movel %%a7, %%d0\n"
  188. "movel %%d0, %0\n": "=d"(nsp): :"%d0");
  189. nsp -= 2048; /* just to be sure */
  190. nsp &= ~0xF;
  191. if (nsp > initrd_high) /* limit as specified */
  192. nsp = initrd_high;
  193. nsp -= rd_len;
  194. nsp &= ~(4096 - 1); /* align on page */
  195. if (nsp >= sp)
  196. initrd_start = nsp;
  197. }
  198. SHOW_BOOT_PROGRESS(12);
  199. debug
  200. ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
  201. rd_data, rd_data + rd_len - 1, rd_len, rd_len);
  202. initrd_end = initrd_start + rd_len;
  203. printf(" Loading Ramdisk to %08lx, end %08lx ... ",
  204. initrd_start, initrd_end);
  205. memmove_wd((void *)initrd_start,
  206. (void *)rd_data, rd_len, CHUNKSZ);
  207. puts("OK\n");
  208. }
  209. } else {
  210. initrd_start = 0;
  211. initrd_end = 0;
  212. }
  213. debug("## Transferring control to Linux (at address %08lx) ...\n",
  214. (ulong) kernel);
  215. SHOW_BOOT_PROGRESS(15);
  216. /*
  217. * Linux Kernel Parameters (passing board info data):
  218. * r3: ptr to board info data
  219. * r4: initrd_start or 0 if no initrd
  220. * r5: initrd_end - unused if r4 is 0
  221. * r6: Start of command line string
  222. * r7: End of command line string
  223. */
  224. (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
  225. /* does not return */
  226. }