armlinux.c 8.2 KB

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