efi: Unified Xen hypervisor/kernel/initrd images
v8 cover efi: Unified Xen hypervisor/kernel/initrd images
This patch series adds support for bundling the xen.efi hypervisor, the xen.cfg configuration file, the Linux kernel and initrd, as well as the XSM, and architectural specific files into a single "unified" EFI executable. This allows an administrator to update the components independently without requiring rebuilding xen, as well as to replace the components in an existing image.
The resulting EFI executable can be invoked directly from the UEFI Boot Manager, removing the need to use a separate loader like grub as well as removing dependencies on local filesystem access. And since it is a single file, it can be signed and validated by UEFI Secure Boot without requring the shim protocol.
It is inspired by systemd-boot's unified kernel technique and borrows the function to locate PE sections from systemd's LGPL'ed code. During EFI boot, Xen looks at its own loaded image to locate the PE sections for the Xen configuration (.config), dom0 kernel (.kernel), dom0 initrd (.ramdisk), and XSM config (.xsm), which are included after building xen.efi using objcopy to add named sections for each input file.
Trammell Hudson (5):
efi/boot.c: add file.need_to_free
efi/boot.c: add handle_file_info()
efi/boot.c: wrap PrintStr/PrintErr to allow const CHAR16* arguments
efi: Enable booting unified hypervisor/kernel/initrd images
efi: Do not use command line if unified config is included
.gitignore | 1 + docs/misc/efi.pandoc | 49 +++++++++++ xen/arch/arm/efi/efi-boot.h | 36 +++++--- xen/arch/x86/efi/Makefile | 2 +- xen/arch/x86/efi/efi-boot.h | 13 ++- xen/common/efi/boot.c | 161 ++++++++++++++++++++++++++---------- xen/common/efi/efi.h | 3 + xen/common/efi/pe.c | 153 ++++++++++++++++++++++++++++++++++ 8 files changed, 362 insertions(+), 56 deletions(-) create mode 100644 xen/common/efi/pe.c
Signature · 1 line
2.25.1
PATCH v8 1/5 efi/boot.c: add file.need_to_free
The config file, kernel, initrd, etc should only be freed if they are allocated with the UEFI allocator. On x86 the ucode, and on ARM the dtb, are also marked as need_to_free when allocated or expanded.
This also fixes a memory leak in ARM fdt_increase_size() if there is an error in building the new device tree.
--- xen/arch/arm/efi/efi-boot.h | 11 +++++++++-- xen/arch/x86/efi/efi-boot.h | 2 +- xen/common/efi/boot.c | 10 ++++++---- 3 files changed, 16 insertions(+), 7 deletions(-)
xen/arch/arm/efi/efi-boot.h +9 -2
@@ -314,7 +314,10 @@ static void __init *fdt_increase_size(struct file *fdtfile, int add_size)if ( fdt_size ) {if (fdt_open_into (dtbfile.ptr, new_fdt, pages *EFI_PAGE_SIZE ) ) + { + efi_bs->FreePages (fdt_addr, pages);return NULL ; + } }else {
@@ -326,7 +329,10 @@ static void __init *fdt_increase_size(struct file *fdtfile, int add_size)* system table that is passed in the FDT. */ if (fdt_create_empty_tree (new_fdt, pages *EFI_PAGE_SIZE ) ) + { + efi_bs->FreePages (fdt_addr, pages);return NULL ; + } }/*
@@ -335,12 +341,13 @@ static void __init *fdt_increase_size(struct file *fdtfile, int add_size)* code will free it. If the original FDT came from a configuration * table, we don't own that memory and can't free it. */ -if ( dtbfile.size ) +if ( dtbfile.need_to_free ) efi_bs->FreePages (dtbfile.addr,PFN_UP (dtbfile.size));/* Update 'file' info for new memory so we clean it up on error exits */ dtbfile.addr = fdt_addr; dtbfile.size = pages *EFI_PAGE_SIZE ; + dtbfile.need_to_free = true;return new_fdt; }
@@ -546,7 +553,7 @@ static void __init efi_arch_cpu(void)static void __init efi_arch_blexit (void ) { -if ( dtbfile.addr && dtbfile.size ) +if ( dtbfile.need_to_free ) efi_bs->FreePages (dtbfile.addr,PFN_UP (dtbfile.size));if ( memmap ) efi_bs->FreePool (memmap);
xen/arch/x86/efi/efi-boot.h +1 -1
@@ -689,7 +689,7 @@ static void __init efi_arch_cpu(void)static void __init efi_arch_blexit (void ) { -if ( ucode.addr ) +if ( ucode.need_to_free ) efi_bs->FreePages (ucode.addr,PFN_UP (ucode.size)); }
xen/common/efi/boot.c +6 -4
@@ -102,6 +102,7 @@ union string {struct file {UINTN size; +bool need_to_free;union {EFI_PHYSICAL_ADDRESS addr;char *str;
@@ -280,13 +281,13 @@ void __init noreturn blexit(const CHAR16 *str)if ( !efi_bs )efi_arch_halt (); -if ( cfg.addr ) +if ( cfg.need_to_free ) efi_bs->FreePages (cfg.addr,PFN_UP (cfg.size)); -if ( kernel.addr ) +if ( kernel.need_to_free ) efi_bs->FreePages (kernel.addr,PFN_UP (kernel.size)); -if ( ramdisk.addr ) +if ( ramdisk.need_to_free ) efi_bs->FreePages (ramdisk.addr,PFN_UP (ramdisk.size)); -if ( xsm.addr ) +if ( xsm.need_to_free ) efi_bs->FreePages (xsm.addr,PFN_UP (xsm.size));efi_arch_blexit ();
@@ -581,6 +582,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, }else { + file->need_to_free = true; file->size = size;if ( file != &cfg ) {
Signature · 1 line
2.25.1
Re: [PATCH v8 1/5] efi/boot.c: add file.need_to_free
Quoted 9 lines · Trammell Hudson
The config file, kernel, initrd, etc should only be freed if they are allocated with the UEFI allocator. On x86 the ucode, and on ARM the dtb, are also marked as
need_to_freewhen allocated or expanded.This also fixes a memory leak in ARM
fdt_increase_size()if there is an error in building the new device tree.Signed-off-by Trammell Hudson <[email protected]>
PATCH v8 2/5 efi/boot.c: add handle_file_info()
In reply to Trammell HudsonAdd a separate function to display the address ranges used by the files and call efi_arch_handle_module() on the modules.
--- xen/common/efi/boot.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
xen/common/efi/boot.c +17 -10
@@ -540,6 +540,22 @@ static char * __init split_string(char *s)return NULL ; } +static void __init handle_file_info (CHAR16 *name, +const struct file *file,const char *options) +{ +if ( file == &cfg ) +return ; + +PrintStr (name); +PrintStr (L": " ); +DisplayUint (file->addr,2 *sizeof (file->addr)); +PrintStr (L"-" ); +DisplayUint (file->addr + file->size,2 *sizeof (file->addr)); +PrintStr (newline); + +efi_arch_handle_module (file, name, options); +} +static bool __init read_file (EFI_FILE_HANDLE dir_handle,CHAR16 *name,struct file *file,const char *options) {
@@ -584,16 +600,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, { file->need_to_free = true; file->size = size; -if ( file != &cfg ) - { -PrintStr (name); -PrintStr (L": " ); -DisplayUint (file->addr,2 *sizeof (file->addr)); -PrintStr (L"-" ); -DisplayUint (file->addr + size,2 *sizeof (file->addr)); -PrintStr (newline); -efi_arch_handle_module (file, name, options); - } +handle_file_info (name, file, options); ret = FileHandle->Read (FileHandle, &file->size, file->str);if ( !EFI_ERROR (ret) && file->size != size )
Signature · 1 line
2.25.1
PATCH v8 3/5 efi/boot.c: wrap PrintStr/PrintErr to allow const CHAR16* arguments
In reply to Trammell HudsonThis patch wraps the EFI OutputString() method so that they can be called with const arguments. The OutputString method does not modify its argument, although the prototype is missing const, so it is necssary to cast away the const when calling it.
It also updates callers of PrintStr/PrintErr to remove unneeded un-const casts.
--- xen/common/efi/boot.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
xen/common/efi/boot.c +14 -7
@@ -151,10 +151,17 @@ static struct file __initdata cfg;static struct file __initdata kernel;static struct file __initdata ramdisk;static struct file __initdata xsm; -static CHAR16 __initdata newline[] =L"\r\n" ; +static const CHAR16 __initconst newline[] =L"\r\n" ; -#define PrintStr (s) StdOut->OutputString(StdOut, s) -#define PrintErr (s) StdErr->OutputString(StdErr, s) +static void __init PrintStr (const CHAR16 *s) +{ + StdOut->OutputString (StdOut, (CHAR16 *)s ); +} + +static void __init PrintErr (const CHAR16 *s) +{ + StdErr->OutputString (StdErr, (CHAR16 *)s ); +}/* * Include architecture specific implementation here, which references the
@@ -275,7 +282,7 @@ static bool __init match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2)void __init noreturnblexit (const CHAR16 *str) {if ( str ) -PrintStr ((CHAR16 *)str); +PrintStr (str);PrintStr (newline);if ( !efi_bs )
@@ -316,7 +323,7 @@ static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode)EFI_STATUS ErrIdx = ErrCode & ~EFI_ERROR_MASK ; StdOut = StdErr; -PrintErr ((CHAR16 *)mesg); +PrintErr (mesg);PrintErr (L": " );if ( (ErrIdx <ARRAY_SIZE (ErrCodeToStr)) && ErrCodeToStr[ErrIdx] )
@@ -540,7 +547,7 @@ static char * __init split_string(char *s)return NULL ; } -static void __init handle_file_info (CHAR16 *name, +static void __init handle_file_info (const CHAR16 *name,const struct file *file,const char *options) {if ( file == &cfg )
@@ -562,7 +569,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,EFI_FILE_HANDLE FileHandle =NULL ;UINT64 size;EFI_STATUS ret; -CHAR16 *what =NULL ; +const CHAR16 *what =NULL ;if ( !name )PrintErrMesg (L"No filename" ,EFI_OUT_OF_RESOURCES );
Signature · 1 line
2.25.1
Re: [PATCH v8 3/5] efi/boot.c: wrap PrintStr/PrintErr to allow const CHAR16* arguments
Quoted 9 lines · Trammell Hudson
This patch wraps the EFI
OutputString()method so that they can be called with const arguments. The OutputString method does not modify its argument, although the prototype is missing const, so it is necssary to cast away the const when calling it.It also updates callers of PrintStr/PrintErr to remove unneeded un-const casts.
Signed-off-by Trammell Hudson <[email protected]>Reviewed-by Jan Beulich <[email protected]>
This one got committed earlier today, sadly ...
Quoted 4 lines
xen/common/efi/boot.c +0
-0@@ -151,10 +151,17 @@ static struct file __initdata cfg;static struct file __initdata kernel;
xen/common/efi/boot.c static struct file __initdata cfg; · line 158
Quoted 10 lines
xen/common/efi/boot.c +4
-3static struct file __initdata ramdisk;static struct file __initdata xsm; -static CHAR16 __initdata newline[] =L"\r\n" ; +static const CHAR16 __initconst newline[] =L"\r\n" ; -#define PrintStr (s) StdOut->OutputString(StdOut, s) -#define PrintErr (s) StdErr->OutputString(StdErr, s) +static void __init PrintStr (const CHAR16 *s) +{ + StdOut->OutputString (StdOut, (CHAR16 *)s );
... without me noticing the stray blank here and ...
xen/common/efi/boot.c static struct file __initdata cfg; · line 163
Quoted 5 lines
xen/common/efi/boot.c +5
-0+} + +static void __init PrintErr (const CHAR16 *s) +{ + StdErr->OutputString (StdErr, (CHAR16 *)s );
... here.
xen/common/efi/boot.c static char * __init split_string(char *s) · line 553
Quoted 9 lines
xen/common/efi/boot.c +1
-1@@ -540,7 +547,7 @@ static char * __init split_string(char *s)return NULL ; } -static void __init handle_file_info (CHAR16 *name, +static void __init handle_file_info (const CHAR16 *name,const struct file *file,const char *options) {if ( file == &cfg )
Obviously I had to drop this hunk, which should now be folded into patch 2. (If no other need for a v9 arises, I'll try to remember to do so while committing that one.)
Jan
Re: [PATCH v8 3/5] efi/boot.c: wrap PrintStr/PrintErr to allow const CHAR16* arguments
Quoted 10 lines · Jan Beulich
Quoted 7 lines · Trammell Hudson
This patch wraps the EFI
OutputString()method so that they can be called with const arguments. The OutputString method does not modify its argument, although the prototype is missing const, so it is necssary to cast away the const when calling it.
It also updates callers of PrintStr/PrintErr to remove unneeded un-const casts.Signed-off-by Trammell Hudson [email protected]Reviewed-by Jan Beulich [email protected]This one got committed earlier today, sadly ...
Ah, I had missed it when I rebased onto upstream/master, instead of upstream/staging.
Quoted 13 lines
[...]
xen/common/efi/boot.c static char * __init split_string(char *s) · line 552
Quoted 8 lines
xen/common/efi/boot.c +1
-1@@ -540,7 +547,7 @@ static char * __init split_string(char *s)return NULL ; } -static void __init handle_file_info (CHAR16 *name, +static void __init handle_file_info (const CHAR16 *name,const struct file *file,const char *options) {if ( file == &cfg )Obviously I had to drop this hunk, which should now be folded into patch 2. (If no other need for a v9 arises, I'll try to remember to do so while committing that one.)
I've squashed them in my tree in case there is a v9. Hopefully it doesn't come to that...
--
Trammell
PATCH v8 4/5 efi: Enable booting unified hypervisor/kernel/initrd images
In reply to Trammell HudsonThis patch adds support for bundling the xen.efi hypervisor, the xen.cfg configuration file, the Linux kernel and initrd, as well as the XSM, and architectural specific files into a single "unified" EFI executable. This allows an administrator to update the components independently without requiring rebuilding xen, as well as to replace the components in an existing image.
The resulting EFI executable can be invoked directly from the UEFI Boot Manager, removing the need to use a separate loader like grub as well as removing dependencies on local filesystem access. And since it is a single file, it can be signed and validated by UEFI Secure Boot without requring the shim protocol.
It is inspired by systemd-boot's unified kernel technique and borrows the function to locate PE sections from systemd's LGPL'ed code. During EFI boot, Xen looks at its own loaded image to locate the PE sections for the Xen configuration (.config), dom0 kernel (.kernel), dom0 initrd (.ramdisk), and XSM config (.xsm), which are included after building xen.efi using objcopy to add named sections for each input file.
For x86, the CPU ucode can be included in a section named .ucode, which is loaded in the efi_arch_cfg_file_late() stage of the boot process.
On ARM systems the Device Tree can be included in a section named .dtb, which is loaded during the efi_arch_cfg_file_early() stage of the boot process.
Note that the system will fall back to loading files from disk if the named sections do not exist. This allows distributions to continue with the status quo if they want a signed kernel + config, while still allowing a user provided initrd (which is how the shim protocol currently works as well).
This patch also adds constness to the section parameter of efi_arch_cfg_file_early() and efi_arch_cfg_file_late(), changes pe_find_section() to use a const CHAR16 section name, and adds pe_name_compare() to match section names.
--- .gitignore | 1 + docs/misc/efi.pandoc | 49 ++++++++++++ xen/arch/arm/efi/efi-boot.h | 25 ++++-- xen/arch/x86/efi/Makefile | 2 +- xen/arch/x86/efi/efi-boot.h | 11 ++- xen/common/efi/boot.c | 64 ++++++++++----- xen/common/efi/efi.h | 3 + xen/common/efi/pe.c | 153 ++++++++++++++++++++++++++++++++++++ 8 files changed, 279 insertions(+), 29 deletions(-) create mode 100644 xen/common/efi/pe.c
.gitignore +1 -0
@@ -317,6 +317,7 @@ xen/arch/*/efi/boot.c xen/arch/*/efi/compat.c xen/arch/*/efi/ebmalloc.c xen/arch/*/efi/efi.h +xen/arch/*/efi/pe.c xen/arch/*/efi/runtime.c xen/common/config_data.S xen/common/config.gz
docs/misc/efi.pandoc +49 -0
52 lines not on this page · raw message
xen/arch/arm/efi/efi-boot.h +17 -8
@@ -382,27 +382,36 @@ static void __init noreturn efi_arch_post_exit_boot(void)efi_xen_start (fdt,fdt_totalsize (fdt)); } -static void __init efi_arch_cfg_file_early (EFI_FILE_HANDLE dir_handle,char *section) +static void __init efi_arch_cfg_file_early (const EFI_LOADED_IMAGE *image, +EFI_FILE_HANDLE dir_handle, +const char *section) {union string name;/* * The DTB must be processed before any other entries in the configuration -* file, as the DTB is updated as modules are loaded. +* file, as the DTB is updated as modules are loaded. Prefer the one +* stored as a PE section in a unified image, and fall back to a file +* on disk if the section is not present. */ - name.s =get_value (&cfg, section,"dtb" ); -if ( name.s ) +if ( !read_section (image,L"dtb" , &dtbfile,NULL ) ) { -split_string (name.s); -read_file (dir_handle,s2w (&name), &dtbfile,NULL ); - efi_bs->FreePool (name.w); + name.s =get_value (&cfg, section,"dtb" ); +if ( name.s ) + { +split_string (name.s); +read_file (dir_handle,s2w (&name), &dtbfile,NULL ); + efi_bs->FreePool (name.w); + } } fdt =fdt_increase_size (&dtbfile, cfg.size +EFI_PAGE_SIZE );if ( !fdt )blexit (L"Unable to create new FDT" ); } -static void __init efi_arch_cfg_file_late (EFI_FILE_HANDLE dir_handle,char *section) +static void __init efi_arch_cfg_file_late (const EFI_LOADED_IMAGE *image, +EFI_FILE_HANDLE dir_handle, +const char *section) { }
xen/arch/x86/efi/Makefile +1 -1
@@ -8,7 +8,7 @@ cmd_objcopy_o_ihex = $(OBJCOPY) -I ihex -O binary $< $@ boot.init.o: buildid.o -EFIOBJ := boot.init.o ebmalloc.o compat.o runtime.o +EFIOBJ := boot.init.o pe.init.o ebmalloc.o compat.o runtime.o $(call cc-option-add,cflags-stack-boundary,CC,-mpreferred-stack-boundary=4) $(EFIOBJ): CFLAGS-stack-boundary := $(cflags-stack-boundary)
xen/arch/x86/efi/efi-boot.h +9 -2
@@ -272,14 +272,21 @@ static void __init noreturn efi_arch_post_exit_boot(void)unreachable (); } -static void __init efi_arch_cfg_file_early (EFI_FILE_HANDLE dir_handle,char *section) +static void __init efi_arch_cfg_file_early (const EFI_LOADED_IMAGE *image, +EFI_FILE_HANDLE dir_handle, +const char *section) { } -static void __init efi_arch_cfg_file_late (EFI_FILE_HANDLE dir_handle,char *section) +static void __init efi_arch_cfg_file_late (const EFI_LOADED_IMAGE *image, +EFI_FILE_HANDLE dir_handle, +const char *section) {union string name; +if (read_section (image,L"ucode" , &ucode,NULL ) ) +return ; + name.s =get_value (&cfg, section,"ucode" );if ( !name.s ) name.s =get_value (&cfg,"global" ,"ucode" );
xen/common/efi/boot.c +46 -18
103 lines not on this page · raw message
xen/common/efi/efi.h +3 -0
@@ -47,3 +47,6 @@ const CHAR16 *wmemchr(const CHAR16 *s, CHAR16 c, UINTN n);/* EFI boot allocator. */ void *ebmalloc (size_t size);void free_ebmalloc_unused_mem (void ); + +const void *pe_find_section (const void *image_base,const size_t image_size, +const CHAR16 *section_name,UINTN *size_out);
xen/common/efi/pe.c new file +153 -0
153 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v8 4/5] efi: Enable booting unified hypervisor/kernel/initrd images
xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 1238
Quoted 11 lines · Trammell Hudson
xen/common/efi/boot.c +4
-2@@ -1215,9 +1231,11 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)/* Get the file system interface. */ dir_handle =get_parent_handle (loaded_image, &file_name); -/* Read and parse the config file. */ -if ( !cfg_file_name ) +if (read_section (loaded_image,L"config" , &cfg,NULL ) ) +PrintStr (L"Using builtin config file\r\n" ); +else if ( !cfg_file_name ) { +/* Read and parse the config file. */
I'm sorry for noticing this only now, but I don't think this comment should be moved. If no other need for a v9 arises, this can likely be undone while committing.
xen/common/efi/pe.c line 90
Quoted 7 lines
xen/common/efi/pe.c new file +7
-0+static bool __init pe_name_compare (const struct PeSectionHeader *sect, +const CHAR16 *name) +{ +size_t i; + +if ( sect->Name[0 ] !='.' ) +return -1 ;
I was about to say "'true' please", but you really mean 'false" now. (Could perhaps again be fixed while committing.)
xen/common/efi/pe.c line 100
Quoted 9 lines
xen/common/efi/pe.c new file +9
-0+for ( i =1 ; i <sizeof (sect->Name); i++ ) + { +const char c = sect->Name[i]; +const CHAR16 cw = name[i -1 ]; + +if ( cw ==L'\0' && c =='\0' ) +return true; +if ( cw != c ) +return false;
Just as a remark (and again spotting only now) this could be had with one less comparison:
if ( cw != c )
return false;
if ( c == '\0' )
return true;At which the need for cw also disappears.
With at least the earlier two issues addressed
Jan
Re: [PATCH v8 4/5] efi: Enable booting unified hypervisor/kernel/initrd images
Quoted 6 lines · Jan Beulich
Quoted 1 line · Trammell Hudson
- /* Read and parse the config file. */
I'm sorry for noticing this only now, but I don't think this comment should be moved. If no other need for a v9 arises, this can likely be undone while committing.
I'll relocate it.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +0
-2- if ( sect->Name[0] != '.' ) - return -1;I was about to say "'true' please", but you really mean 'false" now. (Could perhaps again be fixed while committing.)
oops oops. Yes, that is a mistake. Should be false; I'll fix it.
Quoted 10 lines
[...]
Just as a remark (and again spotting only now) this could be had with one less comparison:if ( cw != c )
return false;
if ( c == '\0' )
return true;At which the need for cw also disappears.
Sure. I'll fix that, too.
Since there are a few patches to the patch, I'll send out a v9 so that we don't forget any of the ones that we wanted to remember to make.
--
Trammell
PATCH v8 5/5 efi: Do not use command line if unified config is included
In reply to Trammell HudsonIf a unified Xen image is used, then the bundled configuration, Xen command line, dom0 kernel, and ramdisk are prefered over any files listed in the config file or provided on the command line.
Unlike the shim based verification, the PE signature on a unified image covers all of the Xen+config+kernel+initrd modules linked into the unified image. This also ensures that, on properly configured UEFI Secure Boot platforms, the entire runtime will be measured into the TPM for unsealing secrets or remote attestation.
--- xen/common/efi/boot.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-)
xen/common/efi/boot.c +38 -5
@@ -950,6 +950,35 @@ static void __init setup_efi_pci(void) efi_bs->FreePool (handles); } +/* +* Logic should remain sync'ed with linux/arch/x86/xen/efi.c +* Secure Boot is enabled iff 'SecureBoot' is set and the system is +* not in Setup Mode. +*/ +static bool __init efi_secure_boot (void ) +{ +static __initdata EFI_GUID global_guid =EFI_GLOBAL_VARIABLE ; +uint8_t secboot, setupmode; +UINTN secboot_size =sizeof (secboot); +UINTN setupmode_size =sizeof (setupmode); +EFI_STATUS rc; + + rc = efi_rs->GetVariable (L"SecureBoot" , &global_guid, +NULL , &secboot_size, &secboot); +if ( rc !=EFI_SUCCESS ) +return false; + + rc = efi_rs->GetVariable (L"SetupMode" , &global_guid, +NULL , &setupmode_size, &setupmode); +if ( rc !=EFI_SUCCESS ) +return false; + +if ( secboot >1 || setupmode >1 ) +blexit (L"Invalid SecureBoot/SetupMode variables" ); + +return secboot ==1 && setupmode ==0 ; +} +static void __init efi_variables (void ) {EFI_STATUS status;
@@ -1126,15 +1155,15 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)static EFI_GUID __initdata shim_lock_guid =SHIM_LOCK_PROTOCOL_GUID ;EFI_LOADED_IMAGE *loaded_image;EFI_STATUS status; -unsigned int i, argc; -CHAR16 **argv, *file_name, *cfg_file_name =NULL , *options =NULL ; +unsigned int i, argc =0 ; +CHAR16 **argv =NULL , *file_name, *cfg_file_name =NULL , *options =NULL ;UINTN gop_mode = ~0 ;EFI_SHIM_LOCK_PROTOCOL *shim_lock;EFI_GRAPHICS_OUTPUT_PROTOCOL *gop =NULL ;union string section = {NULL }, name;bool base_video = false;const char *option_str; -bool use_cfg_file; +bool use_cfg_file, secure;__set_bit (EFI_BOOT , &efi_flags);__set_bit (EFI_LOADER , &efi_flags);
@@ -1153,8 +1182,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)PrintErrMesg (L"No Loaded Image Protocol" , status);efi_arch_load_addr_check (loaded_image); + secure =efi_secure_boot (); -if ( use_cfg_file ) +if ( use_cfg_file && + !read_section (loaded_image,L"config" , &cfg,NULL ) ) {UINTN offset =0 ;
@@ -1212,6 +1243,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) PrintStr(L"Xen " __stringify(XEN_VERSION) "." __stringify(XEN_SUBVERSION)XEN_EXTRAVERSION " (c/s " XEN_CHANGESET ") EFI loader\r\n" ); +if ( secure ) +PrintStr (L"UEFI Secure Boot enabled\r\n" );efi_arch_relocate_image (0 );
@@ -1231,7 +1264,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)/* Get the file system interface. */ dir_handle =get_parent_handle (loaded_image, &file_name); -if (read_section (loaded_image,L"config" , &cfg,NULL ) ) +if ( cfg.ptr )PrintStr (L"Using builtin config file\r\n" );else if ( !cfg_file_name ) {
Signature · 1 line
2.25.1