*
* @v image bzImage file
* @v bzimg bzImage context
- * @v cmdline Kernel command line
* @ret rc Return status code
*/
static int bzimage_parse_cmdline ( struct image *image,
- struct bzimage_context *bzimg,
- char *cmdline ) {
+ struct bzimage_context *bzimg ) {
+ const char *vga;
+ const char *mem;
char *sep;
- char *vga;
- char *mem;
+ char *end;
/* Look for "vga=" */
- if ( ( vga = strstr ( cmdline, "vga=" ) ) ) {
- vga += 4;
+ if ( ( vga = image_argument ( image, "vga=" ) ) ) {
sep = strchr ( vga, ' ' );
if ( sep )
*sep = '\0';
} else if ( strcmp ( vga, "ask" ) == 0 ) {
bzimg->vid_mode = BZI_VID_MODE_ASK;
} else {
- bzimg->vid_mode = strtoul ( vga, &vga, 0 );
- if ( *vga ) {
+ bzimg->vid_mode = strtoul ( vga, &end, 0 );
+ if ( *end ) {
DBGC ( image, "bzImage %p strange \"vga=\" "
- "terminator '%c'\n", image, *vga );
+ "terminator '%c'\n", image, *end );
}
}
if ( sep )
}
/* Look for "mem=" */
- if ( ( mem = strstr ( cmdline, "mem=" ) ) ) {
- mem += 4;
- bzimg->mem_limit = strtoul ( mem, &mem, 0 );
- switch ( *mem ) {
+ if ( ( mem = image_argument ( image, "mem=" ) ) ) {
+ bzimg->mem_limit = strtoul ( mem, &end, 0 );
+ switch ( *end ) {
case 'G':
case 'g':
bzimg->mem_limit <<= 10;
break;
default:
DBGC ( image, "bzImage %p strange \"mem=\" "
- "terminator '%c'\n", image, *mem );
+ "terminator '%c'\n", image, *end );
break;
}
bzimg->mem_limit -= 1;
*
* @v image bzImage image
* @v bzimg bzImage context
- * @v cmdline Kernel command line
*/
static void bzimage_set_cmdline ( struct image *image,
- struct bzimage_context *bzimg,
- const char *cmdline ) {
+ struct bzimage_context *bzimg ) {
+ const char *cmdline = ( image->cmdline ? image->cmdline : "" );
size_t cmdline_len;
/* Copy command line down to real-mode portion */
*/
static int bzimage_exec ( struct image *image ) {
struct bzimage_context bzimg;
- char *cmdline = ( image->cmdline ? image->cmdline : "" );
int rc;
/* Read and parse header from image */
}
/* Parse command line for bootloader parameters */
- if ( ( rc = bzimage_parse_cmdline ( image, &bzimg, cmdline ) ) != 0)
+ if ( ( rc = bzimage_parse_cmdline ( image, &bzimg ) ) != 0)
return rc;
/* Check that initrds can be loaded */
bzimg.rm_filesz, bzimg.pm_sz );
/* Store command line */
- bzimage_set_cmdline ( image, &bzimg, cmdline );
+ bzimage_set_cmdline ( image, &bzimg );
/* Prepare for exiting. Must do this before loading initrds,
* since loading the initrds will corrupt the external heap.
*/
static void cpio_parse_cmdline ( struct image *image,
struct cpio_header *cpio ) {
- const char *cmdline;
- char *arg;
+ const char *arg;
char *end;
unsigned int mode;
- /* Skip image filename */
- cmdline = ( cpio_name ( image ) + cpio_name_len ( image ) );
-
/* Look for "mode=" */
- if ( ( arg = strstr ( cmdline, "mode=" ) ) ) {
- arg += 5;
+ if ( ( arg = image_argument ( image, "mode=" ) ) ) {
mode = strtoul ( arg, &end, 8 /* Octal for file mode */ );
if ( *end && ( *end != ' ' ) ) {
DBGC ( image, "CPIO %p strange \"mode=\" "
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <ctype.h>
#include <errno.h>
#include <assert.h>
#include <libgen.h>
err_alloc_image:
return NULL;
}
+
+/**
+ * Find argument within image command line
+ *
+ * @v image Image
+ * @v key Argument search key (including trailing delimiter)
+ * @ret value Argument value, or NULL if not found
+ */
+const char * image_argument ( struct image *image, const char *key ) {
+ const char *cmdline = image->cmdline;
+ const char *search;
+ const char *match;
+ const char *next;
+
+ /* Find argument */
+ for ( search = cmdline ; search ; search = next ) {
+
+ /* Find next occurrence, if any */
+ match = strstr ( search, key );
+ if ( ! match )
+ break;
+ next = ( match + strlen ( key ) );
+
+ /* Check preceding delimiter, if any */
+ if ( ( match == cmdline ) || isspace ( match[-1] ) )
+ return next;
+ }
+
+ return NULL;
+}