bootm.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Copyright (C) 2011 Andes Technology Corporation
  3. * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
  4. * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <common.h>
  22. #include <command.h>
  23. #include <image.h>
  24. #include <u-boot/zlib.h>
  25. #include <asm/byteorder.h>
  26. DECLARE_GLOBAL_DATA_PTR;
  27. #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
  28. defined(CONFIG_CMDLINE_TAG) || \
  29. defined(CONFIG_INITRD_TAG) || \
  30. defined(CONFIG_SERIAL_TAG) || \
  31. defined(CONFIG_REVISION_TAG)
  32. static void setup_start_tag(bd_t *bd);
  33. # ifdef CONFIG_SETUP_MEMORY_TAGS
  34. static void setup_memory_tags(bd_t *bd);
  35. # endif
  36. static void setup_commandline_tag(bd_t *bd, char *commandline);
  37. # ifdef CONFIG_INITRD_TAG
  38. static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end);
  39. # endif
  40. static void setup_end_tag(bd_t *bd);
  41. static struct tag *params;
  42. #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
  43. int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
  44. {
  45. bd_t *bd = gd->bd;
  46. char *s;
  47. int machid = bd->bi_arch_number;
  48. void (*theKernel)(int zero, int arch, uint params);
  49. #ifdef CONFIG_CMDLINE_TAG
  50. char *commandline = getenv("bootargs");
  51. #endif
  52. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  53. return 1;
  54. theKernel = (void (*)(int, int, uint))images->ep;
  55. s = getenv("machid");
  56. if (s) {
  57. machid = simple_strtoul(s, NULL, 16);
  58. printf("Using machid 0x%x from environment\n", machid);
  59. }
  60. show_boot_progress(15);
  61. debug("## Transferring control to Linux (at address %08lx) ...\n",
  62. (ulong)theKernel);
  63. #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
  64. defined(CONFIG_CMDLINE_TAG) || \
  65. defined(CONFIG_INITRD_TAG) || \
  66. defined(CONFIG_SERIAL_TAG) || \
  67. defined(CONFIG_REVISION_TAG)
  68. setup_start_tag(bd);
  69. #ifdef CONFIG_SERIAL_TAG
  70. setup_serial_tag(&params);
  71. #endif
  72. #ifdef CONFIG_REVISION_TAG
  73. setup_revision_tag(&params);
  74. #endif
  75. #ifdef CONFIG_SETUP_MEMORY_TAGS
  76. setup_memory_tags(bd);
  77. #endif
  78. #ifdef CONFIG_CMDLINE_TAG
  79. setup_commandline_tag(bd, commandline);
  80. #endif
  81. #ifdef CONFIG_INITRD_TAG
  82. if (images->rd_start && images->rd_end)
  83. setup_initrd_tag(bd, images->rd_start, images->rd_end);
  84. #endif
  85. setup_end_tag(bd);
  86. #endif
  87. /* we assume that the kernel is in place */
  88. printf("\nStarting kernel ...\n\n");
  89. #ifdef CONFIG_USB_DEVICE
  90. {
  91. extern void udc_disconnect(void);
  92. udc_disconnect();
  93. }
  94. #endif
  95. cleanup_before_linux();
  96. theKernel(0, machid, bd->bi_boot_params);
  97. /* does not return */
  98. return 1;
  99. }
  100. #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
  101. defined(CONFIG_CMDLINE_TAG) || \
  102. defined(CONFIG_INITRD_TAG) || \
  103. defined(CONFIG_SERIAL_TAG) || \
  104. defined(CONFIG_REVISION_TAG)
  105. static void setup_start_tag(bd_t *bd)
  106. {
  107. params = (struct tag *)bd->bi_boot_params;
  108. params->hdr.tag = ATAG_CORE;
  109. params->hdr.size = tag_size(tag_core);
  110. params->u.core.flags = 0;
  111. params->u.core.pagesize = 0;
  112. params->u.core.rootdev = 0;
  113. params = tag_next(params);
  114. }
  115. #ifdef CONFIG_SETUP_MEMORY_TAGS
  116. static void setup_memory_tags(bd_t *bd)
  117. {
  118. int i;
  119. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  120. params->hdr.tag = ATAG_MEM;
  121. params->hdr.size = tag_size(tag_mem32);
  122. params->u.mem.start = bd->bi_dram[i].start;
  123. params->u.mem.size = bd->bi_dram[i].size;
  124. params = tag_next(params);
  125. }
  126. }
  127. #endif /* CONFIG_SETUP_MEMORY_TAGS */
  128. static void setup_commandline_tag(bd_t *bd, char *commandline)
  129. {
  130. char *p;
  131. if (!commandline)
  132. return;
  133. /* eat leading white space */
  134. for (p = commandline; *p == ' '; p++)
  135. ;
  136. /* skip non-existent command lines so the kernel will still
  137. * use its default command line.
  138. */
  139. if (*p == '\0')
  140. return;
  141. params->hdr.tag = ATAG_CMDLINE;
  142. params->hdr.size =
  143. (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;
  144. strcpy(params->u.cmdline.cmdline, p)
  145. ;
  146. params = tag_next(params);
  147. }
  148. #ifdef CONFIG_INITRD_TAG
  149. static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
  150. {
  151. /* an ATAG_INITRD node tells the kernel where the compressed
  152. * ramdisk can be found. ATAG_RDIMG is a better name, actually.
  153. */
  154. params->hdr.tag = ATAG_INITRD2;
  155. params->hdr.size = tag_size(tag_initrd);
  156. params->u.initrd.start = initrd_start;
  157. params->u.initrd.size = initrd_end - initrd_start;
  158. params = tag_next(params);
  159. }
  160. #endif /* CONFIG_INITRD_TAG */
  161. #ifdef CONFIG_SERIAL_TAG
  162. void setup_serial_tag(struct tag **tmp)
  163. {
  164. struct tag *params = *tmp;
  165. struct tag_serialnr serialnr;
  166. void get_board_serial(struct tag_serialnr *serialnr);
  167. get_board_serial(&serialnr);
  168. params->hdr.tag = ATAG_SERIAL;
  169. params->hdr.size = tag_size(tag_serialnr);
  170. params->u.serialnr.low = serialnr.low;
  171. params->u.serialnr.high = serialnr.high;
  172. params = tag_next(params);
  173. *tmp = params;
  174. }
  175. #endif
  176. #ifdef CONFIG_REVISION_TAG
  177. void setup_revision_tag(struct tag **in_params)
  178. {
  179. u32 rev = 0;
  180. u32 get_board_rev(void);
  181. rev = get_board_rev();
  182. params->hdr.tag = ATAG_REVISION;
  183. params->hdr.size = tag_size(tag_revision);
  184. params->u.revision.rev = rev;
  185. params = tag_next(params);
  186. }
  187. #endif /* CONFIG_REVISION_TAG */
  188. static void setup_end_tag(bd_t *bd)
  189. {
  190. params->hdr.tag = ATAG_NONE;
  191. params->hdr.size = 0;
  192. }
  193. #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */