armlinux.c 8.5 KB

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