]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[image] Allow for zero embedded images
authorMichael Brown <mcb30@etherboot.org>
Tue, 24 Feb 2009 05:51:21 +0000 (05:51 +0000)
committerMichael Brown <mcb30@etherboot.org>
Tue, 24 Feb 2009 05:57:56 +0000 (05:57 +0000)
Having a default script containing

  #!gpxe
  autoboot

can cause problems when entering commands to load and start a kernel
manually; the default script image will still be present when the
kernel is started and so will be treated as an initrd.  It is possible
to work around this by typing "imgfree" before any other commands, but
this is counter-intuitive.

Fix by allowing the embedded image list to be empty (in which case we
just call autoboot()), and making this the default.

Reported by alkisg@gmail.com.

src/Makefile.housekeeping
src/core/main.c
src/hci/commands/image_cmd.c
src/image/default.gpxe [deleted file]
src/image/embedded.c
src/include/gpxe/image.h

index 2146d9cbf2e1fdde71a99a7fe1061d4f42f235fb..2ab842e674c788f7fd27adb4c6137f8dcdf0d227 100644 (file)
@@ -286,10 +286,6 @@ CFLAGS             += $(EXTRA_CFLAGS)
 ASFLAGS                += $(EXTRA_ASFLAGS)
 LDFLAGS                += $(EXTRA_LDFLAGS)
 
-# Embedded image(s), or default if not set
-#
-EMBEDDED_IMAGE = image/default.gpxe
-
 # Inhibit -Werror if NO_WERROR is specified on make command line
 #
 ifneq ($(NO_WERROR),1)
index 8d360c4236008dab0105b285d951a4c5eb76eb28..bd2428f05fa508f10eebbe51904f0f1968e94f3c 100644 (file)
@@ -71,13 +71,17 @@ __asmcall int main ( void ) {
                shell();
        } else {
                /* User doesn't want shell; load and execute the first
-                * image.  If booting fails (i.e. if the image
-                * returns, or fails to execute), offer a second
-                * chance to enter the shell for diagnostics.
+                * image, or autoboot() if we have no images.  If
+                * booting fails for any reason, offer a second chance
+                * to enter the shell for diagnostics.
                 */
-               for_each_image ( image ) {
-                       image_exec ( image );
-                       break;
+               if ( have_images() ) {
+                       for_each_image ( image ) {
+                               image_exec ( image );
+                               break;
+                       }
+               } else {
+                       autoboot();
                }
 
                if ( shell_banner() )
index befa5a64b0546b358bfe68cbe95e14edf9b6f59b..6d8b590812ca9a08a4209bdd10ce7482ecd7fa22 100644 (file)
@@ -222,13 +222,13 @@ static int kernel_exec ( int argc, char **argv ) {
 }
 
 /**
- * The "imgauto" command
+ * The "chain" command
  *
  * @v argc             Argument count
  * @v argv             Argument list
  * @ret rc             Exit code
  */
-static int imgauto_exec ( int argc, char **argv) {
+static int chain_exec ( int argc, char **argv) {
        int rc;
 
        if ( ( rc = imgfetch_core_exec ( NULL, IMG_EXEC, argc, argv ) ) != 0 )
@@ -563,8 +563,8 @@ struct command image_commands[] __command = {
                .exec = kernel_exec,
        },
        {
-               .name = "imgauto",
-               .exec = imgauto_exec,
+               .name = "chain",
+               .exec = chain_exec,
        },
        {
                .name = "imgload",
diff --git a/src/image/default.gpxe b/src/image/default.gpxe
deleted file mode 100644 (file)
index 0b080b5..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!gpxe
-autoboot
index f76ca11b6c1c4d49cea54beb4f43b49c7c05b857..4f76357880166c2657a5c01be8d79de99e43ec34 100644 (file)
@@ -16,7 +16,8 @@
  *
  * @v refcnt           Reference counter
  */
-static void embedded_image_free ( struct refcnt *refcnt __unused ) {
+static void __attribute__ (( unused ))
+embedded_image_free ( struct refcnt *refcnt __unused ) {
        /* Do nothing */
 }
 
@@ -51,14 +52,18 @@ static struct image embedded_images[] = {
  * Register all embedded images
  */
 static void embedded_init ( void ) {
-       unsigned int i;
+       int i;
        struct image *image;
        void *data;
        int rc;
 
+       /* Skip if we have no embedded images */
+       if ( ! sizeof ( embedded_images ) )
+               return;
+
        /* Fix up data pointers and register images */
-       for ( i = 0 ; i < ( sizeof ( embedded_images ) /
-                           sizeof ( embedded_images[0] ) ) ; i++ ) {
+       for ( i = 0 ; i < ( int ) ( sizeof ( embedded_images ) /
+                                   sizeof ( embedded_images[0] ) ) ; i++ ) {
                image = &embedded_images[i];
 
                /* virt_to_user() cannot be used in a static
index f8b1482ee6f26991d7a9f16610fdb9820c771c59..b953e15092032e241c1c8677b5218bc13ab02008 100644 (file)
@@ -133,6 +133,15 @@ extern struct list_head images;
 #define for_each_image( image ) \
        list_for_each_entry ( (image), &images, list )
 
+/**
+ * Test for existence of images
+ *
+ * @ret existence      Some images exist
+ */
+static inline int have_images ( void ) {
+       return ( ! list_empty ( &images ) );
+}
+
 extern struct image * alloc_image ( void );
 extern int image_set_uri ( struct image *image, struct uri *uri );
 extern int image_set_cmdline ( struct image *image, const char *cmdline );