--- linuxppc_2_4_devel/arch/ppc/boot/prep/head.S	Mon Nov 26 17:09:43 2001
+++ linuxppc_2_4_devel-140/arch/ppc/boot/prep/head.S	Mon Dec  3 18:12:40 2001
@@ -18,6 +18,12 @@
  *      Jump to the kernel entry
  *            -- Cort
  */
+
+#define CMD_BUF_LEN	256
+	.globl	cmd_buf		/* cmd_buf is here so that it can easily */
+cmd_buf:			/* be modified by an external tool       */
+	.space	CMD_BUF_LEN,0
+
 	.globl	start
 start:
 	bl	start_
@@ -48,8 +54,8 @@
 	mtmsr	r3
 
 	/* compute the size of the whole image in words. */
-	lis	r4,start@h
-	ori	r4,r4,start@l
+	lis	r4,cmd_buf@h
+	ori	r4,r4,cmd_buf@l
 	lis	r5,end@h
 	ori	r5,r5,end@l
 	addi	r5,r5,3		/* round up */
@@ -60,7 +66,7 @@
 	/* check if we need to relocate ourselves to the link addr or were
 	 * we loaded there to begin with -- Cort */
 	mflr	r3
-	subi	r3,r3,4		/* we get the nip, not the ip of the branch */
+	subi	r3,r3,CMD_BUF_LEN+4	/* adjust nip->ip, + cmd_buf length */
 	mr	r8,r3
 	cmp	0,r3,r4
 	beq	start_ldr	/* If 0, we don't need to relocate */
@@ -68,11 +74,11 @@
  * no matter where we're loaded, move ourselves to -Ttext address
  */
 relocate:
-	mflr	r3		/* Compute code bias */
-	subi	r3,r3,4
+	mflr	r3			/* Compute code bias */
+	subi	r3,r3,CMD_BUF_LEN+4	/* adjust nip->ip, + cmd_buf length */
 	mr	r8,r3
-	lis	r4,start@h
-	ori	r4,r4,start@l
+	lis	r4,cmd_buf@h
+	ori	r4,r4,cmd_buf@l
 	mr	r5,r7		/* Get the # of longwords again */
 	mtctr	r5		/* Setup for loop */
 	li	r6,0
--- linuxppc_2_4_devel/arch/ppc/boot/prep/misc.c	Mon Nov 26 17:09:41 2001
+++ linuxppc_2_4_devel-140/arch/ppc/boot/prep/misc.c	Mon Nov 26 22:27:56 2001
@@ -38,13 +38,7 @@
 extern char __ramdisk_begin, __ramdisk_end;
 extern char _end[];
 
-#ifdef CONFIG_CMDLINE
-#define CMDLINE CONFIG_CMDLINE
-#else
-#define CMDLINE ""
-#endif
-char cmd_preset[] = CMDLINE;
-char cmd_buf[256];
+extern char cmd_buf[256];
 char *cmd_line = cmd_buf;
 
 int keyb_present = 1;	/* keyboard controller is present by default */
@@ -118,13 +112,69 @@
 }
 #endif /* CONFIG_VGA_CONSOLE */
 
+void
+read_args(void)
+{
+	int timer = 0;
+	char *cp, ch;
+
+	puts("\nLinux/PPC load: ");
+	cp = cmd_line;
+	while ( *cp ) putc(*cp++);
+	while (timer++ < 5*1000) {
+		if (tstc()) {
+			while ((ch = getc()) != '\n' && ch != '\r') {
+				/* Test for backspace/delete */
+				if (ch == '\b' || ch == '\177') {
+					if (cp != cmd_line) {
+						cp--;
+						puts("\b \b");
+					}
+				/* Test for ^x/^u (and wipe the line) */
+				} else if (ch == '\030' || ch == '\025') {
+					while (cp != cmd_line) {
+						cp--;
+						puts("\b \b");
+					}
+				} else {
+					*cp++ = ch;
+					putc(ch);
+				}
+			}
+			break;  /* Exit 'timer' loop */
+		}
+		udelay(1000);  /* 1 msec */
+	}
+	*cp = 0;
+	puts("\n");
+}
+
+int
+get_of_args(void)
+{
+	int chosen, size, res;
+	char buf[256];
+
+	/* Get bootargs property of /chosen node */
+	res = of_finddevice("/chosen", &chosen);
+	if (!res) 
+		res = of_getprop(chosen, "bootargs", buf, sizeof(buf), &size);
+
+	if (!res) {
+		if (strlen(buf))
+			memcpy(cmd_buf, buf, strlen(buf) + 1);
+		else
+			res = -1;
+	}
+
+	return res;
+}
+
 unsigned long
 decompress_kernel(unsigned long load_addr, int num_words, unsigned long cksum,
 		  RESIDUAL *residual, void *OFW_interface)
 {
-	int timer = 0;
 	extern unsigned long start;
-	char *cp, ch;
 	unsigned long TotalMemory;
 	int dev_handle;
 	int mem_info[2];
@@ -155,6 +205,20 @@
 		puts("\n");
 	}
 
+	/* Initialise the OpenFirmware but only if the entry point
+	 * is in a sane location...
+	 */
+	if (OFW_interface) {
+		if ((unsigned long)OFW_interface < 0x10000000) {
+			/* Restore the slightly inaccurate
+			 * MSR so that OpenFirmware will behave. -- Tom
+			 */
+			_put_MSR(orig_MSR);
+			of_init(OFW_interface);
+		} else
+			OFW_interface = 0;
+	}
+
 	if (residual) {
 		/*
 		 * Tell the user where the residual data is.
@@ -227,14 +291,8 @@
 		 * we don't try this on a PReP box without OF
 		 *     -- Cort
 		 */
-		while (OFW_interface && ((unsigned long)OFW_interface < 0x10000000) )
+		while (OFW_interface)
 		{
-			/* We need to restore the slightly inaccurate
-			 * MSR so that OpenFirmware will behave. -- Tom
-			 */
-			_put_MSR(orig_MSR);
-			of_init(OFW_interface);
-
 			/* get handle to memory description */
 			res = of_finddevice("/memory@0",
 					    &dev_handle);
@@ -257,8 +315,6 @@
 		hold_residual->TotalMemory = TotalMemory;
 		residual = hold_residual;
 
-		/* Enforce a sane MSR for booting. */
-		_put_MSR(MSR_IP);
         }
 
 	/* assume the chunk below 8M is free */
@@ -299,36 +355,16 @@
 	if (keyb_present)
 		CRT_tstc();  /* Forces keyboard to be initialized */
 
-	puts("\nLinux/PPC load: ");
-	cp = cmd_line;
-	memcpy (cmd_line, cmd_preset, sizeof(cmd_preset));
-	while ( *cp ) putc(*cp++);
-	while (timer++ < 5*1000) {
-		if (tstc()) {
-			while ((ch = getc()) != '\n' && ch != '\r') {
-				/* Test for backspace/delete */
-				if (ch == '\b' || ch == '\177') {
-					if (cp != cmd_line) {
-						cp--;
-						puts("\b \b");
-					}
-				/* Test for ^x/^u (and wipe the line) */
-				} else if (ch == '\030' || ch == '\025') {
-					while (cp != cmd_line) {
-						cp--;
-						puts("\b \b");
-					}
-				} else {
-					*cp++ = ch;
-					putc(ch);
-				}
-			}
-			break;  /* Exit 'timer' loop */
-		}
-		udelay(1000);  /* 1 msec */
-	}
-	*cp = 0;
-	puts("\n");
+	/* If we have OF then try to get args from there */
+	if (OFW_interface)
+		get_of_args();
+
+	/* Always give an opportunity to change the arguments */
+	read_args();
+
+	/* Enforce a sane MSR for booting. */
+	if (OFW_interface)
+		_put_MSR(MSR_IP);
 
 	puts("Uncompressing Linux...");
 
--- linuxppc_2_4_devel/arch/ppc/boot/utils/mkprep.c	Mon Nov 26 17:09:54 2001
+++ linuxppc_2_4_devel-140/arch/ppc/boot/utils/mkprep.c	Mon Nov 26 22:27:56 2001
@@ -165,10 +165,10 @@
  
   /* set entry point and boot image size skipping over elf header */
 #ifdef __i386__
-  *entry = 0x400/*+65536*/;
+  *entry = 0x500/*+65536*/;
   *length = info.st_size-elfhdr_size+0x400;
 #else
-  *entry = cpu_to_le32(0x400/*+65536*/);
+  *entry = cpu_to_le32(0x500/*+65536*/);
   *length = cpu_to_le32(info.st_size-elfhdr_size+0x400);
 #endif /* __i386__ */
 
