armlinux.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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, 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);
  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))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), (char *)&header);
  89. } else
  90. #endif
  91. memcpy (&header, (char *)addr, sizeof(image_header_t));
  92. if (ntohl(hdr->ih_magic) != IH_MAGIC) {
  93. printf ("Bad Magic Number\n");
  94. SHOW_BOOT_PROGRESS (-10);
  95. do_reset (cmdtp, flag, argc, argv);
  96. }
  97. data = (ulong)&header;
  98. len = sizeof(image_header_t);
  99. checksum = ntohl(hdr->ih_hcrc);
  100. hdr->ih_hcrc = 0;
  101. if (crc32 (0, (char *)data, len) != checksum) {
  102. printf ("Bad Header Checksum\n");
  103. SHOW_BOOT_PROGRESS (-11);
  104. do_reset (cmdtp, flag, argc, argv);
  105. }
  106. SHOW_BOOT_PROGRESS (10);
  107. print_image_hdr (hdr);
  108. data = addr + sizeof(image_header_t);
  109. len = ntohl(hdr->ih_size);
  110. #ifdef CONFIG_HAS_DATAFLASH
  111. if (addr_dataflash(addr)){
  112. read_dataflash(data, len, (char *)CFG_LOAD_ADDR);
  113. data = CFG_LOAD_ADDR;
  114. }
  115. #endif
  116. if (verify) {
  117. ulong csum = 0;
  118. printf (" Verifying Checksum ... ");
  119. csum = crc32 (0, (char *)data, len);
  120. if (csum != ntohl(hdr->ih_dcrc)) {
  121. printf ("Bad Data CRC\n");
  122. SHOW_BOOT_PROGRESS (-12);
  123. do_reset (cmdtp, flag, argc, argv);
  124. }
  125. printf ("OK\n");
  126. }
  127. SHOW_BOOT_PROGRESS (11);
  128. if ((hdr->ih_os != IH_OS_LINUX) ||
  129. (hdr->ih_arch != IH_CPU_ARM) ||
  130. (hdr->ih_type != IH_TYPE_RAMDISK) ) {
  131. printf ("No Linux ARM Ramdisk Image\n");
  132. SHOW_BOOT_PROGRESS (-13);
  133. do_reset (cmdtp, flag, argc, argv);
  134. }
  135. /*
  136. * Now check if we have a multifile image
  137. */
  138. } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
  139. ulong tail = ntohl(len_ptr[0]) % 4;
  140. int i;
  141. SHOW_BOOT_PROGRESS (13);
  142. /* skip kernel length and terminator */
  143. data = (ulong)(&len_ptr[2]);
  144. /* skip any additional image length fields */
  145. for (i=1; len_ptr[i]; ++i)
  146. data += 4;
  147. /* add kernel length, and align */
  148. data += ntohl(len_ptr[0]);
  149. if (tail) {
  150. data += 4 - tail;
  151. }
  152. len = ntohl(len_ptr[1]);
  153. } else {
  154. /*
  155. * no initrd image
  156. */
  157. SHOW_BOOT_PROGRESS (14);
  158. data = 0;
  159. }
  160. #ifdef DEBUG
  161. if (!data) {
  162. printf ("No initrd\n");
  163. }
  164. #endif
  165. if (data) {
  166. initrd_start = data;
  167. initrd_end = initrd_start + len;
  168. } else {
  169. initrd_start = 0;
  170. initrd_end = 0;
  171. }
  172. SHOW_BOOT_PROGRESS (15);
  173. #ifdef DEBUG
  174. printf ("## Transferring control to Linux (at address %08lx) ...\n",
  175. (ulong)theKernel);
  176. #endif
  177. #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
  178. defined (CONFIG_CMDLINE_TAG) || \
  179. defined (CONFIG_INITRD_TAG) || \
  180. defined (CONFIG_VFD)
  181. setup_start_tag(bd);
  182. #ifdef CONFIG_SETUP_MEMORY_TAGS
  183. setup_memory_tags(bd);
  184. #endif
  185. #ifdef CONFIG_CMDLINE_TAG
  186. setup_commandline_tag(bd, commandline);
  187. #endif
  188. #ifdef CONFIG_INITRD_TAG
  189. setup_initrd_tag(bd, initrd_start, initrd_end);
  190. #endif
  191. #if 0
  192. setup_ramdisk_tag(bd);
  193. #endif
  194. #if defined (CONFIG_VFD)
  195. setup_videolfb_tag((gd_t *)gd);
  196. #endif
  197. setup_end_tag(bd);
  198. #endif
  199. /* we assume that the kernel is in place */
  200. printf("\nStarting kernel ...\n\n");
  201. cleanup_before_linux();
  202. theKernel(0, bd->bi_arch_number);
  203. }
  204. #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
  205. defined (CONFIG_CMDLINE_TAG) || \
  206. defined (CONFIG_INITRD_TAG) || \
  207. defined (CONFIG_VFD)
  208. static void setup_start_tag(bd_t *bd)
  209. {
  210. params = (struct tag *)bd->bi_boot_params;
  211. params->hdr.tag = ATAG_CORE;
  212. params->hdr.size = tag_size(tag_core);
  213. params->u.core.flags = 0;
  214. params->u.core.pagesize = 0;
  215. params->u.core.rootdev = 0;
  216. params = tag_next(params);
  217. }
  218. #ifdef CONFIG_SETUP_MEMORY_TAGS
  219. static void setup_memory_tags(bd_t *bd)
  220. {
  221. int i;
  222. for(i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  223. params->hdr.tag = ATAG_MEM;
  224. params->hdr.size = tag_size(tag_mem32);
  225. params->u.mem.start = bd->bi_dram[i].start;
  226. params->u.mem.size = bd->bi_dram[i].size;
  227. params = tag_next(params);
  228. }
  229. }
  230. #endif /* CONFIG_SETUP_MEMORY_TAGS */
  231. static void setup_commandline_tag(bd_t *bd, char *commandline)
  232. {
  233. char *p;
  234. /* eat leading white space */
  235. for(p = commandline; *p == ' '; p++)
  236. ;
  237. /* skip non-existent command lines so the kernel will still
  238. * use its default command line.
  239. */
  240. if(*p == '\0')
  241. return;
  242. params->hdr.tag = ATAG_CMDLINE;
  243. params->hdr.size = (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;
  244. strcpy(params->u.cmdline.cmdline, p);
  245. params = tag_next(params);
  246. }
  247. #ifndef ATAG_INITRD2
  248. #define ATAG_INITRD2 0x54420005
  249. #endif
  250. #ifdef CONFIG_INITRD_TAG
  251. static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
  252. {
  253. /* an ATAG_INITRD node tells the kernel where the compressed
  254. * ramdisk can be found. ATAG_RDIMG is a better name, actually.
  255. */
  256. params->hdr.tag = ATAG_INITRD2;
  257. params->hdr.size = tag_size(tag_initrd);
  258. params->u.initrd.start = initrd_start;
  259. params->u.initrd.size = initrd_end - initrd_start;
  260. params = tag_next(params);
  261. }
  262. #endif /* CONFIG_INITRD_TAG */
  263. #if 0
  264. static void setup_ramdisk_tag(bd_t *bd)
  265. {
  266. /* an ATAG_RAMDISK node tells the kernel how large the
  267. * decompressed ramdisk will become.
  268. */
  269. params->hdr.tag = ATAG_RAMDISK;
  270. params->hdr.size = tag_size(tag_ramdisk);
  271. params->u.ramdisk.start = 0;
  272. /*params->u.ramdisk.size = RAMDISK_SIZE; */
  273. params->u.ramdisk.flags = 1; /* automatically load ramdisk */
  274. params = tag_next(params);
  275. }
  276. #endif /* 0 */
  277. #if defined (CONFIG_VFD)
  278. static void setup_videolfb_tag(gd_t *gd)
  279. {
  280. /* An ATAG_VIDEOLFB node tells the kernel where and how large
  281. * the framebuffer for video was allocated (among other things).
  282. * Note that a _physical_ address is passed !
  283. *
  284. * We only use it to pass the address and size, the other entries
  285. * in the tag_videolfb are not of interest.
  286. */
  287. params->hdr.tag = ATAG_VIDEOLFB;
  288. params->hdr.size = tag_size(tag_videolfb);
  289. params->u.videolfb.lfb_base = (u32)gd->fb_base;
  290. /* 7168 = 256*4*56/8 - actually 2 pages (8192 bytes) are allocated */
  291. params->u.videolfb.lfb_size = 7168;
  292. params = tag_next(params);
  293. }
  294. #endif
  295. static void setup_end_tag(bd_t *bd)
  296. {
  297. params->hdr.tag = ATAG_NONE;
  298. params->hdr.size = 0;
  299. }
  300. #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */