diff options
| author | Michael Brown | 2007-01-12 08:32:46 +0100 |
|---|---|---|
| committer | Michael Brown | 2007-01-12 08:32:46 +0100 |
| commit | 2876197306df09f003024784feb197d7ef14b0f8 (patch) | |
| tree | c2e1aad526a44e59d6cf35be6535c23b07ebb74e | |
| parent | Cleaner separation between imgXXX() functions and image_cmd.c (diff) | |
| download | ipxe-2876197306df09f003024784feb197d7ef14b0f8.tar.gz ipxe-2876197306df09f003024784feb197d7ef14b0f8.tar.xz ipxe-2876197306df09f003024784feb197d7ef14b0f8.zip | |
Allow "imgexec" with no arguments to boot the file that was loaded with
"kernel".
| -rw-r--r-- | src/hci/commands/image_cmd.c | 27 | ||||
| -rw-r--r-- | src/include/usr/imgmgmt.h | 1 | ||||
| -rw-r--r-- | src/usr/imgmgmt.c | 16 |
3 files changed, 35 insertions, 9 deletions
diff --git a/src/hci/commands/image_cmd.c b/src/hci/commands/image_cmd.c index 0dc165577..8055f686f 100644 --- a/src/hci/commands/image_cmd.c +++ b/src/hci/commands/image_cmd.c @@ -304,7 +304,7 @@ static int imgexec_exec ( int argc, char **argv ) { { NULL, 0, NULL, 0 }, }; struct image *image; - const char *name; + const char *name = NULL; int c; int rc; @@ -320,19 +320,29 @@ static int imgexec_exec ( int argc, char **argv ) { } } - /* Need exactly one image name */ - if ( optind != ( argc - 1 ) ) { + /* Need no more than one image name */ + if ( optind != argc ) + name = argv[optind++]; + if ( optind != argc ) { imgexec_syntax ( argv ); return 1; } - name = argv[optind]; /* Execute specified image */ - image = find_image ( name ); - if ( ! image ) { - printf ( "No such image: %s\n", name ); - return 1; + if ( name ) { + image = find_image ( name ); + if ( ! image ) { + printf ( "No such image: %s\n", name ); + return 1; + } + } else { + image = imgautoselect(); + if ( ! image ) { + printf ( "No loaded images\n" ); + return 1; + } } + if ( ( rc = imgexec ( image ) ) != 0 ) { printf ( "Could not execute %s: %s\n", name, strerror ( rc ) ); return 1; @@ -448,7 +458,6 @@ static int imgfree_exec ( int argc, char **argv ) { return 0; } - /** Image management commands */ struct command image_commands[] __command = { { diff --git a/src/include/usr/imgmgmt.h b/src/include/usr/imgmgmt.h index 86a65da50..f0484106b 100644 --- a/src/include/usr/imgmgmt.h +++ b/src/include/usr/imgmgmt.h @@ -11,6 +11,7 @@ extern int imgfetch ( const char *filename, const char *name, struct image **new_image ); extern int imgload ( struct image *image ); extern int imgexec ( struct image *image ); +extern struct image * imgautoselect ( void ); extern void imgstat ( struct image *image ); extern void imgfree ( struct image *image ); diff --git a/src/usr/imgmgmt.c b/src/usr/imgmgmt.c index de71dee1b..2c949ae24 100644 --- a/src/usr/imgmgmt.c +++ b/src/usr/imgmgmt.c @@ -91,6 +91,22 @@ int imgexec ( struct image *image ) { } /** + * Identify the first loaded image + * + * @ret image Image, or NULL + */ +struct image * imgautoselect ( void ) { + struct image *image; + + for_each_image ( image ) { + if ( image->flags & IMAGE_LOADED ) + return image; + } + + return NULL; +} + +/** * Display status of an image * * @v image Executable/loadable image |
