Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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