[efi] Implement "shim" as a dummy command on non-EFI platforms

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>
pull/963/head
Michael Brown 2023-05-24 10:20:31 +01:00
parent 5b43181436
commit 6a7f560e60
3 changed files with 15 additions and 2 deletions

View File

@ -47,7 +47,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define USB_BLOCK /* USB block devices */ #define USB_BLOCK /* USB block devices */
#define REBOOT_CMD /* Reboot command */ #define REBOOT_CMD /* Reboot command */
#define SHIM_CMD /* EFI shim command */
#if defined ( __i386__ ) || defined ( __x86_64__ ) #if defined ( __i386__ ) || defined ( __x86_64__ )
#define IOAPI_X86 #define IOAPI_X86

View File

@ -160,7 +160,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
//#define CERT_CMD /* Certificate management commands */ //#define CERT_CMD /* Certificate management commands */
//#define IMAGE_MEM_CMD /* Read memory command */ //#define IMAGE_MEM_CMD /* Read memory command */
#define IMAGE_ARCHIVE_CMD /* Archive image management commands */ #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 * ROM-specific options

View 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 */ /** "shim" options */
struct shim_options { struct shim_options {
/** Download timeout */ /** Download timeout */
@ -79,6 +86,12 @@ static int shim_exec ( int argc, char **argv ) {
int download; int download;
int rc; int rc;
/* Do absolutely nothing if this is a non-EFI platform */
if ( shim_dummy ) {
rc = 0;
goto err_dummy;
}
/* Parse options */ /* Parse options */
if ( ( rc = parse_options ( argc, argv, &shim_cmd, &opts ) ) != 0 ) if ( ( rc = parse_options ( argc, argv, &shim_cmd, &opts ) ) != 0 )
goto err_parse; goto err_parse;
@ -105,6 +118,7 @@ static int shim_exec ( int argc, char **argv ) {
err_shim: err_shim:
err_image: err_image:
err_parse: err_parse:
err_dummy:
return rc; return rc;
} }