Browse Source

[multiboot] Include full image URI in command line

Solaris kernels seem to rely on having the full kernel path present in
the multiboot command line; if only the kernel name is present then
the boot fails with the error message

  krtld: failed to open 'unix'

Debugged-by: Michael Brown <mcb30@ipxe.org>
Debugged-by: Scott McWhirter <scottm@joyent.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
d11b82f0e4
1 changed files with 30 additions and 21 deletions
  1. 30
    21
      src/arch/i386/image/multiboot.c

+ 30
- 21
src/arch/i386/image/multiboot.c View File

37
 #include <ipxe/elf.h>
37
 #include <ipxe/elf.h>
38
 #include <ipxe/init.h>
38
 #include <ipxe/init.h>
39
 #include <ipxe/features.h>
39
 #include <ipxe/features.h>
40
+#include <ipxe/uri.h>
40
 
41
 
41
 FEATURE ( FEATURE_IMAGE, "MBOOT", DHCP_EB_FEATURE_MULTIBOOT, 1 );
42
 FEATURE ( FEATURE_IMAGE, "MBOOT", DHCP_EB_FEATURE_MULTIBOOT, 1 );
42
 
43
 
139
 /**
140
 /**
140
  * Add command line in base memory
141
  * Add command line in base memory
141
  *
142
  *
142
- * @v imgname		Image name
143
- * @v cmdline		Command line
143
+ * @v image		Image
144
  * @ret physaddr	Physical address of command line
144
  * @ret physaddr	Physical address of command line
145
  */
145
  */
146
-physaddr_t multiboot_add_cmdline ( const char *imgname, const char *cmdline ) {
147
-	char *mb_cmdline;
148
-
149
-	if ( ! cmdline )
150
-		cmdline = "";
151
-
152
-	/* Copy command line to base memory buffer */
153
-	mb_cmdline = ( mb_cmdlines + mb_cmdline_offset );
154
-	mb_cmdline_offset +=
155
-		( snprintf ( mb_cmdline,
156
-			     ( sizeof ( mb_cmdlines ) - mb_cmdline_offset ),
157
-			     "%s %s", imgname, cmdline ) + 1 );
158
-
159
-	/* Truncate to terminating NUL in buffer if necessary */
160
-	if ( mb_cmdline_offset > sizeof ( mb_cmdlines ) )
161
-		mb_cmdline_offset = ( sizeof ( mb_cmdlines ) - 1 );
146
+physaddr_t multiboot_add_cmdline ( struct image *image ) {
147
+	char *mb_cmdline = ( mb_cmdlines + mb_cmdline_offset );
148
+	size_t remaining = ( sizeof ( mb_cmdlines ) - mb_cmdline_offset );
149
+	char *buf = mb_cmdline;
150
+	size_t len;
151
+
152
+	/* Copy image URI to base memory buffer as start of command line */
153
+	len = ( unparse_uri ( buf, remaining, image->uri,
154
+			      URI_ALL ) + 1 /* NUL */ );
155
+	if ( len > remaining )
156
+		len = remaining;
157
+	mb_cmdline_offset += len;
158
+	buf += len;
159
+	remaining -= len;
160
+
161
+	/* Copy command line to base memory buffer, if present */
162
+	if ( image->cmdline ) {
163
+		mb_cmdline_offset--; /* Strip NUL */
164
+		buf--;
165
+		remaining++;
166
+		len = ( snprintf ( buf, remaining, " %s",
167
+				   image->cmdline ) + 1 /* NUL */ );
168
+		if ( len > remaining )
169
+			len = remaining;
170
+		mb_cmdline_offset += len;
171
+	}
162
 
172
 
163
 	return virt_to_phys ( mb_cmdline );
173
 	return virt_to_phys ( mb_cmdline );
164
 }
174
 }
209
 			  ( ( count - insert ) * sizeof ( *module ) ) );
219
 			  ( ( count - insert ) * sizeof ( *module ) ) );
210
 		module->mod_start = start;
220
 		module->mod_start = start;
211
 		module->mod_end = end;
221
 		module->mod_end = end;
212
-		module->string = multiboot_add_cmdline ( module_image->name,
213
-						       module_image->cmdline );
222
+		module->string = multiboot_add_cmdline ( module_image );
214
 		module->reserved = 0;
223
 		module->reserved = 0;
215
 		
224
 		
216
 		/* We promise to page-align modules */
225
 		/* We promise to page-align modules */
405
 	mbinfo.flags = ( MBI_FLAG_LOADER | MBI_FLAG_MEM | MBI_FLAG_MMAP |
414
 	mbinfo.flags = ( MBI_FLAG_LOADER | MBI_FLAG_MEM | MBI_FLAG_MMAP |
406
 			 MBI_FLAG_CMDLINE | MBI_FLAG_MODS );
415
 			 MBI_FLAG_CMDLINE | MBI_FLAG_MODS );
407
 	mb_cmdline_offset = 0;
416
 	mb_cmdline_offset = 0;
408
-	mbinfo.cmdline = multiboot_add_cmdline ( image->name, image->cmdline );
417
+	mbinfo.cmdline = multiboot_add_cmdline ( image );
409
 	mbinfo.mods_count = multiboot_build_module_list ( image, mbmodules,
418
 	mbinfo.mods_count = multiboot_build_module_list ( image, mbmodules,
410
 				( sizeof(mbmodules) / sizeof(mbmodules[0]) ) );
419
 				( sizeof(mbmodules) / sizeof(mbmodules[0]) ) );
411
 	mbinfo.mods_addr = virt_to_phys ( mbmodules );
420
 	mbinfo.mods_addr = virt_to_phys ( mbmodules );

Loading…
Cancel
Save