armlinux.c 8.6 KB

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