bootm.c 4.5 KB

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