bootm.c 7.6 KB

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