]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Implement "shim" as a dummy command on non-EFI platforms
authorMichael Brown <mcb30@ipxe.org>
Wed, 24 May 2023 09:20:31 +0000 (10:20 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 24 May 2023 09:20:31 +0000 (10:20 +0100)
The "shim" command will skip downloading the shim binary (and is
therefore a conditional no-op) if there is already a selected EFI
image that can be executed directly via LoadImage()/StartImage().
This allows the same iPXE script to be used with Secure Boot either
enabled or disabled.

Generalise this further to provide a dummy "shim" command that is an
unconditional no-op on non-EFI platforms.  This then allows the same
iPXE script to be used for BIOS, EFI with Secure Boot disabled, or EFI
with Secure Boot enabled.

The same effect could be achieved by using "iseq ${platform} efi"
within the script, but this would complicate end-user documentation.

To minimise the code size impact, the dummy "shim" command is a pure
no-op that does not call parse_options() and so will ignore even
standardised arguments such as "--help".

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/config/defaults/efi.h
src/config/general.h
src/hci/commands/shim_cmd.c

index 998bdcc1605440eed66af2d5d2ea854f408798be..8e53b9ab6a435cf958906007ca00e9d328aec700 100644 (file)
@@ -47,7 +47,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #define USB_BLOCK              /* USB block devices */
 
 #define        REBOOT_CMD              /* Reboot command */
-#define SHIM_CMD               /* EFI shim command */
 
 #if defined ( __i386__ ) || defined ( __x86_64__ )
 #define IOAPI_X86
index 2a371d0e6ad37e1691d18191a277702b919672c8..6e8e86b2b47ef462074b5d2b065a8c0cfe8f728b 100644 (file)
@@ -160,7 +160,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 //#define CERT_CMD             /* Certificate management commands */
 //#define IMAGE_MEM_CMD                /* Read memory command */
 #define IMAGE_ARCHIVE_CMD      /* Archive image management commands */
-//#define SHIM_CMD             /* EFI shim command */
+#define SHIM_CMD               /* EFI shim command (or dummy command) */
 
 /*
  * ROM-specific options
index 9150af3fd195d9a6f8bcd8ea34b6dfc59cfba76e..11956290a00972fee978aecf63647b6caca59af6 100644 (file)
@@ -36,6 +36,13 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  *
  */
 
+/* Exist as a dummy command on non-EFI platforms */
+#ifdef PLATFORM_efi
+#define shim_dummy 0
+#else
+#define shim_dummy 1
+#endif
+
 /** "shim" options */
 struct shim_options {
        /** Download timeout */
@@ -79,6 +86,12 @@ static int shim_exec ( int argc, char **argv ) {
        int download;
        int rc;
 
+       /* Do absolutely nothing if this is a non-EFI platform */
+       if ( shim_dummy ) {
+               rc = 0;
+               goto err_dummy;
+       }
+
        /* Parse options */
        if ( ( rc = parse_options ( argc, argv, &shim_cmd, &opts ) ) != 0 )
                goto err_parse;
@@ -105,6 +118,7 @@ static int shim_exec ( int argc, char **argv ) {
  err_shim:
  err_image:
  err_parse:
+ err_dummy:
        return rc;
 }