浏览代码

[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 17 年前
父节点
当前提交
0436e417bc
共有 2 个文件被更改,包括 10 次插入6 次删除
  1. 1
    1
      src/hci/commands/image_cmd.c
  2. 9
    5
      src/usr/imgmgmt.c

+ 1
- 1
src/hci/commands/image_cmd.c 查看文件

407
 	} else {
407
 	} else {
408
 		image = imgautoselect();
408
 		image = imgautoselect();
409
 		if ( ! image ) {
409
 		if ( ! image ) {
410
-			printf ( "No loaded images\n" );
410
+			printf ( "No (unique) loaded image\n" );
411
 			return 1;
411
 			return 1;
412
 		}
412
 		}
413
 	}
413
 	}

+ 9
- 5
src/usr/imgmgmt.c 查看文件

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
 struct image * imgautoselect ( void ) {
93
 struct image * imgautoselect ( void ) {
94
 	struct image *image;
94
 	struct image *image;
95
+	struct image *selected_image = NULL;
96
+	int flagged_images = 0;
95
 
97
 
96
 	for_each_image ( image ) {
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
 /**

正在加载...
取消
保存