misc.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * arch/ppc/simple/misc.c
  3. *
  4. * Misc. bootloader code for many machines. This assumes you have are using
  5. * a 6xx/7xx/74xx CPU in your machine. This assumes the chunk of memory
  6. * below 8MB is free. Finally, it assumes you have a NS16550-style uart for
  7. * your serial console. If a machine meets these requirements, it can quite
  8. * likely use this code during boot.
  9. *
  10. * Author: Matt Porter <mporter@mvista.com>
  11. * Derived from arch/ppc/boot/prep/misc.c
  12. *
  13. * 2001 (c) MontaVista, Software, Inc. This file is licensed under
  14. * the terms of the GNU General Public License version 2. This program
  15. * is licensed "as is" without any warranty of any kind, whether express
  16. * or implied.
  17. */
  18. #include <linux/types.h>
  19. #include <linux/config.h>
  20. #include <linux/string.h>
  21. #include <asm/page.h>
  22. #include <asm/mmu.h>
  23. #include <asm/bootinfo.h>
  24. #ifdef CONFIG_44x
  25. #include <asm/ibm4xx.h>
  26. #endif
  27. #include <asm/reg.h>
  28. #include "nonstdio.h"
  29. /* Default cmdline */
  30. #ifdef CONFIG_CMDLINE
  31. #define CMDLINE CONFIG_CMDLINE
  32. #else
  33. #define CMDLINE ""
  34. #endif
  35. /* Keyboard (and VGA console)? */
  36. #ifdef CONFIG_VGA_CONSOLE
  37. #define HAS_KEYB 1
  38. #else
  39. #define HAS_KEYB 0
  40. #endif
  41. /* Will / Can the user give input?
  42. * Val Henson has requested that Gemini doesn't wait for the
  43. * user to edit the cmdline or not.
  44. */
  45. #if (defined(CONFIG_SERIAL_8250_CONSOLE) \
  46. || defined(CONFIG_VGA_CONSOLE) \
  47. || defined(CONFIG_SERIAL_MPC52xx_CONSOLE) \
  48. || defined(CONFIG_SERIAL_MPSC_CONSOLE)) \
  49. && !defined(CONFIG_GEMINI)
  50. #define INTERACTIVE_CONSOLE 1
  51. #endif
  52. char *avail_ram;
  53. char *end_avail;
  54. char *zimage_start;
  55. char cmd_preset[] = CMDLINE;
  56. char cmd_buf[256];
  57. char *cmd_line = cmd_buf;
  58. int keyb_present = HAS_KEYB;
  59. int zimage_size;
  60. unsigned long com_port;
  61. unsigned long initrd_size = 0;
  62. /* The linker tells us various locations in the image */
  63. extern char __image_begin, __image_end;
  64. extern char __ramdisk_begin, __ramdisk_end;
  65. extern char _end[];
  66. /* Original location */
  67. extern unsigned long start;
  68. extern int CRT_tstc(void);
  69. extern unsigned long serial_init(int chan, void *ignored);
  70. extern void serial_close(unsigned long com_port);
  71. extern void gunzip(void *, int, unsigned char *, int *);
  72. extern void serial_fixups(void);
  73. /* Allow get_mem_size to be hooked into. This is the default. */
  74. unsigned long __attribute__ ((weak))
  75. get_mem_size(void)
  76. {
  77. return 0;
  78. }
  79. struct bi_record *
  80. decompress_kernel(unsigned long load_addr, int num_words, unsigned long cksum)
  81. {
  82. #ifdef INTERACTIVE_CONSOLE
  83. int timer = 0;
  84. char ch;
  85. #endif
  86. char *cp;
  87. struct bi_record *rec;
  88. unsigned long initrd_loc = 0, TotalMemory = 0;
  89. #if defined(CONFIG_SERIAL_8250_CONSOLE) || defined(CONFIG_SERIAL_MPSC_CONSOLE)
  90. com_port = serial_init(0, NULL);
  91. #endif
  92. #if defined(CONFIG_44x) && defined(PPC44x_EMAC0_MR0)
  93. /* Reset MAL */
  94. mtdcr(DCRN_MALCR(DCRN_MAL_BASE), MALCR_MMSR);
  95. /* Wait for reset */
  96. while (mfdcr(DCRN_MALCR(DCRN_MAL_BASE)) & MALCR_MMSR) {};
  97. /* Reset EMAC */
  98. *(volatile unsigned long *)PPC44x_EMAC0_MR0 = 0x20000000;
  99. __asm__ __volatile__("eieio");
  100. #endif
  101. /*
  102. * Call get_mem_size(), which is memory controller dependent,
  103. * and we must have the correct file linked in here.
  104. */
  105. TotalMemory = get_mem_size();
  106. /* assume the chunk below 8M is free */
  107. end_avail = (char *)0x00800000;
  108. /*
  109. * Reveal where we were loaded at and where we
  110. * were relocated to.
  111. */
  112. puts("loaded at: "); puthex(load_addr);
  113. puts(" "); puthex((unsigned long)(load_addr + (4*num_words)));
  114. puts("\n");
  115. if ( (unsigned long)load_addr != (unsigned long)&start )
  116. {
  117. puts("relocated to: "); puthex((unsigned long)&start);
  118. puts(" ");
  119. puthex((unsigned long)((unsigned long)&start + (4*num_words)));
  120. puts("\n");
  121. }
  122. /*
  123. * We link ourself to 0x00800000. When we run, we relocate
  124. * ourselves there. So we just need __image_begin for the
  125. * start. -- Tom
  126. */
  127. zimage_start = (char *)(unsigned long)(&__image_begin);
  128. zimage_size = (unsigned long)(&__image_end) -
  129. (unsigned long)(&__image_begin);
  130. initrd_size = (unsigned long)(&__ramdisk_end) -
  131. (unsigned long)(&__ramdisk_begin);
  132. /*
  133. * The zImage and initrd will be between start and _end, so they've
  134. * already been moved once. We're good to go now. -- Tom
  135. */
  136. avail_ram = (char *)PAGE_ALIGN((unsigned long)_end);
  137. puts("zimage at: "); puthex((unsigned long)zimage_start);
  138. puts(" "); puthex((unsigned long)(zimage_size+zimage_start));
  139. puts("\n");
  140. if ( initrd_size ) {
  141. puts("initrd at: ");
  142. puthex((unsigned long)(&__ramdisk_begin));
  143. puts(" "); puthex((unsigned long)(&__ramdisk_end));puts("\n");
  144. }
  145. avail_ram = (char *)0x00400000;
  146. end_avail = (char *)0x00800000;
  147. puts("avail ram: "); puthex((unsigned long)avail_ram); puts(" ");
  148. puthex((unsigned long)end_avail); puts("\n");
  149. if (keyb_present)
  150. CRT_tstc(); /* Forces keyboard to be initialized */
  151. #ifdef CONFIG_GEMINI
  152. /*
  153. * If cmd_line is empty and cmd_preset is not, copy cmd_preset
  154. * to cmd_line. This way we can override cmd_preset with the
  155. * command line from Smon.
  156. */
  157. if ( (cmd_line[0] == '\0') && (cmd_preset[0] != '\0'))
  158. memcpy (cmd_line, cmd_preset, sizeof(cmd_preset));
  159. #endif
  160. /* Display standard Linux/PPC boot prompt for kernel args */
  161. puts("\nLinux/PPC load: ");
  162. cp = cmd_line;
  163. memcpy (cmd_line, cmd_preset, sizeof(cmd_preset));
  164. while ( *cp ) putc(*cp++);
  165. #ifdef INTERACTIVE_CONSOLE
  166. /*
  167. * If they have a console, allow them to edit the command line.
  168. * Otherwise, don't bother wasting the five seconds.
  169. */
  170. while (timer++ < 5*1000) {
  171. if (tstc()) {
  172. while ((ch = getc()) != '\n' && ch != '\r') {
  173. /* Test for backspace/delete */
  174. if (ch == '\b' || ch == '\177') {
  175. if (cp != cmd_line) {
  176. cp--;
  177. puts("\b \b");
  178. }
  179. /* Test for ^x/^u (and wipe the line) */
  180. } else if (ch == '\030' || ch == '\025') {
  181. while (cp != cmd_line) {
  182. cp--;
  183. puts("\b \b");
  184. }
  185. } else {
  186. *cp++ = ch;
  187. putc(ch);
  188. }
  189. }
  190. break; /* Exit 'timer' loop */
  191. }
  192. udelay(1000); /* 1 msec */
  193. }
  194. *cp = 0;
  195. #endif
  196. puts("\n");
  197. puts("Uncompressing Linux...");
  198. gunzip(NULL, 0x400000, zimage_start, &zimage_size);
  199. puts("done.\n");
  200. /* get the bi_rec address */
  201. rec = bootinfo_addr(zimage_size);
  202. /* We need to make sure that the initrd and bi_recs do not
  203. * overlap. */
  204. if ( initrd_size ) {
  205. unsigned long rec_loc = (unsigned long) rec;
  206. initrd_loc = (unsigned long)(&__ramdisk_begin);
  207. /* If the bi_recs are in the middle of the current
  208. * initrd, move the initrd to the next MB
  209. * boundary. */
  210. if ((rec_loc > initrd_loc) &&
  211. ((initrd_loc + initrd_size) > rec_loc)) {
  212. initrd_loc = _ALIGN((unsigned long)(zimage_size)
  213. + (2 << 20) - 1, (2 << 20));
  214. memmove((void *)initrd_loc, &__ramdisk_begin,
  215. initrd_size);
  216. puts("initrd moved: "); puthex(initrd_loc);
  217. puts(" "); puthex(initrd_loc + initrd_size);
  218. puts("\n");
  219. }
  220. }
  221. bootinfo_init(rec);
  222. if ( TotalMemory )
  223. bootinfo_append(BI_MEMSIZE, sizeof(int), (void*)&TotalMemory);
  224. bootinfo_append(BI_CMD_LINE, strlen(cmd_line)+1, (void*)cmd_line);
  225. /* add a bi_rec for the initrd if it exists */
  226. if (initrd_size) {
  227. unsigned long initrd[2];
  228. initrd[0] = initrd_loc;
  229. initrd[1] = initrd_size;
  230. bootinfo_append(BI_INITRD, sizeof(initrd), &initrd);
  231. }
  232. puts("Now booting the kernel\n");
  233. serial_close(com_port);
  234. return rec;
  235. }
  236. void __attribute__ ((weak))
  237. board_isa_init(void)
  238. {
  239. }
  240. /* Allow decompress_kernel to be hooked into. This is the default. */
  241. void * __attribute__ ((weak))
  242. load_kernel(unsigned long load_addr, int num_words, unsigned long cksum,
  243. void *ign1, void *ign2)
  244. {
  245. board_isa_init();
  246. return decompress_kernel(load_addr, num_words, cksum);
  247. }