armlinux.c 9.8 KB

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