Browse Source

Allow "imgexec" with no arguments to boot the file that was loaded with

"kernel".
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
2876197306
3 changed files with 35 additions and 9 deletions
  1. 18
    9
      src/hci/commands/image_cmd.c
  2. 1
    0
      src/include/usr/imgmgmt.h
  3. 16
    0
      src/usr/imgmgmt.c

+ 18
- 9
src/hci/commands/image_cmd.c View File

304
 		{ NULL, 0, NULL, 0 },
304
 		{ NULL, 0, NULL, 0 },
305
 	};
305
 	};
306
 	struct image *image;
306
 	struct image *image;
307
-	const char *name;
307
+	const char *name = NULL;
308
 	int c;
308
 	int c;
309
 	int rc;
309
 	int rc;
310
 
310
 
320
 		}
320
 		}
321
 	}
321
 	}
322
 
322
 
323
-	/* Need exactly one image name */
324
-	if ( optind != ( argc - 1 ) ) {
323
+	/* Need no more than one image name */
324
+	if ( optind != argc )
325
+		name = argv[optind++];
326
+	if ( optind != argc ) {
325
 		imgexec_syntax ( argv );
327
 		imgexec_syntax ( argv );
326
 		return 1;
328
 		return 1;
327
 	}
329
 	}
328
-	name = argv[optind];
329
 	
330
 	
330
 	/* Execute specified image */
331
 	/* Execute specified image */
331
-	image = find_image ( name );
332
-	if ( ! image ) {
333
-		printf ( "No such image: %s\n", name );
334
-		return 1;
332
+	if ( name ) {
333
+		image = find_image ( name );
334
+		if ( ! image ) {
335
+			printf ( "No such image: %s\n", name );
336
+			return 1;
337
+		}
338
+	} else {
339
+		image = imgautoselect();
340
+		if ( ! image ) {
341
+			printf ( "No loaded images\n" );
342
+			return 1;
343
+		}
335
 	}
344
 	}
345
+
336
 	if ( ( rc = imgexec ( image ) ) != 0 ) {
346
 	if ( ( rc = imgexec ( image ) ) != 0 ) {
337
 		printf ( "Could not execute %s: %s\n", name, strerror ( rc ) );
347
 		printf ( "Could not execute %s: %s\n", name, strerror ( rc ) );
338
 		return 1;
348
 		return 1;
448
 	return 0;
458
 	return 0;
449
 }
459
 }
450
 
460
 
451
-
452
 /** Image management commands */
461
 /** Image management commands */
453
 struct command image_commands[] __command = {
462
 struct command image_commands[] __command = {
454
 	{
463
 	{

+ 1
- 0
src/include/usr/imgmgmt.h View File

11
 		      struct image **new_image );
11
 		      struct image **new_image );
12
 extern int imgload ( struct image *image );
12
 extern int imgload ( struct image *image );
13
 extern int imgexec ( struct image *image );
13
 extern int imgexec ( struct image *image );
14
+extern struct image * imgautoselect ( void );
14
 extern void imgstat ( struct image *image );
15
 extern void imgstat ( struct image *image );
15
 extern void imgfree ( struct image *image );
16
 extern void imgfree ( struct image *image );
16
 
17
 

+ 16
- 0
src/usr/imgmgmt.c View File

90
 	return image_exec ( image );
90
 	return image_exec ( image );
91
 }
91
 }
92
 
92
 
93
+/**
94
+ * Identify the first loaded image
95
+ *
96
+ * @ret image		Image, or NULL
97
+ */
98
+struct image * imgautoselect ( void ) {
99
+	struct image *image;
100
+
101
+	for_each_image ( image ) {
102
+		if ( image->flags & IMAGE_LOADED )
103
+			return image;
104
+	}
105
+
106
+	return NULL;
107
+}
108
+
93
 /**
109
 /**
94
  * Display status of an image
110
  * Display status of an image
95
  *
111
  *

Loading…
Cancel
Save