Skip to content

Commit 89c75c3

Browse files
committed
WIP - refactored
1 parent 57f3fce commit 89c75c3

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

src/hci/commands/shim_cmd.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,26 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
3838

3939
/** "shim" options */
4040
struct shim_options {
41-
/** Always download shim */
42-
int always;
4341
/** Download timeout */
4442
unsigned long timeout;
4543
/** Crutch image name or URI */
4644
char *crutch;
45+
/** Require third party loader */
46+
int require_loader;
47+
/** Allow PXE base code protocol */
48+
int allow_pxe;
4749
};
4850

4951
/** "shim" option list */
5052
static struct option_descriptor shim_opts[] = {
51-
OPTION_DESC ( "always", 'a', no_argument,
52-
struct shim_options, always, parse_flag ),
5353
OPTION_DESC ( "timeout", 't', required_argument,
5454
struct shim_options, timeout, parse_timeout ),
5555
OPTION_DESC ( "crutch", 'c', required_argument,
5656
struct shim_options, crutch, parse_string ),
57+
OPTION_DESC ( "require-loader", 'l', no_argument,
58+
struct shim_options, require_loader, parse_flag ),
59+
OPTION_DESC ( "allow-pxe", 'p', no_argument,
60+
struct shim_options, allow_pxe, parse_flag ),
5761
};
5862

5963
/** "shim" command descriptor */
@@ -82,7 +86,7 @@ static int shim_exec ( int argc, char **argv ) {
8286

8387
/* Decide whether or not to download images */
8488
kernel = find_image_tag ( &selected_image );
85-
download = ( ( kernel && efi_can_load ( kernel ) ) ? opts.always : 1 );
89+
download = ( ! ( kernel && efi_can_load ( kernel ) ) );
8690

8791
/* Parse name/URI string */
8892
name_uri = argv[optind];
@@ -102,7 +106,8 @@ static int shim_exec ( int argc, char **argv ) {
102106
}
103107

104108
/* (Un)register as shim */
105-
if ( ( rc = shim ( image, crutch ) ) != 0 )
109+
if ( ( rc = shim ( image, crutch, opts.require_loader,
110+
opts.allow_pxe ) ) != 0 )
106111
goto err_shim;
107112

108113
err_shim:

src/image/efi_image.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ static int efi_image_exec ( struct image *image ) {
209209
}
210210

211211
/* Install shim special handling if applicable */
212-
if ( shim && ( ( rc = efi_shim_install ( snpdev->handle ) ) != 0 ) ) {
212+
if ( shim &&
213+
( ( rc = efi_shim_install ( shim, snpdev->handle,
214+
&cmdline ) ) != 0 ) ){
213215
DBGC ( image, "EFIIMAGE %s could not install shim handling: "
214216
"%s\n", image->name, strerror ( rc ) );
215217
goto err_shim_install;

src/include/ipxe/efi/efi_shim.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extern int efi_shim_allow_pxe;
1717
extern struct image_tag efi_shim __image_tag;
1818
extern struct image_tag efi_shim_crutch __image_tag;
1919

20-
extern int efi_shim_install ( EFI_HANDLE handle );
20+
extern int efi_shim_install ( struct image *shim, EFI_HANDLE handle,
21+
wchar_t **cmdline );
2122
extern void efi_shim_uninstall ( void );
2223

2324
#endif /* _IPXE_EFI_SHIM_H */

src/interface/efi/efi_shim.c

+44-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
2525

2626
#include <string.h>
27+
#include <stdlib.h>
2728
#include <errno.h>
2829
#include <ipxe/image.h>
2930
#include <ipxe/efi/efi.h>
31+
#include <ipxe/efi/efi_strings.h>
3032
#include <ipxe/efi/efi_shim.h>
3133
#include <ipxe/efi/Protocol/PxeBaseCode.h>
3234
#include <ipxe/efi/Protocol/ShimLock.h>
@@ -174,13 +176,48 @@ static int efi_shim_inhibit_pxe ( EFI_HANDLE handle ) {
174176
return rc;
175177
}
176178

179+
/**
180+
* Update command line
181+
*
182+
* @v shim Shim image
183+
* @v cmdline Command line to update
184+
* @ret rc Return status code
185+
*/
186+
static int efi_shim_cmdline ( struct image *shim, wchar_t **cmdline ) {
187+
wchar_t *shimcmdline;
188+
int len;
189+
int rc;
190+
191+
/* Construct new command line */
192+
len = ( shim->cmdline ?
193+
efi_asprintf ( &shimcmdline, "%s %s", shim->name,
194+
shim->cmdline ) :
195+
efi_asprintf ( &shimcmdline, "%s %ls", shim->name,
196+
*cmdline ) );
197+
if ( len < 0 ) {
198+
rc = len;
199+
DBGC ( &efi_shim, "SHIM could not construct command line: "
200+
"%s\n", strerror ( rc ) );
201+
return rc;
202+
}
203+
204+
/* Replace command line */
205+
free ( *cmdline );
206+
*cmdline = shimcmdline;
207+
208+
return 0;
209+
}
210+
177211
/**
178212
* Install UEFI shim special handling
179213
*
180-
* @v handle EFI handle
214+
* @v shim Shim image
215+
* @v handle EFI device handle
216+
* @v cmdline Command line to update
181217
* @ret rc Return status code
182218
*/
183-
int efi_shim_install ( EFI_HANDLE handle ) {
219+
int efi_shim_install ( struct image *shim, EFI_HANDLE handle,
220+
wchar_t **cmdline ) {
184221
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
185222
int rc;
186223

@@ -195,8 +232,13 @@ int efi_shim_install ( EFI_HANDLE handle ) {
195232
goto err_inhibit_pxe;
196233
}
197234

235+
/* Update command line */
236+
if ( ( rc = efi_shim_cmdline ( shim, cmdline ) ) != 0 )
237+
goto err_cmdline;
238+
198239
return 0;
199240

241+
err_cmdline:
200242
err_inhibit_pxe:
201243
bs->GetMemoryMap = efi_shim_orig_map;
202244
return rc;

0 commit comments

Comments
 (0)