bootm.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. DECLARE_GLOBAL_DATA_PTR;
  29. #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
  30. defined (CONFIG_CMDLINE_TAG) || \
  31. defined (CONFIG_INITRD_TAG) || \
  32. defined (CONFIG_SERIAL_TAG) || \
  33. defined (CONFIG_REVISION_TAG) || \
  34. defined (CONFIG_VFD) || \
  35. defined (CONFIG_LCD)
  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,
  46. ulong initrd_end);
  47. # endif
  48. static void setup_end_tag (bd_t *bd);
  49. # if defined (CONFIG_VFD) || defined (CONFIG_LCD)
  50. static void setup_videolfb_tag (gd_t *gd);
  51. # endif
  52. static struct tag *params;
  53. #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
  54. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  55. void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  56. bootm_headers_t *images)
  57. {
  58. ulong initrd_start, initrd_end;
  59. ulong ep = 0;
  60. bd_t *bd = gd->bd;
  61. char *s;
  62. int machid = bd->bi_arch_number;
  63. void (*theKernel)(int zero, int arch, uint params);
  64. int ret;
  65. #ifdef CONFIG_CMDLINE_TAG
  66. char *commandline = getenv ("bootargs");
  67. #endif
  68. /* find kernel entry point */
  69. if (images->legacy_hdr_valid) {
  70. ep = image_get_ep (&images->legacy_hdr_os_copy);
  71. #if defined(CONFIG_FIT)
  72. } else if (images->fit_uname_os) {
  73. ret = fit_image_get_entry (images->fit_hdr_os,
  74. images->fit_noffset_os, &ep);
  75. if (ret) {
  76. puts ("Can't get entry point property!\n");
  77. goto error;
  78. }
  79. #endif
  80. } else {
  81. puts ("Could not find kernel entry point!\n");
  82. goto error;
  83. }
  84. theKernel = (void (*)(int, int, uint))ep;
  85. s = getenv ("machid");
  86. if (s) {
  87. machid = simple_strtoul (s, NULL, 16);
  88. printf ("Using machid 0x%x from environment\n", machid);
  89. }
  90. ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_ARM,
  91. &initrd_start, &initrd_end);
  92. if (ret)
  93. goto error;
  94. show_boot_progress (15);
  95. debug ("## Transferring control to Linux (at address %08lx) ...\n",
  96. (ulong) theKernel);
  97. #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
  98. defined (CONFIG_CMDLINE_TAG) || \
  99. defined (CONFIG_INITRD_TAG) || \
  100. defined (CONFIG_SERIAL_TAG) || \
  101. defined (CONFIG_REVISION_TAG) || \
  102. defined (CONFIG_LCD) || \
  103. defined (CONFIG_VFD)
  104. setup_start_tag (bd);
  105. #ifdef CONFIG_SERIAL_TAG
  106. setup_serial_tag (&params);
  107. #endif
  108. #ifdef CONFIG_REVISION_TAG
  109. setup_revision_tag (&params);
  110. #endif
  111. #ifdef CONFIG_SETUP_MEMORY_TAGS
  112. setup_memory_tags (bd);
  113. #endif
  114. #ifdef CONFIG_CMDLINE_TAG
  115. setup_commandline_tag (bd, commandline);
  116. #endif
  117. #ifdef CONFIG_INITRD_TAG
  118. if (initrd_start && initrd_end)
  119. setup_initrd_tag (bd, initrd_start, initrd_end);
  120. #endif
  121. #if defined (CONFIG_VFD) || defined (CONFIG_LCD)
  122. setup_videolfb_tag ((gd_t *) gd);
  123. #endif
  124. setup_end_tag (bd);
  125. #endif
  126. if (!images->autostart)
  127. return ;
  128. /* we assume that the kernel is in place */
  129. printf ("\nStarting kernel ...\n\n");
  130. #ifdef CONFIG_USB_DEVICE
  131. {
  132. extern void udc_disconnect (void);
  133. udc_disconnect ();
  134. }
  135. #endif
  136. cleanup_before_linux ();
  137. theKernel (0, machid, bd->bi_boot_params);
  138. /* does not return */
  139. return;
  140. error:
  141. if (images->autostart)
  142. do_reset (cmdtp, flag, argc, argv);
  143. return;
  144. }
  145. #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
  146. defined (CONFIG_CMDLINE_TAG) || \
  147. defined (CONFIG_INITRD_TAG) || \
  148. defined (CONFIG_SERIAL_TAG) || \
  149. defined (CONFIG_REVISION_TAG) || \
  150. defined (CONFIG_LCD) || \
  151. defined (CONFIG_VFD)
  152. static void setup_start_tag (bd_t *bd)
  153. {
  154. params = (struct tag *) bd->bi_boot_params;
  155. params->hdr.tag = ATAG_CORE;
  156. params->hdr.size = tag_size (tag_core);
  157. params->u.core.flags = 0;
  158. params->u.core.pagesize = 0;
  159. params->u.core.rootdev = 0;
  160. params = tag_next (params);
  161. }
  162. #ifdef CONFIG_SETUP_MEMORY_TAGS
  163. static void setup_memory_tags (bd_t *bd)
  164. {
  165. int i;
  166. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  167. params->hdr.tag = ATAG_MEM;
  168. params->hdr.size = tag_size (tag_mem32);
  169. params->u.mem.start = bd->bi_dram[i].start;
  170. params->u.mem.size = bd->bi_dram[i].size;
  171. params = tag_next (params);
  172. }
  173. }
  174. #endif /* CONFIG_SETUP_MEMORY_TAGS */
  175. static void setup_commandline_tag (bd_t *bd, char *commandline)
  176. {
  177. char *p;
  178. if (!commandline)
  179. return;
  180. /* eat leading white space */
  181. for (p = commandline; *p == ' '; p++);
  182. /* skip non-existent command lines so the kernel will still
  183. * use its default command line.
  184. */
  185. if (*p == '\0')
  186. return;
  187. params->hdr.tag = ATAG_CMDLINE;
  188. params->hdr.size =
  189. (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
  190. strcpy (params->u.cmdline.cmdline, p);
  191. params = tag_next (params);
  192. }
  193. #ifdef CONFIG_INITRD_TAG
  194. static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
  195. {
  196. /* an ATAG_INITRD node tells the kernel where the compressed
  197. * ramdisk can be found. ATAG_RDIMG is a better name, actually.
  198. */
  199. params->hdr.tag = ATAG_INITRD2;
  200. params->hdr.size = tag_size (tag_initrd);
  201. params->u.initrd.start = initrd_start;
  202. params->u.initrd.size = initrd_end - initrd_start;
  203. params = tag_next (params);
  204. }
  205. #endif /* CONFIG_INITRD_TAG */
  206. #if defined (CONFIG_VFD) || defined (CONFIG_LCD)
  207. extern ulong calc_fbsize (void);
  208. static void setup_videolfb_tag (gd_t *gd)
  209. {
  210. /* An ATAG_VIDEOLFB node tells the kernel where and how large
  211. * the framebuffer for video was allocated (among other things).
  212. * Note that a _physical_ address is passed !
  213. *
  214. * We only use it to pass the address and size, the other entries
  215. * in the tag_videolfb are not of interest.
  216. */
  217. params->hdr.tag = ATAG_VIDEOLFB;
  218. params->hdr.size = tag_size (tag_videolfb);
  219. params->u.videolfb.lfb_base = (u32) gd->fb_base;
  220. /* Fb size is calculated according to parameters for our panel
  221. */
  222. params->u.videolfb.lfb_size = calc_fbsize();
  223. params = tag_next (params);
  224. }
  225. #endif /* CONFIG_VFD || CONFIG_LCD */
  226. #ifdef CONFIG_SERIAL_TAG
  227. void setup_serial_tag (struct tag **tmp)
  228. {
  229. struct tag *params = *tmp;
  230. struct tag_serialnr serialnr;
  231. void get_board_serial(struct tag_serialnr *serialnr);
  232. get_board_serial(&serialnr);
  233. params->hdr.tag = ATAG_SERIAL;
  234. params->hdr.size = tag_size (tag_serialnr);
  235. params->u.serialnr.low = serialnr.low;
  236. params->u.serialnr.high= serialnr.high;
  237. params = tag_next (params);
  238. *tmp = params;
  239. }
  240. #endif
  241. #ifdef CONFIG_REVISION_TAG
  242. void setup_revision_tag(struct tag **in_params)
  243. {
  244. u32 rev = 0;
  245. u32 get_board_rev(void);
  246. rev = get_board_rev();
  247. params->hdr.tag = ATAG_REVISION;
  248. params->hdr.size = tag_size (tag_revision);
  249. params->u.revision.rev = rev;
  250. params = tag_next (params);
  251. }
  252. #endif /* CONFIG_REVISION_TAG */
  253. static void setup_end_tag (bd_t *bd)
  254. {
  255. params->hdr.tag = ATAG_NONE;
  256. params->hdr.size = 0;
  257. }
  258. #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */