bootm.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* SPARC code for booting linux 2.6
  2. *
  3. * (C) Copyright 2007
  4. * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <command.h>
  10. #include <asm/byteorder.h>
  11. #include <asm/prom.h>
  12. #include <asm/cache.h>
  13. #include <image.h>
  14. #define PRINT_KERNEL_HEADER
  15. extern image_header_t header;
  16. extern void srmmu_init_cpu(unsigned int entry);
  17. extern void prepare_bootargs(char *bootargs);
  18. #ifdef CONFIG_USB_UHCI
  19. extern int usb_lowlevel_stop(int index);
  20. #endif
  21. /* sparc kernel argument (the ROM vector) */
  22. struct linux_romvec *kernel_arg_promvec;
  23. /* page szie is 4k */
  24. #define PAGE_SIZE 0x1000
  25. #define RAMDISK_IMAGE_START_MASK 0x07FF
  26. #define RAMDISK_PROMPT_FLAG 0x8000
  27. #define RAMDISK_LOAD_FLAG 0x4000
  28. struct __attribute__ ((packed)) {
  29. char traptable[PAGE_SIZE];
  30. char swapper_pg_dir[PAGE_SIZE];
  31. char pg0[PAGE_SIZE];
  32. char pg1[PAGE_SIZE];
  33. char pg2[PAGE_SIZE];
  34. char pg3[PAGE_SIZE];
  35. char empty_bad_page[PAGE_SIZE];
  36. char empty_bad_page_table[PAGE_SIZE];
  37. char empty_zero_page[PAGE_SIZE];
  38. unsigned char hdr[4]; /* ascii "HdrS" */
  39. /* 00.02.06.0b is for Linux kernel 2.6.11 */
  40. unsigned char linuxver_mega_major;
  41. unsigned char linuxver_major;
  42. unsigned char linuxver_minor;
  43. unsigned char linuxver_revision;
  44. /* header version 0x0203 */
  45. unsigned short hdr_ver;
  46. union __attribute__ ((packed)) {
  47. struct __attribute__ ((packed)) {
  48. unsigned short root_flags;
  49. unsigned short root_dev;
  50. unsigned short ram_flags;
  51. unsigned int sparc_ramdisk_image;
  52. unsigned int sparc_ramdisk_size;
  53. unsigned int reboot_command;
  54. unsigned int resv[3];
  55. unsigned int end;
  56. } ver_0203;
  57. } hdr_input;
  58. } *linux_hdr;
  59. /* temporary initrd image holder */
  60. image_header_t ihdr;
  61. void arch_lmb_reserve(struct lmb *lmb)
  62. {
  63. /* Reserve the space used by PROM and stack. This is done
  64. * to avoid that the RAM image is copied over stack or
  65. * PROM.
  66. */
  67. lmb_reserve(lmb, CONFIG_SYS_RELOC_MONITOR_BASE, CONFIG_SYS_RAM_END);
  68. }
  69. /* boot the linux kernel */
  70. int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t * images)
  71. {
  72. char *bootargs;
  73. ulong rd_len;
  74. void (*kernel) (struct linux_romvec *, void *);
  75. int ret;
  76. /*
  77. * allow the PREP bootm subcommand, it is required for bootm to work
  78. */
  79. if (flag & BOOTM_STATE_OS_PREP)
  80. return 0;
  81. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  82. return 1;
  83. /* Get virtual address of kernel start */
  84. linux_hdr = (void *)images->os.load;
  85. /* */
  86. kernel = (void (*)(struct linux_romvec *, void *))images->ep;
  87. /* check for a SPARC kernel */
  88. if ((linux_hdr->hdr[0] != 'H') ||
  89. (linux_hdr->hdr[1] != 'd') ||
  90. (linux_hdr->hdr[2] != 'r') || (linux_hdr->hdr[3] != 'S')) {
  91. puts("Error reading header of SPARC Linux kernel, aborting\n");
  92. goto error;
  93. }
  94. #ifdef PRINT_KERNEL_HEADER
  95. printf("## Found SPARC Linux kernel %d.%d.%d ...\n",
  96. linux_hdr->linuxver_major,
  97. linux_hdr->linuxver_minor, linux_hdr->linuxver_revision);
  98. #endif
  99. #ifdef CONFIG_USB_UHCI
  100. usb_lowlevel_stop();
  101. #endif
  102. /* set basic boot params in kernel header now that it has been
  103. * extracted and is writeable.
  104. */
  105. ret = image_setup_linux(images);
  106. if (ret) {
  107. puts("### Failed to relocate RAM disk\n");
  108. goto error;
  109. }
  110. /* Calc length of RAM disk, if zero no ramdisk available */
  111. rd_len = images->rd_end - images->rd_start;
  112. if (rd_len) {
  113. /* Update SPARC kernel header so that Linux knows
  114. * what is going on and where to find RAM disk.
  115. *
  116. * Set INITRD Image address relative to RAM Start
  117. */
  118. linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image =
  119. images->initrd_start - CONFIG_SYS_RAM_BASE;
  120. linux_hdr->hdr_input.ver_0203.sparc_ramdisk_size = rd_len;
  121. /* Clear READ ONLY flag if set to non-zero */
  122. linux_hdr->hdr_input.ver_0203.root_flags = 1;
  123. /* Set root device to: Root_RAM0 */
  124. linux_hdr->hdr_input.ver_0203.root_dev = 0x100;
  125. linux_hdr->hdr_input.ver_0203.ram_flags = 0;
  126. } else {
  127. /* NOT using RAMDISK image, overwriting kernel defaults */
  128. linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image = 0;
  129. linux_hdr->hdr_input.ver_0203.sparc_ramdisk_size = 0;
  130. /* Leave to kernel defaults
  131. linux_hdr->hdr_input.ver_0203.root_flags = 1;
  132. linux_hdr->hdr_input.ver_0203.root_dev = 0;
  133. linux_hdr->hdr_input.ver_0203.ram_flags = 0;
  134. */
  135. }
  136. /* Copy bootargs from bootargs variable to kernel readable area */
  137. bootargs = getenv("bootargs");
  138. prepare_bootargs(bootargs);
  139. /* turn on mmu & setup context table & page table for process 0 (kernel) */
  140. srmmu_init_cpu((unsigned int)kernel);
  141. /* Enter SPARC Linux kernel
  142. * From now on the only code in u-boot that will be
  143. * executed is the PROM code.
  144. */
  145. kernel(kernel_arg_promvec, (void *)images->ep);
  146. /* It will never come to this... */
  147. while (1) ;
  148. error:
  149. return 1;
  150. }