armlinux.c 10 KB

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