bootm.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* SPARC code for booting linux 2.6
  2. *
  3. * (C) Copyright 2007
  4. * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <command.h>
  26. #include <asm/byteorder.h>
  27. #include <asm/prom.h>
  28. #include <asm/cache.h>
  29. #define PRINT_KERNEL_HEADER
  30. extern image_header_t header;
  31. extern void srmmu_init_cpu(unsigned int entry);
  32. extern void prepare_bootargs(char *bootargs);
  33. extern int do_reset(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
  34. #ifdef CONFIG_USB_UHCI
  35. extern int usb_lowlevel_stop(void);
  36. #endif
  37. /* sparc kernel argument (the ROM vector) */
  38. struct linux_romvec *kernel_arg_promvec;
  39. /* page szie is 4k */
  40. #define PAGE_SIZE 0x1000
  41. #define RAMDISK_IMAGE_START_MASK 0x07FF
  42. #define RAMDISK_PROMPT_FLAG 0x8000
  43. #define RAMDISK_LOAD_FLAG 0x4000
  44. struct __attribute__ ((packed)) {
  45. char traptable[PAGE_SIZE];
  46. char swapper_pg_dir[PAGE_SIZE];
  47. char pg0[PAGE_SIZE];
  48. char pg1[PAGE_SIZE];
  49. char pg2[PAGE_SIZE];
  50. char pg3[PAGE_SIZE];
  51. char empty_bad_page[PAGE_SIZE];
  52. char empty_bad_page_table[PAGE_SIZE];
  53. char empty_zero_page[PAGE_SIZE];
  54. unsigned char hdr[4]; /* ascii "HdrS" */
  55. /* 00.02.06.0b is for Linux kernel 2.6.11 */
  56. unsigned char linuxver_mega_major;
  57. unsigned char linuxver_major;
  58. unsigned char linuxver_minor;
  59. unsigned char linuxver_revision;
  60. /* header version 0x0203 */
  61. unsigned short hdr_ver;
  62. union __attribute__ ((packed)) {
  63. struct __attribute__ ((packed)) {
  64. unsigned short root_flags;
  65. unsigned short root_dev;
  66. unsigned short ram_flags;
  67. unsigned int sparc_ramdisk_image;
  68. unsigned int sparc_ramdisk_size;
  69. unsigned int reboot_command;
  70. unsigned int resv[3];
  71. unsigned int end;
  72. } ver_0203;
  73. } hdr_input;
  74. } *linux_hdr;
  75. /* temporary initrd image holder */
  76. image_header_t ihdr;
  77. /* boot the linux kernel */
  78. void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
  79. bootm_headers_t * images)
  80. {
  81. char *bootargs;
  82. ulong load;
  83. ulong initrd_start, initrd_end;
  84. ulong rd_len;
  85. unsigned int data, len, checksum;
  86. unsigned int initrd_addr, kernend;
  87. void (*kernel) (struct linux_romvec *, void *);
  88. struct lmb *lmb = &images->lmb;
  89. int ret;
  90. if (images->legacy_hdr_valid) {
  91. load = image_get_load(images->legacy_hdr_os);
  92. #if defined(CONFIG_FIT)
  93. } else if (images->fit_uname_os) {
  94. ret = fit_image_get_load(images->fit_hdr_os,
  95. images->fit_noffset_os, &load);
  96. if (ret) {
  97. puts("Can't get load address property!\n");
  98. goto error;
  99. }
  100. #endif
  101. } else {
  102. puts("Could not find kernel entry point!\n");
  103. goto error;
  104. }
  105. /* Get virtual address of kernel start */
  106. linux_hdr = (void *)load;
  107. /* */
  108. kernel = (void (*)(struct linux_romvec *, void *))images->ep;
  109. /* check for a SPARC kernel */
  110. if ((linux_hdr->hdr[0] != 'H') ||
  111. (linux_hdr->hdr[1] != 'd') ||
  112. (linux_hdr->hdr[2] != 'r') || (linux_hdr->hdr[3] != 'S')) {
  113. puts("Error reading header of SPARC Linux kernel, aborting\n");
  114. goto error;
  115. }
  116. #ifdef PRINT_KERNEL_HEADER
  117. printf("## Found SPARC Linux kernel %d.%d.%d ...\n",
  118. linux_hdr->linuxver_major,
  119. linux_hdr->linuxver_minor, linux_hdr->linuxver_revision);
  120. #endif
  121. #ifdef CONFIG_USB_UHCI
  122. usb_lowlevel_stop();
  123. #endif
  124. /* set basic boot params in kernel header now that it has been
  125. * extracted and is writeable.
  126. */
  127. /* Calc length of RAM disk, if zero no ramdisk available */
  128. rd_len = images->rd_end - images->rd_start;
  129. if (rd_len) {
  130. /* Reserve the space used by PROM and stack. This is done
  131. * to avoid that the RAM image is copied over stack or
  132. * PROM.
  133. */
  134. lmb_reserve(lmb, CFG_RELOC_MONITOR_BASE, CFG_RAM_END);
  135. ret = boot_ramdisk_high(lmb, images->rd_start, rd_len,
  136. &initrd_start, &initrd_end);
  137. if (ret) {
  138. puts("### Failed to relocate RAM disk\n");
  139. goto error;
  140. }
  141. /* Update SPARC kernel header so that Linux knows
  142. * what is going on and where to find RAM disk.
  143. *
  144. * Set INITRD Image address relative to RAM Start
  145. */
  146. linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image =
  147. initrd_start - CFG_RAM_BASE;
  148. linux_hdr->hdr_input.ver_0203.sparc_ramdisk_size = rd_len;
  149. /* Clear READ ONLY flag if set to non-zero */
  150. linux_hdr->hdr_input.ver_0203.root_flags = 1;
  151. /* Set root device to: Root_RAM0 */
  152. linux_hdr->hdr_input.ver_0203.root_dev = 0x100;
  153. linux_hdr->hdr_input.ver_0203.ram_flags = 0;
  154. } else {
  155. /* NOT using RAMDISK image, overwriting kernel defaults */
  156. linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image = 0;
  157. linux_hdr->hdr_input.ver_0203.sparc_ramdisk_size = 0;
  158. /* Leave to kernel defaults
  159. linux_hdr->hdr_input.ver_0203.root_flags = 1;
  160. linux_hdr->hdr_input.ver_0203.root_dev = 0;
  161. linux_hdr->hdr_input.ver_0203.ram_flags = 0;
  162. */
  163. }
  164. /* Copy bootargs from bootargs variable to kernel readable area */
  165. bootargs = getenv("bootargs");
  166. prepare_bootargs(bootargs);
  167. /* turn on mmu & setup context table & page table for process 0 (kernel) */
  168. srmmu_init_cpu((unsigned int)kernel);
  169. /* Enter SPARC Linux kernel
  170. * From now on the only code in u-boot that will be
  171. * executed is the PROM code.
  172. */
  173. kernel(kernel_arg_promvec, (void *)ep);
  174. /* It will never come to this... */
  175. while (1) ;
  176. error:
  177. do_reset(cmdtp, flag, argc, argv);
  178. return;
  179. }