bootm.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. /*
  53. * allow the PREP bootm subcommand, it is required for bootm to work
  54. */
  55. if (flag & BOOTM_STATE_OS_PREP)
  56. return 0;
  57. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  58. return 1;
  59. theKernel = (void (*)(int, int, uint))images->ep;
  60. s = getenv("machid");
  61. if (s) {
  62. machid = simple_strtoul(s, NULL, 16);
  63. printf("Using machid 0x%x from environment\n", machid);
  64. }
  65. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  66. debug("## Transferring control to Linux (at address %08lx) ...\n",
  67. (ulong)theKernel);
  68. #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
  69. defined(CONFIG_CMDLINE_TAG) || \
  70. defined(CONFIG_INITRD_TAG) || \
  71. defined(CONFIG_SERIAL_TAG) || \
  72. defined(CONFIG_REVISION_TAG)
  73. setup_start_tag(bd);
  74. #ifdef CONFIG_SERIAL_TAG
  75. setup_serial_tag(&params);
  76. #endif
  77. #ifdef CONFIG_REVISION_TAG
  78. setup_revision_tag(&params);
  79. #endif
  80. #ifdef CONFIG_SETUP_MEMORY_TAGS
  81. setup_memory_tags(bd);
  82. #endif
  83. #ifdef CONFIG_CMDLINE_TAG
  84. setup_commandline_tag(bd, commandline);
  85. #endif
  86. #ifdef CONFIG_INITRD_TAG
  87. if (images->rd_start && images->rd_end)
  88. setup_initrd_tag(bd, images->rd_start, images->rd_end);
  89. #endif
  90. setup_end_tag(bd);
  91. #endif
  92. /* we assume that the kernel is in place */
  93. printf("\nStarting kernel ...\n\n");
  94. #ifdef CONFIG_USB_DEVICE
  95. {
  96. extern void udc_disconnect(void);
  97. udc_disconnect();
  98. }
  99. #endif
  100. cleanup_before_linux();
  101. theKernel(0, machid, bd->bi_boot_params);
  102. /* does not return */
  103. return 1;
  104. }
  105. #if defined(CONFIG_SETUP_MEMORY_TAGS) || \
  106. defined(CONFIG_CMDLINE_TAG) || \
  107. defined(CONFIG_INITRD_TAG) || \
  108. defined(CONFIG_SERIAL_TAG) || \
  109. defined(CONFIG_REVISION_TAG)
  110. static void setup_start_tag(bd_t *bd)
  111. {
  112. params = (struct tag *)bd->bi_boot_params;
  113. params->hdr.tag = ATAG_CORE;
  114. params->hdr.size = tag_size(tag_core);
  115. params->u.core.flags = 0;
  116. params->u.core.pagesize = 0;
  117. params->u.core.rootdev = 0;
  118. params = tag_next(params);
  119. }
  120. #ifdef CONFIG_SETUP_MEMORY_TAGS
  121. static void setup_memory_tags(bd_t *bd)
  122. {
  123. int i;
  124. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  125. params->hdr.tag = ATAG_MEM;
  126. params->hdr.size = tag_size(tag_mem32);
  127. params->u.mem.start = bd->bi_dram[i].start;
  128. params->u.mem.size = bd->bi_dram[i].size;
  129. params = tag_next(params);
  130. }
  131. }
  132. #endif /* CONFIG_SETUP_MEMORY_TAGS */
  133. static void setup_commandline_tag(bd_t *bd, char *commandline)
  134. {
  135. char *p;
  136. if (!commandline)
  137. return;
  138. /* eat leading white space */
  139. for (p = commandline; *p == ' '; p++)
  140. ;
  141. /* skip non-existent command lines so the kernel will still
  142. * use its default command line.
  143. */
  144. if (*p == '\0')
  145. return;
  146. params->hdr.tag = ATAG_CMDLINE;
  147. params->hdr.size =
  148. (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;
  149. strcpy(params->u.cmdline.cmdline, p)
  150. ;
  151. params = tag_next(params);
  152. }
  153. #ifdef CONFIG_INITRD_TAG
  154. static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
  155. {
  156. /* an ATAG_INITRD node tells the kernel where the compressed
  157. * ramdisk can be found. ATAG_RDIMG is a better name, actually.
  158. */
  159. params->hdr.tag = ATAG_INITRD2;
  160. params->hdr.size = tag_size(tag_initrd);
  161. params->u.initrd.start = initrd_start;
  162. params->u.initrd.size = initrd_end - initrd_start;
  163. params = tag_next(params);
  164. }
  165. #endif /* CONFIG_INITRD_TAG */
  166. #ifdef CONFIG_SERIAL_TAG
  167. void setup_serial_tag(struct tag **tmp)
  168. {
  169. struct tag *params = *tmp;
  170. struct tag_serialnr serialnr;
  171. void get_board_serial(struct tag_serialnr *serialnr);
  172. get_board_serial(&serialnr);
  173. params->hdr.tag = ATAG_SERIAL;
  174. params->hdr.size = tag_size(tag_serialnr);
  175. params->u.serialnr.low = serialnr.low;
  176. params->u.serialnr.high = serialnr.high;
  177. params = tag_next(params);
  178. *tmp = params;
  179. }
  180. #endif
  181. #ifdef CONFIG_REVISION_TAG
  182. void setup_revision_tag(struct tag **in_params)
  183. {
  184. u32 rev = 0;
  185. u32 get_board_rev(void);
  186. rev = get_board_rev();
  187. params->hdr.tag = ATAG_REVISION;
  188. params->hdr.size = tag_size(tag_revision);
  189. params->u.revision.rev = rev;
  190. params = tag_next(params);
  191. }
  192. #endif /* CONFIG_REVISION_TAG */
  193. static void setup_end_tag(bd_t *bd)
  194. {
  195. params->hdr.tag = ATAG_NONE;
  196. params->hdr.size = 0;
  197. }
  198. #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */