Browse Source

[image] Fail "imgexec"/"boot" if the image to execute is ambiguous

If there is more than one loaded image, refuse to automatically select
the image to execute.  There are at least two possible cases, with
different "correct" answers:

1. User loads image A by mistake, then loads image B and types "boot".
   User wants to execute image B.

2. User loads image A, then loads image B (which patches image A), then
   types "boot".  User wants to execute image A.

If a user actually wants to load multiple images, they must explicitly
specify which image is to be executed.
tags/v0.9.4
Michael Brown 16 years ago
parent
commit
0436e417bc
2 changed files with 10 additions and 6 deletions
  1. 1
    1
      src/hci/commands/image_cmd.c
  2. 9
    5
      src/usr/imgmgmt.c

+ 1
- 1
src/hci/commands/image_cmd.c View File

@@ -407,7 +407,7 @@ static int imgexec_exec ( int argc, char **argv ) {
407 407
 	} else {
408 408
 		image = imgautoselect();
409 409
 		if ( ! image ) {
410
-			printf ( "No loaded images\n" );
410
+			printf ( "No (unique) loaded image\n" );
411 411
 			return 1;
412 412
 		}
413 413
 	}

+ 9
- 5
src/usr/imgmgmt.c View File

@@ -86,19 +86,23 @@ int imgexec ( struct image *image ) {
86 86
 }
87 87
 
88 88
 /**
89
- * Identify the first loaded image
89
+ * Identify the only loaded image
90 90
  *
91
- * @ret image		Image, or NULL
91
+ * @ret image		Image, or NULL if 0 or >1 images are loaded
92 92
  */
93 93
 struct image * imgautoselect ( void ) {
94 94
 	struct image *image;
95
+	struct image *selected_image = NULL;
96
+	int flagged_images = 0;
95 97
 
96 98
 	for_each_image ( image ) {
97
-		if ( image->flags & IMAGE_LOADED )
98
-			return image;
99
+		if ( image->flags & IMAGE_LOADED ) {
100
+			selected_image = image;
101
+			flagged_images++;
102
+		}
99 103
 	}
100 104
 
101
-	return NULL;
105
+	return ( ( flagged_images == 1 ) ? selected_image : NULL );
102 106
 }
103 107
 
104 108
 /**

Loading…
Cancel
Save