bootm.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 <zlib.h>
  26. #include <asm/byteorder.h>
  27. #include <asm/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. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  35. static struct tag *setup_start_tag(struct tag *params)
  36. {
  37. params->hdr.tag = ATAG_CORE;
  38. params->hdr.size = tag_size(tag_core);
  39. params->u.core.flags = 0;
  40. params->u.core.pagesize = 4096;
  41. params->u.core.rootdev = 0;
  42. return tag_next(params);
  43. }
  44. static struct tag *setup_memory_tags(struct tag *params)
  45. {
  46. bd_t *bd = gd->bd;
  47. int i;
  48. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  49. params->hdr.tag = ATAG_MEM;
  50. params->hdr.size = tag_size(tag_mem_range);
  51. params->u.mem_range.addr = bd->bi_dram[i].start;
  52. params->u.mem_range.size = bd->bi_dram[i].size;
  53. params = tag_next(params);
  54. }
  55. return params;
  56. }
  57. static struct tag *setup_commandline_tag(struct tag *params, char *cmdline)
  58. {
  59. if (!cmdline)
  60. return params;
  61. /* eat leading white space */
  62. while (*cmdline == ' ') cmdline++;
  63. /*
  64. * Don't include tags for empty command lines; let the kernel
  65. * use its default command line.
  66. */
  67. if (*cmdline == '\0')
  68. return params;
  69. params->hdr.tag = ATAG_CMDLINE;
  70. params->hdr.size =
  71. (sizeof (struct tag_header) + strlen(cmdline) + 1 + 3) >> 2;
  72. strcpy(params->u.cmdline.cmdline, cmdline);
  73. return tag_next(params);
  74. }
  75. static struct tag *setup_ramdisk_tag(struct tag *params,
  76. unsigned long rd_start,
  77. unsigned long rd_end)
  78. {
  79. if (rd_start == rd_end)
  80. return params;
  81. params->hdr.tag = ATAG_RDIMG;
  82. params->hdr.size = tag_size(tag_mem_range);
  83. params->u.mem_range.addr = rd_start;
  84. params->u.mem_range.size = rd_end - rd_start;
  85. return tag_next(params);
  86. }
  87. static struct tag *setup_clock_tags(struct tag *params)
  88. {
  89. params->hdr.tag = ATAG_CLOCK;
  90. params->hdr.size = tag_size(tag_clock);
  91. params->u.clock.clock_id = ACLOCK_BOOTCPU;
  92. params->u.clock.clock_flags = 0;
  93. params->u.clock.clock_hz = gd->cpu_hz;
  94. #ifdef CONFIG_AT32AP7000
  95. /*
  96. * New kernels don't need this, but we should be backwards
  97. * compatible for a while...
  98. */
  99. params = tag_next(params);
  100. params->hdr.tag = ATAG_CLOCK;
  101. params->hdr.size = tag_size(tag_clock);
  102. params->u.clock.clock_id = ACLOCK_HSB;
  103. params->u.clock.clock_flags = 0;
  104. params->u.clock.clock_hz = get_hsb_clk_rate();
  105. #endif
  106. return tag_next(params);
  107. }
  108. static struct tag *setup_ethernet_tag(struct tag *params,
  109. char *addr, int index)
  110. {
  111. char *s, *e;
  112. int i;
  113. params->hdr.tag = ATAG_ETHERNET;
  114. params->hdr.size = tag_size(tag_ethernet);
  115. params->u.ethernet.mac_index = index;
  116. params->u.ethernet.mii_phy_addr = gd->bd->bi_phy_id[index];
  117. s = addr;
  118. for (i = 0; i < 6; i++) {
  119. params->u.ethernet.hw_address[i] = simple_strtoul(s, &e, 16);
  120. s = e + 1;
  121. }
  122. return tag_next(params);
  123. }
  124. static struct tag *setup_ethernet_tags(struct tag *params)
  125. {
  126. char name[16] = "ethaddr";
  127. char *addr;
  128. int i = 0;
  129. do {
  130. addr = getenv(name);
  131. if (addr)
  132. params = setup_ethernet_tag(params, addr, i);
  133. sprintf(name, "eth%daddr", ++i);
  134. } while (i < 4);
  135. return params;
  136. }
  137. static void setup_end_tag(struct tag *params)
  138. {
  139. params->hdr.tag = ATAG_NONE;
  140. params->hdr.size = 0;
  141. }
  142. void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  143. bootm_headers_t *images)
  144. {
  145. ulong initrd_start, initrd_end;
  146. void (*theKernel)(int magic, void *tagtable);
  147. struct tag *params, *params_start;
  148. char *commandline = getenv("bootargs");
  149. int ret;
  150. theKernel = (void *)images->ep;
  151. ret = boot_get_ramdisk (argc, argv, images, IH_ARCH_AVR32,
  152. &initrd_start, &initrd_end);
  153. if (ret)
  154. goto error;
  155. show_boot_progress (15);
  156. params = params_start = (struct tag *)gd->bd->bi_boot_params;
  157. params = setup_start_tag(params);
  158. params = setup_memory_tags(params);
  159. if (initrd_start) {
  160. params = setup_ramdisk_tag(params,
  161. PHYSADDR(initrd_start),
  162. PHYSADDR(initrd_end));
  163. }
  164. params = setup_commandline_tag(params, commandline);
  165. params = setup_clock_tags(params);
  166. params = setup_ethernet_tags(params);
  167. setup_end_tag(params);
  168. printf("\nStarting kernel at %p (params at %p)...\n\n",
  169. theKernel, params_start);
  170. prepare_to_boot();
  171. theKernel(ATAG_MAGIC, params_start);
  172. /* does not return */
  173. return;
  174. error:
  175. do_reset (cmdtp, flag, argc, argv);
  176. return;
  177. }