|
@@ -37,6 +37,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
37
|
37
|
#include <ipxe/elf.h>
|
38
|
38
|
#include <ipxe/init.h>
|
39
|
39
|
#include <ipxe/features.h>
|
|
40
|
+#include <ipxe/uri.h>
|
40
|
41
|
|
41
|
42
|
FEATURE ( FEATURE_IMAGE, "MBOOT", DHCP_EB_FEATURE_MULTIBOOT, 1 );
|
42
|
43
|
|
|
@@ -139,26 +140,35 @@ static void multiboot_build_memmap ( struct image *image,
|
139
|
140
|
/**
|
140
|
141
|
* Add command line in base memory
|
141
|
142
|
*
|
142
|
|
- * @v imgname Image name
|
143
|
|
- * @v cmdline Command line
|
|
143
|
+ * @v image Image
|
144
|
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
|
173
|
return virt_to_phys ( mb_cmdline );
|
164
|
174
|
}
|
|
@@ -209,8 +219,7 @@ multiboot_build_module_list ( struct image *image,
|
209
|
219
|
( ( count - insert ) * sizeof ( *module ) ) );
|
210
|
220
|
module->mod_start = start;
|
211
|
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
|
223
|
module->reserved = 0;
|
215
|
224
|
|
216
|
225
|
/* We promise to page-align modules */
|
|
@@ -405,7 +414,7 @@ static int multiboot_exec ( struct image *image ) {
|
405
|
414
|
mbinfo.flags = ( MBI_FLAG_LOADER | MBI_FLAG_MEM | MBI_FLAG_MMAP |
|
406
|
415
|
MBI_FLAG_CMDLINE | MBI_FLAG_MODS );
|
407
|
416
|
mb_cmdline_offset = 0;
|
408
|
|
- mbinfo.cmdline = multiboot_add_cmdline ( image->name, image->cmdline );
|
|
417
|
+ mbinfo.cmdline = multiboot_add_cmdline ( image );
|
409
|
418
|
mbinfo.mods_count = multiboot_build_module_list ( image, mbmodules,
|
410
|
419
|
( sizeof(mbmodules) / sizeof(mbmodules[0]) ) );
|
411
|
420
|
mbinfo.mods_addr = virt_to_phys ( mbmodules );
|