misc-simple.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * arch/ppc/common/misc-simple.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.  * Copyright 2001 MontaVista Software Inc.
  14.  *
  15.  * This program is free software; you can redistribute  it and/or modify it
  16.  * under  the terms of  the GNU General  Public License as published by the
  17.  * Free Software Foundation;  either version 2 of the  License, or (at your
  18.  * option) any later version.
  19.  */
  20. #include <linux/types.h>
  21. #include <linux/elf.h>
  22. #include <linux/config.h>
  23. #include <asm/page.h>
  24. #include <asm/processor.h>
  25. #include <asm/mmu.h>
  26. #include <asm/bootinfo.h>
  27. #include "nonstdio.h"
  28. #include "zlib.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. char *avail_ram;
  42. char *end_avail;
  43. char *zimage_start;
  44. char cmd_preset[] = CMDLINE;
  45. char cmd_buf[256];
  46. char *cmd_line = cmd_buf;
  47. int keyb_present = HAS_KEYB;
  48. int zimage_size;
  49. unsigned long com_port;
  50. unsigned long initrd_size = 0;
  51. /* The linker tells us various locations in the image */
  52. extern char __image_begin, __image_end;
  53. extern char __ramdisk_begin, __ramdisk_end;
  54. extern char _end[];
  55. /* Original location */
  56. extern unsigned long start;
  57. extern int CRT_tstc(void);
  58. extern unsigned long serial_init(int chan, void *ignored);
  59. extern void serial_close(unsigned long com_port);
  60. extern void gunzip(void *, int, unsigned char *, int *);
  61. extern void serial_fixups(void);
  62. struct bi_record *
  63. decompress_kernel(unsigned long load_addr, int num_words, unsigned long cksum)
  64. {
  65. int timer = 0;
  66. char *cp, ch;
  67. struct bi_record *rec, *birecs;
  68. serial_fixups();
  69. com_port = serial_init(0, NULL);
  70. /* assume the chunk below 8M is free */
  71. end_avail = (char *)0x00800000;
  72. /*
  73.  * Reveal where we were loaded at and where we
  74.  * were relocated to.
  75.  */
  76. puts("loaded at:     "); puthex(load_addr);
  77. puts(" "); puthex((unsigned long)(load_addr + (4*num_words)));
  78. puts("n");
  79. if ( (unsigned long)load_addr != (unsigned long)&start )
  80. {
  81. puts("relocated to:  "); puthex((unsigned long)&start);
  82. puts(" ");
  83. puthex((unsigned long)((unsigned long)&start + (4*num_words)));
  84. puts("n");
  85. }
  86. /*
  87.  * We link ourself to 0x00800000.  When we run, we relocate
  88.  * ourselves there.  So we just need __image_begin for the
  89.  * start. -- Tom
  90.  */
  91. zimage_start = (char *)(unsigned long)(&__image_begin);
  92. zimage_size = (unsigned long)(&__image_end) -
  93. (unsigned long)(&__image_begin);
  94. initrd_size = (unsigned long)(&__ramdisk_end) -
  95. (unsigned long)(&__ramdisk_begin);
  96. /*
  97.  * The zImage and initrd will be between start and _end, so they've
  98.  * already been moved once.  We're good to go now. -- Tom
  99.  */
  100. avail_ram = (char *)PAGE_ALIGN((unsigned long)_end);
  101. puts("zimage at:     "); puthex((unsigned long)zimage_start);
  102. puts(" "); puthex((unsigned long)(zimage_size+zimage_start));
  103. puts("n");
  104. if ( initrd_size ) {
  105. puts("initrd at:     ");
  106. puthex((unsigned long)(&__ramdisk_begin));
  107. puts(" "); puthex((unsigned long)(&__ramdisk_end));puts("n");
  108. }
  109. avail_ram = (char *)0x00400000;
  110. end_avail = (char *)0x00800000;
  111. puts("avail ram:     "); puthex((unsigned long)avail_ram); puts(" ");
  112. puthex((unsigned long)end_avail); puts("n");
  113. if (keyb_present)
  114. CRT_tstc();  /* Forces keyboard to be initialized */
  115. #ifdef CONFIG_GEMINI
  116. /*
  117.  * If cmd_line is empty and cmd_preset is not, copy cmd_preset
  118.  * to cmd_line.  This way we can override cmd_preset with the
  119.  * command line from Smon.
  120.  */
  121. if ( (cmd_line[0] == '') && (cmd_preset[0] != ''))
  122. memcpy (cmd_line, cmd_preset, sizeof(cmd_preset));
  123. #endif
  124. /* Display standard Linux/PPC boot prompt for kernel args */
  125. puts("nLinux/PPC load: ");
  126. cp = cmd_line;
  127. memcpy (cmd_line, cmd_preset, sizeof(cmd_preset));
  128. while ( *cp ) putc(*cp++);
  129. #if (defined(CONFIG_SERIAL_CONSOLE) || defined(CONFIG_VGA_CONSOLE)) 
  130. && !defined(CONFIG_GEMINI)
  131. /*
  132.  * If they have a console, allow them to edit the command line.
  133.  * Otherwise, don't bother wasting the five seconds.
  134.  */
  135. while (timer++ < 5*1000) {
  136. if (tstc()) {
  137. while ((ch = getc()) != 'n' && ch != 'r') {
  138. /* Test for backspace/delete */
  139. if (ch == 'b' || ch == '177') {
  140. if (cp != cmd_line) {
  141. cp--;
  142. puts("b b");
  143. }
  144. /* Test for ^x/^u (and wipe the line) */
  145. } else if (ch == '30' || ch == '25') {
  146. while (cp != cmd_line) {
  147. cp--;
  148. puts("b b");
  149. }
  150. } else {
  151. *cp++ = ch;
  152. putc(ch);
  153. }
  154. }
  155. break;  /* Exit 'timer' loop */
  156. }
  157. udelay(1000);  /* 1 msec */
  158. }
  159. *cp = 0;
  160. #endif
  161. puts("n");
  162. puts("Uncompressing Linux...");
  163. gunzip(0, 0x400000, zimage_start, &zimage_size);
  164. puts("done.n");
  165. /*
  166.  * Create bi_recs for cmd_line and initrds
  167.  */
  168. rec = (struct bi_record *)_ALIGN((unsigned long)(zimage_size) +
  169. (1 << 20) - 1, (1 << 20));
  170. birecs = rec;
  171. rec->tag = BI_FIRST;
  172. rec->size = sizeof(struct bi_record);
  173. rec = (struct bi_record *)((unsigned long)rec + rec->size);
  174. rec->tag = BI_CMD_LINE;
  175. memcpy( (char *)rec->data, cmd_line, strlen(cmd_line)+1);
  176. rec->size = sizeof(struct bi_record) + strlen(cmd_line) + 1;
  177. rec = (struct bi_record *)((unsigned long)rec + rec->size);
  178. if ( initrd_size ) {
  179. rec->tag = BI_INITRD;
  180. rec->data[0] = (unsigned long)(&__ramdisk_begin);
  181. rec->data[1] = initrd_size;
  182. rec->size = sizeof(struct bi_record) + 2 *
  183. sizeof(unsigned long);
  184. rec = (struct bi_record *)((unsigned long)rec +
  185. rec->size);
  186. }
  187. rec->tag = BI_LAST;
  188. rec->size = sizeof(struct bi_record);
  189. rec = (struct bi_record *)((unsigned long)rec + rec->size);
  190. puts("Now booting the kerneln");
  191. serial_close(com_port);
  192. return birecs;
  193. }