Subject: Re: Booting a LiveCD
To: Chris Ross <cross@distal.com>
From: Martin Husemann <martin@duskware.de>
List: port-sparc64
Date: 09/20/2007 21:01:24
--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Thu, Sep 20, 2007 at 11:52:24AM -0400, Chris Ross wrote:
>   I have an ofwquestion that I've been meaning to ask.  I notice  
> that the BOOTP
> support in net_open doesn't know enough to learn from the parameters it
> gets back from a DHCP server. 

This does not fit well into the structure of the bootloader (the results
from DHCP are available only after opening the network device, which is
long after all option parsing has happened). I did a quick hack that does
it partly, but does not get all debugging output correct and is so ugly
I do not want to commit it ;-)

Doing it correctly probably needs more restructuring, which I'm not sure
is worth the effort.

Note that it only works if you do not use DHCP at the prom level to load
ofwboot, and requires an unset boot-file variable.

Martin

--wRRV7LY7NUeQGEoC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch

Index: boot.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/stand/ofwboot/boot.c,v
retrieving revision 1.17
diff -u -p -r1.17 boot.c
--- boot.c	20 Sep 2007 09:25:00 -0000	1.17
+++ boot.c	20 Sep 2007 18:53:38 -0000
@@ -92,6 +92,9 @@ char bootdev[PROM_MAX_PATH];
 
 int debug  = 0;
 int compatmode = 0;
+int is_default_kernelname = 0;
+int kernelname_replaced_by_bootfile = 0;
+extern char bootfile[];
 
 #if 0
 static void
@@ -349,7 +352,10 @@ start_kernel(char *kernel, char *bootlin
 	 * by PROM. Otherwise, map the kernel with 4MB permanent pages.
 	 */
 	loadfile_set_allocator(LOADFILE_NOP_ALLOCATOR);
-	if ( (fd = loadfile(kernel, marks, LOAD_HDR|COUNT_TEXT)) != -1) {
+	fd = loadfile(kernel, marks, LOAD_HDR|COUNT_TEXT);
+	if (kernelname_replaced_by_bootfile)
+		kernel = bootfile;
+	if (fd != -1) {
 		if (COMPAT_BOOT(marks) || compatmode) {
 			(void)printf("[c] ");
 			loadfile_set_allocator(LOADFILE_OFW_ALLOCATOR);
@@ -423,12 +429,15 @@ main(void *ofw)
 			i = 0;
 		}
 
+		is_default_kernelname = 0;
 		if (*kernel == '\0') {
 			if (kernelnames[i] == NULL) {
 				boothowto |= RB_ASKNAME;
 				continue;
 			}
 			strncpy(kernel, kernelnames[i++], PROM_MAX_PATH);
+			is_default_kernelname = 
+				!kernelname_replaced_by_bootfile;
 		} else if (i == 0) {
 			/*
 			 * Kernel name was passed via command line -- ask user
Index: ofdev.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/stand/ofwboot/ofdev.c,v
retrieving revision 1.17
diff -u -p -r1.17 ofdev.c
--- ofdev.c	20 Sep 2007 09:23:54 -0000	1.17
+++ ofdev.c	20 Sep 2007 18:53:38 -0000
@@ -369,6 +369,9 @@ search_label(struct of_dev *devp, u_long
 int
 devopen(struct open_file *of, const char *name, char **file)
 {
+	extern char bootfile[];
+	extern int is_default_kernelname;
+	extern int kernelname_replaced_by_bootfile;
 	char *cp;
 	char partition;
 	char fname[256], devname[256];
@@ -537,6 +540,12 @@ open_again:
 		nfsys = 1;
 		if (error = net_open(&ofdev))
 			goto bad;
+		if (bootfile[0] && is_default_kernelname) {
+			*file = bootfile;
+			kernelname_replaced_by_bootfile = 1;
+			DPRINTF(("default kernel name replaced by DHCP"
+				" one: %s\n",bootfile));
+		}
 		return 0;
 	}
 #endif

--wRRV7LY7NUeQGEoC--