misc.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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_4xx
  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. #if defined(CONFIG_40x)
  80. #define PPC4xx_EMAC0_MR0 EMAC0_BASE
  81. #endif
  82. #if defined(CONFIG_44x) && defined(PPC44x_EMAC0_MR0)
  83. #define PPC4xx_EMAC0_MR0 PPC44x_EMAC0_MR0
  84. #endif
  85. struct bi_record *
  86. decompress_kernel(unsigned long load_addr, int num_words, unsigned long cksum)
  87. {
  88. #ifdef INTERACTIVE_CONSOLE
  89. int timer = 0;
  90. char ch;
  91. #endif
  92. char *cp;
  93. struct bi_record *rec;
  94. unsigned long initrd_loc = 0, TotalMemory = 0;
  95. #if defined(CONFIG_SERIAL_8250_CONSOLE) || defined(CONFIG_SERIAL_MPSC_CONSOLE)
  96. com_port = serial_init(0, NULL);
  97. #endif
  98. #if defined(PPC4xx_EMAC0_MR0)
  99. /* Reset MAL */
  100. mtdcr(DCRN_MALCR(DCRN_MAL_BASE), MALCR_MMSR);
  101. /* Wait for reset */
  102. while (mfdcr(DCRN_MALCR(DCRN_MAL_BASE)) & MALCR_MMSR) {};
  103. /* Reset EMAC */
  104. *(volatile unsigned long *)PPC4xx_EMAC0_MR0 = 0x20000000;
  105. __asm__ __volatile__("eieio");
  106. #endif
  107. /*
  108. * Call get_mem_size(), which is memory controller dependent,
  109. * and we must have the correct file linked in here.
  110. */
  111. TotalMemory = get_mem_size();
  112. /* assume the chunk below 8M is free */
  113. end_avail = (char *)0x00800000;
  114. /*
  115. * Reveal where we were loaded at and where we
  116. * were relocated to.
  117. */
  118. puts("loaded at: "); puthex(load_addr);
  119. puts(" "); puthex((unsigned long)(load_addr + (4*num_words)));
  120. puts("\n");
  121. if ( (unsigned long)load_addr != (unsigned long)&start )
  122. {
  123. puts("relocated to: "); puthex((unsigned long)&start);
  124. puts(" ");
  125. puthex((unsigned long)((unsigned long)&start + (4*num_words)));
  126. puts("\n");
  127. }
  128. /*
  129. * We link ourself to 0x00800000. When we run, we relocate
  130. * ourselves there. So we just need __image_begin for the
  131. * start. -- Tom
  132. */
  133. zimage_start = (char *)(unsigned long)(&__image_begin);
  134. zimage_size = (unsigned long)(&__image_end) -
  135. (unsigned long)(&__image_begin);
  136. initrd_size = (unsigned long)(&__ramdisk_end) -
  137. (unsigned long)(&__ramdisk_begin);
  138. /*
  139. * The zImage and initrd will be between start and _end, so they've
  140. * already been moved once. We're good to go now. -- Tom
  141. */
  142. avail_ram = (char *)PAGE_ALIGN((unsigned long)_end);
  143. puts("zimage at: "); puthex((unsigned long)zimage_start);
  144. puts(" "); puthex((unsigned long)(zimage_size+zimage_start));
  145. puts("\n");
  146. if ( initrd_size ) {
  147. puts("initrd at: ");
  148. puthex((unsigned long)(&__ramdisk_begin));
  149. puts(" "); puthex((unsigned long)(&__ramdisk_end));puts("\n");
  150. }
  151. #ifndef CONFIG_40x /* don't overwrite the 40x image located at 0x00400000! */
  152. avail_ram = (char *)0x00400000;
  153. #endif
  154. end_avail = (char *)0x00800000;
  155. puts("avail ram: "); puthex((unsigned long)avail_ram); puts(" ");
  156. puthex((unsigned long)end_avail); puts("\n");
  157. if (keyb_present)
  158. CRT_tstc(); /* Forces keyboard to be initialized */
  159. #ifdef CONFIG_GEMINI
  160. /*
  161. * If cmd_line is empty and cmd_preset is not, copy cmd_preset
  162. * to cmd_line. This way we can override cmd_preset with the
  163. * command line from Smon.
  164. */
  165. if ( (cmd_line[0] == '\0') && (cmd_preset[0] != '\0'))
  166. memcpy (cmd_line, cmd_preset, sizeof(cmd_preset));
  167. #endif
  168. /* Display standard Linux/PPC boot prompt for kernel args */
  169. puts("\nLinux/PPC load: ");
  170. cp = cmd_line;
  171. memcpy (cmd_line, cmd_preset, sizeof(cmd_preset));
  172. while ( *cp ) putc(*cp++);
  173. #ifdef INTERACTIVE_CONSOLE
  174. /*
  175. * If they have a console, allow them to edit the command line.
  176. * Otherwise, don't bother wasting the five seconds.
  177. */
  178. while (timer++ < 5*1000) {
  179. if (tstc()) {
  180. while ((ch = getc()) != '\n' && ch != '\r') {
  181. /* Test for backspace/delete */
  182. if (ch == '\b' || ch == '\177') {
  183. if (cp != cmd_line) {
  184. cp--;
  185. puts("\b \b");
  186. }
  187. /* Test for ^x/^u (and wipe the line) */
  188. } else if (ch == '\030' || ch == '\025') {
  189. while (cp != cmd_line) {
  190. cp--;
  191. puts("\b \b");
  192. }
  193. } else {
  194. *cp++ = ch;
  195. putc(ch);
  196. }
  197. }
  198. break; /* Exit 'timer' loop */
  199. }
  200. udelay(1000); /* 1 msec */
  201. }
  202. *cp = 0;
  203. #endif
  204. puts("\n");
  205. puts("Uncompressing Linux...");
  206. gunzip(NULL, 0x400000, zimage_start, &zimage_size);
  207. puts("done.\n");
  208. /* get the bi_rec address */
  209. rec = bootinfo_addr(zimage_size);
  210. /* We need to make sure that the initrd and bi_recs do not
  211. * overlap. */
  212. if ( initrd_size ) {
  213. unsigned long rec_loc = (unsigned long) rec;
  214. initrd_loc = (unsigned long)(&__ramdisk_begin);
  215. /* If the bi_recs are in the middle of the current
  216. * initrd, move the initrd to the next MB
  217. * boundary. */
  218. if ((rec_loc > initrd_loc) &&
  219. ((initrd_loc + initrd_size) > rec_loc)) {
  220. initrd_loc = _ALIGN((unsigned long)(zimage_size)
  221. + (2 << 20) - 1, (2 << 20));
  222. memmove((void *)initrd_loc, &__ramdisk_begin,
  223. initrd_size);
  224. puts("initrd moved: "); puthex(initrd_loc);
  225. puts(" "); puthex(initrd_loc + initrd_size);
  226. puts("\n");
  227. }
  228. }
  229. bootinfo_init(rec);
  230. if ( TotalMemory )
  231. bootinfo_append(BI_MEMSIZE, sizeof(int), (void*)&TotalMemory);
  232. bootinfo_append(BI_CMD_LINE, strlen(cmd_line)+1, (void*)cmd_line);
  233. /* add a bi_rec for the initrd if it exists */
  234. if (initrd_size) {
  235. unsigned long initrd[2];
  236. initrd[0] = initrd_loc;
  237. initrd[1] = initrd_size;
  238. bootinfo_append(BI_INITRD, sizeof(initrd), &initrd);
  239. }
  240. puts("Now booting the kernel\n");
  241. serial_close(com_port);
  242. return rec;
  243. }
  244. void __attribute__ ((weak))
  245. board_isa_init(void)
  246. {
  247. }
  248. /* Allow decompress_kernel to be hooked into. This is the default. */
  249. void * __attribute__ ((weak))
  250. load_kernel(unsigned long load_addr, int num_words, unsigned long cksum,
  251. void *ign1, void *ign2)
  252. {
  253. board_isa_init();
  254. return decompress_kernel(load_addr, num_words, cksum);
  255. }