armlinux.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
  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 <asm/byteorder.h>
  28. #ifdef CONFIG_HAS_DATAFLASH
  29. #include <dataflash.h>
  30. #endif
  31. /*cmd_boot.c*/
  32. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  33. #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
  34. defined (CONFIG_CMDLINE_TAG) || \
  35. defined (CONFIG_INITRD_TAG) || \
  36. defined (CONFIG_SERIAL_TAG) || \
  37. defined (CONFIG_REVISION_TAG) || \
  38. defined (CONFIG_VFD)
  39. static void setup_start_tag (bd_t *bd);
  40. # ifdef CONFIG_SETUP_MEMORY_TAGS
  41. static void setup_memory_tags (bd_t *bd);
  42. # endif
  43. static void setup_commandline_tag (bd_t *bd, char *commandline);
  44. #if 0
  45. static void setup_ramdisk_tag (bd_t *bd);
  46. #endif
  47. # ifdef CONFIG_INITRD_TAG
  48. static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
  49. ulong initrd_end);
  50. # endif
  51. static void setup_end_tag (bd_t *bd);
  52. # if defined (CONFIG_VFD)
  53. static void setup_videolfb_tag (gd_t *gd);
  54. # endif
  55. static struct tag *params;
  56. #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
  57. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  58. # include <status_led.h>
  59. # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
  60. #else
  61. # define SHOW_BOOT_PROGRESS(arg)
  62. #endif
  63. extern image_header_t header; /* from cmd_bootm.c */
  64. void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  65. ulong addr, ulong *len_ptr, int verify)
  66. {
  67. DECLARE_GLOBAL_DATA_PTR;
  68. ulong len = 0, checksum;
  69. ulong initrd_start, initrd_end;
  70. ulong data;
  71. void (*theKernel)(int zero, int arch, uint params);
  72. image_header_t *hdr = &header;
  73. bd_t *bd = gd->bd;
  74. #ifdef CONFIG_CMDLINE_TAG
  75. char *commandline = getenv ("bootargs");
  76. #endif
  77. theKernel = (void (*)(int, int, uint))ntohl(hdr->ih_ep);
  78. /*
  79. * Check if there is an initrd image
  80. */
  81. if (argc >= 3) {
  82. SHOW_BOOT_PROGRESS (9);
  83. addr = simple_strtoul (argv[2], NULL, 16);
  84. printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
  85. /* Copy header so we can blank CRC field for re-calculation */
  86. #ifdef CONFIG_HAS_DATAFLASH
  87. if (addr_dataflash (addr)) {
  88. read_dataflash (addr, sizeof (image_header_t),
  89. (char *) &header);
  90. } else
  91. #endif
  92. memcpy (&header, (char *) addr,
  93. sizeof (image_header_t));
  94. if (ntohl (hdr->ih_magic) != IH_MAGIC) {
  95. printf ("Bad Magic Number\n");
  96. SHOW_BOOT_PROGRESS (-10);
  97. do_reset (cmdtp, flag, argc, argv);
  98. }
  99. data = (ulong) & header;
  100. len = sizeof (image_header_t);
  101. checksum = ntohl (hdr->ih_hcrc);
  102. hdr->ih_hcrc = 0;
  103. if (crc32 (0, (char *) data, len) != checksum) {
  104. printf ("Bad Header Checksum\n");
  105. SHOW_BOOT_PROGRESS (-11);
  106. do_reset (cmdtp, flag, argc, argv);
  107. }
  108. SHOW_BOOT_PROGRESS (10);
  109. print_image_hdr (hdr);
  110. data = addr + sizeof (image_header_t);
  111. len = ntohl (hdr->ih_size);
  112. #ifdef CONFIG_HAS_DATAFLASH
  113. if (addr_dataflash (addr)) {
  114. read_dataflash (data, len, (char *) CFG_LOAD_ADDR);
  115. data = CFG_LOAD_ADDR;
  116. }
  117. #endif
  118. if (verify) {
  119. ulong csum = 0;
  120. printf (" Verifying Checksum ... ");
  121. csum = crc32 (0, (char *) data, len);
  122. if (csum != ntohl (hdr->ih_dcrc)) {
  123. printf ("Bad Data CRC\n");
  124. SHOW_BOOT_PROGRESS (-12);
  125. do_reset (cmdtp, flag, argc, argv);
  126. }
  127. printf ("OK\n");
  128. }
  129. SHOW_BOOT_PROGRESS (11);
  130. if ((hdr->ih_os != IH_OS_LINUX) ||
  131. (hdr->ih_arch != IH_CPU_ARM) ||
  132. (hdr->ih_type != IH_TYPE_RAMDISK)) {
  133. printf ("No Linux ARM Ramdisk Image\n");
  134. SHOW_BOOT_PROGRESS (-13);
  135. do_reset (cmdtp, flag, argc, argv);
  136. }
  137. #ifdef CONFIG_B2
  138. /*
  139. *we need to copy the ramdisk to SRAM to let Linux boot
  140. */
  141. memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
  142. data = ntohl(hdr->ih_load);
  143. #endif /* CONFIG_B2 */
  144. /*
  145. * Now check if we have a multifile image
  146. */
  147. } else if ((hdr->ih_type == IH_TYPE_MULTI) && (len_ptr[1])) {
  148. ulong tail = ntohl (len_ptr[0]) % 4;
  149. int i;
  150. SHOW_BOOT_PROGRESS (13);
  151. /* skip kernel length and terminator */
  152. data = (ulong) (&len_ptr[2]);
  153. /* skip any additional image length fields */
  154. for (i = 1; len_ptr[i]; ++i)
  155. data += 4;
  156. /* add kernel length, and align */
  157. data += ntohl (len_ptr[0]);
  158. if (tail) {
  159. data += 4 - tail;
  160. }
  161. len = ntohl (len_ptr[1]);
  162. } else {
  163. /*
  164. * no initrd image
  165. */
  166. SHOW_BOOT_PROGRESS (14);
  167. len = data = 0;
  168. }
  169. #ifdef DEBUG
  170. if (!data) {
  171. printf ("No initrd\n");
  172. }
  173. #endif
  174. if (data) {
  175. initrd_start = data;
  176. initrd_end = initrd_start + len;
  177. } else {
  178. initrd_start = 0;
  179. initrd_end = 0;
  180. }
  181. SHOW_BOOT_PROGRESS (15);
  182. debug ("## Transferring control to Linux (at address %08lx) ...\n",
  183. (ulong) theKernel);
  184. #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
  185. defined (CONFIG_CMDLINE_TAG) || \
  186. defined (CONFIG_INITRD_TAG) || \
  187. defined (CONFIG_SERIAL_TAG) || \
  188. defined (CONFIG_REVISION_TAG) || \
  189. defined (CONFIG_VFD)
  190. setup_start_tag (bd);
  191. #ifdef CONFIG_SERIAL_TAG
  192. setup_serial_tag (&params);
  193. #endif
  194. #ifdef CONFIG_REVISION_TAG
  195. setup_revision_tag (&params);
  196. #endif
  197. #ifdef CONFIG_SETUP_MEMORY_TAGS
  198. setup_memory_tags (bd);
  199. #endif
  200. #ifdef CONFIG_CMDLINE_TAG
  201. setup_commandline_tag (bd, commandline);
  202. #endif
  203. #ifdef CONFIG_INITRD_TAG
  204. if (initrd_start && initrd_end)
  205. setup_initrd_tag (bd, initrd_start, initrd_end);
  206. #endif
  207. #if defined (CONFIG_VFD)
  208. setup_videolfb_tag ((gd_t *) gd);
  209. #endif
  210. setup_end_tag (bd);
  211. #endif
  212. /* we assume that the kernel is in place */
  213. printf ("\nStarting kernel ...\n\n");
  214. #ifdef CONFIG_USB_DEVICE
  215. {
  216. extern void udc_disconnect (void);
  217. udc_disconnect ();
  218. }
  219. #endif
  220. cleanup_before_linux ();
  221. theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
  222. }
  223. #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
  224. defined (CONFIG_CMDLINE_TAG) || \
  225. defined (CONFIG_INITRD_TAG) || \
  226. defined (CONFIG_SERIAL_TAG) || \
  227. defined (CONFIG_REVISION_TAG) || \
  228. defined (CONFIG_VFD)
  229. static void setup_start_tag (bd_t *bd)
  230. {
  231. params = (struct tag *) bd->bi_boot_params;
  232. params->hdr.tag = ATAG_CORE;
  233. params->hdr.size = tag_size (tag_core);
  234. params->u.core.flags = 0;
  235. params->u.core.pagesize = 0;
  236. params->u.core.rootdev = 0;
  237. params = tag_next (params);
  238. }
  239. #ifdef CONFIG_SETUP_MEMORY_TAGS
  240. static void setup_memory_tags (bd_t *bd)
  241. {
  242. int i;
  243. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  244. params->hdr.tag = ATAG_MEM;
  245. params->hdr.size = tag_size (tag_mem32);
  246. params->u.mem.start = bd->bi_dram[i].start;
  247. params->u.mem.size = bd->bi_dram[i].size;
  248. params = tag_next (params);
  249. }
  250. }
  251. #endif /* CONFIG_SETUP_MEMORY_TAGS */
  252. static void setup_commandline_tag (bd_t *bd, char *commandline)
  253. {
  254. char *p;
  255. if (!commandline)
  256. return;
  257. /* eat leading white space */
  258. for (p = commandline; *p == ' '; p++);
  259. /* skip non-existent command lines so the kernel will still
  260. * use its default command line.
  261. */
  262. if (*p == '\0')
  263. return;
  264. params->hdr.tag = ATAG_CMDLINE;
  265. params->hdr.size =
  266. (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
  267. strcpy (params->u.cmdline.cmdline, p);
  268. params = tag_next (params);
  269. }
  270. #ifdef CONFIG_INITRD_TAG
  271. static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
  272. {
  273. /* an ATAG_INITRD node tells the kernel where the compressed
  274. * ramdisk can be found. ATAG_RDIMG is a better name, actually.
  275. */
  276. params->hdr.tag = ATAG_INITRD2;
  277. params->hdr.size = tag_size (tag_initrd);
  278. params->u.initrd.start = initrd_start;
  279. params->u.initrd.size = initrd_end - initrd_start;
  280. params = tag_next (params);
  281. }
  282. #endif /* CONFIG_INITRD_TAG */
  283. #if defined (CONFIG_VFD)
  284. static void setup_videolfb_tag (gd_t *gd)
  285. {
  286. /* An ATAG_VIDEOLFB node tells the kernel where and how large
  287. * the framebuffer for video was allocated (among other things).
  288. * Note that a _physical_ address is passed !
  289. *
  290. * We only use it to pass the address and size, the other entries
  291. * in the tag_videolfb are not of interest.
  292. */
  293. params->hdr.tag = ATAG_VIDEOLFB;
  294. params->hdr.size = tag_size (tag_videolfb);
  295. params->u.videolfb.lfb_base = (u32) gd->fb_base;
  296. /* 7168 = 256*4*56/8 - actually 2 pages (8192 bytes) are allocated */
  297. params->u.videolfb.lfb_size = 7168;
  298. params = tag_next (params);
  299. }
  300. #endif
  301. static void setup_end_tag (bd_t *bd)
  302. {
  303. params->hdr.tag = ATAG_NONE;
  304. params->hdr.size = 0;
  305. }
  306. #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */