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,7 +304,7 @@ static int imgexec_exec ( int argc, char **argv ) {
304 304
 		{ NULL, 0, NULL, 0 },
305 305
 	};
306 306
 	struct image *image;
307
-	const char *name;
307
+	const char *name = NULL;
308 308
 	int c;
309 309
 	int rc;
310 310
 
@@ -320,19 +320,29 @@ static int imgexec_exec ( int argc, char **argv ) {
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 327
 		imgexec_syntax ( argv );
326 328
 		return 1;
327 329
 	}
328
-	name = argv[optind];
329 330
 	
330 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 346
 	if ( ( rc = imgexec ( image ) ) != 0 ) {
337 347
 		printf ( "Could not execute %s: %s\n", name, strerror ( rc ) );
338 348
 		return 1;
@@ -448,7 +458,6 @@ static int imgfree_exec ( int argc, char **argv ) {
448 458
 	return 0;
449 459
 }
450 460
 
451
-
452 461
 /** Image management commands */
453 462
 struct command image_commands[] __command = {
454 463
 	{

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

@@ -11,6 +11,7 @@ extern int imgfetch ( const char *filename, const char *name,
11 11
 		      struct image **new_image );
12 12
 extern int imgload ( struct image *image );
13 13
 extern int imgexec ( struct image *image );
14
+extern struct image * imgautoselect ( void );
14 15
 extern void imgstat ( struct image *image );
15 16
 extern void imgfree ( struct image *image );
16 17
 

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

@@ -90,6 +90,22 @@ int imgexec ( struct image *image ) {
90 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 110
  * Display status of an image
95 111
  *

Loading…
Cancel
Save