diff --git a/src/hci/commands/image_cmd.c b/src/hci/commands/image_cmd.c index 05e7ddee..d1a38c47 100644 --- a/src/hci/commands/image_cmd.c +++ b/src/hci/commands/image_cmd.c @@ -407,7 +407,7 @@ static int imgexec_exec ( int argc, char **argv ) { } else { image = imgautoselect(); if ( ! image ) { - printf ( "No loaded images\n" ); + printf ( "No (unique) loaded image\n" ); return 1; } } diff --git a/src/usr/imgmgmt.c b/src/usr/imgmgmt.c index bead4867..be153f87 100644 --- a/src/usr/imgmgmt.c +++ b/src/usr/imgmgmt.c @@ -86,19 +86,23 @@ int imgexec ( struct image *image ) { } /** - * Identify the first loaded image + * Identify the only loaded image * - * @ret image Image, or NULL + * @ret image Image, or NULL if 0 or >1 images are loaded */ struct image * imgautoselect ( void ) { struct image *image; + struct image *selected_image = NULL; + int flagged_images = 0; for_each_image ( image ) { - if ( image->flags & IMAGE_LOADED ) - return image; + if ( image->flags & IMAGE_LOADED ) { + selected_image = image; + flagged_images++; + } } - return NULL; + return ( ( flagged_images == 1 ) ? selected_image : NULL ); } /**