bootm.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <command.h>
  24. #include <image.h>
  25. #include <u-boot/zlib.h>
  26. #include <asm/byteorder.h>
  27. #include <asm/arch/addrspace.h>
  28. #include <asm/io.h>
  29. #include <asm/setup.h>
  30. #include <asm/arch/clk.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. /* CPU-specific hook to allow flushing of caches, etc. */
  33. extern void prepare_to_boot(void);
  34. static struct tag *setup_start_tag(struct tag *params)
  35. {
  36. params->hdr.tag = ATAG_CORE;
  37. params->hdr.size = tag_size(tag_core);
  38. params->u.core.flags = 0;
  39. params->u.core.pagesize = 4096;
  40. params->u.core.rootdev = 0;
  41. return tag_next(params);
  42. }
  43. static struct tag *setup_memory_tags(struct tag *params)
  44. {
  45. bd_t *bd = gd->bd;
  46. int i;
  47. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  48. params->hdr.tag = ATAG_MEM;
  49. params->hdr.size = tag_size(tag_mem_range);
  50. params->u.mem_range.addr = bd->bi_dram[i].start;
  51. params->u.mem_range.size = bd->bi_dram[i].size;
  52. params = tag_next(params);
  53. }
  54. return params;
  55. }
  56. static struct tag *setup_commandline_tag(struct tag *params, char *cmdline)
  57. {
  58. if (!cmdline)
  59. return params;
  60. /* eat leading white space */
  61. while (*cmdline == ' ') cmdline++;
  62. /*
  63. * Don't include tags for empty command lines; let the kernel
  64. * use its default command line.
  65. */
  66. if (*cmdline == '\0')
  67. return params;
  68. params->hdr.tag = ATAG_CMDLINE;
  69. params->hdr.size =
  70. (sizeof (struct tag_header) + strlen(cmdline) + 1 + 3) >> 2;
  71. strcpy(params->u.cmdline.cmdline, cmdline);
  72. return tag_next(params);
  73. }
  74. static struct tag *setup_ramdisk_tag(struct tag *params,
  75. unsigned long rd_start,
  76. unsigned long rd_end)
  77. {
  78. if (rd_start == rd_end)
  79. return params;
  80. params->hdr.tag = ATAG_RDIMG;
  81. params->hdr.size = tag_size(tag_mem_range);
  82. params->u.mem_range.addr = rd_start;
  83. params->u.mem_range.size = rd_end - rd_start;
  84. return tag_next(params);
  85. }
  86. static struct tag *setup_clock_tags(struct tag *params)
  87. {
  88. params->hdr.tag = ATAG_CLOCK;
  89. params->hdr.size = tag_size(tag_clock);
  90. params->u.clock.clock_id = ACLOCK_BOOTCPU;
  91. params->u.clock.clock_flags = 0;
  92. params->u.clock.clock_hz = gd->cpu_hz;
  93. #ifdef CONFIG_AT32AP7000
  94. /*
  95. * New kernels don't need this, but we should be backwards
  96. * compatible for a while...
  97. */
  98. params = tag_next(params);
  99. params->hdr.tag = ATAG_CLOCK;
  100. params->hdr.size = tag_size(tag_clock);
  101. params->u.clock.clock_id = ACLOCK_HSB;
  102. params->u.clock.clock_flags = 0;
  103. params->u.clock.clock_hz = get_hsb_clk_rate();
  104. #endif
  105. return tag_next(params);
  106. }
  107. static struct tag *setup_ethernet_tag(struct tag *params,
  108. char *addr, int index)
  109. {
  110. char *s, *e;
  111. int i;
  112. params->hdr.tag = ATAG_ETHERNET;
  113. params->hdr.size = tag_size(tag_ethernet);
  114. params->u.ethernet.mac_index = index;
  115. params->u.ethernet.mii_phy_addr = gd->bd->bi_phy_id[index];
  116. s = addr;
  117. for (i = 0; i < 6; i++) {
  118. params->u.ethernet.hw_address[i] = simple_strtoul(s, &e, 16);
  119. s = e + 1;
  120. }
  121. return tag_next(params);
  122. }
  123. static struct tag *setup_ethernet_tags(struct tag *params)
  124. {
  125. char name[16] = "ethaddr";
  126. char *addr;
  127. int i = 0;
  128. do {
  129. addr = getenv(name);
  130. if (addr)
  131. params = setup_ethernet_tag(params, addr, i);
  132. sprintf(name, "eth%daddr", ++i);
  133. } while (i < 4);
  134. return params;
  135. }
  136. static void setup_end_tag(struct tag *params)
  137. {
  138. params->hdr.tag = ATAG_NONE;
  139. params->hdr.size = 0;
  140. }
  141. int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
  142. {
  143. void (*theKernel)(int magic, void *tagtable);
  144. struct tag *params, *params_start;
  145. char *commandline = getenv("bootargs");
  146. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  147. return 1;
  148. theKernel = (void *)images->ep;
  149. show_boot_progress (15);
  150. params = params_start = (struct tag *)gd->bd->bi_boot_params;
  151. params = setup_start_tag(params);
  152. params = setup_memory_tags(params);
  153. if (images->rd_start) {
  154. params = setup_ramdisk_tag(params,
  155. PHYSADDR(images->rd_start),
  156. PHYSADDR(images->rd_end));
  157. }
  158. params = setup_commandline_tag(params, commandline);
  159. params = setup_clock_tags(params);
  160. params = setup_ethernet_tags(params);
  161. setup_end_tag(params);
  162. printf("\nStarting kernel at %p (params at %p)...\n\n",
  163. theKernel, params_start);
  164. prepare_to_boot();
  165. theKernel(ATAG_MAGIC, params_start);
  166. /* does not return */
  167. return 1;
  168. }