1616#include <efilib.h>
1717
1818#include "kernel-stub.h"
19- #include "version.h"
2019#include "loader_interface.h"
20+ #include "print.h"
21+ #include "version.h"
2122
2223typedef struct {
2324 UINT8 Ignore [60 ];
@@ -55,7 +56,6 @@ typedef struct {
5556 UINT8 Ignore [24 ];
5657} __attribute__((packed )) SECTION ;
5758
58- static EFI_HANDLE this_image ;
5959static EFI_LOADED_IMAGE kernel_image ;
6060
6161EFI_PHYSICAL_ADDRESS align_addr (EFI_PHYSICAL_ADDRESS ptr ,
@@ -64,24 +64,6 @@ EFI_PHYSICAL_ADDRESS align_addr(EFI_PHYSICAL_ADDRESS ptr,
6464 return (ptr + align - 1 ) & ~(align - 1 );
6565}
6666
67- VOID info (CHAR16 * message )
68- {
69- Print (L"Unified kernel stub: %s\n" , message );
70- }
71-
72- VOID error (CHAR16 * message , EFI_STATUS status )
73- {
74- Print (L"Unified kernel stub: %s (%r).\n" , message , status );
75- (VOID ) BS -> Stall (3 * 1000 * 1000 );
76- }
77-
78- VOID __attribute__((noreturn )) error_exit (CHAR16 * message , EFI_STATUS status )
79- {
80- error (message , status );
81- (VOID ) BS -> Exit (this_image , status , 0 , NULL );
82- __builtin_unreachable ();
83- }
84-
8567static const PE_HEADER * get_pe_header (const VOID * image )
8668{
8769 const DOS_HEADER * dos_header = image ;
@@ -119,8 +101,10 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
119101 this_image = image_handle ;
120102 InitializeLib (image_handle , system_table );
121103
122- Print (L"Unified kernel stub (EFI Boot Guard %s)\n" ,
123- L"" EFIBOOTGUARD_VERSION );
104+ #if !defined(SILENT_BOOT )
105+ PrintC (EFI_CYAN , L"Unified kernel stub (EFI Boot Guard %s)\n" ,
106+ L"" EFIBOOTGUARD_VERSION );
107+ #endif
124108
125109 fdt_compatible = get_fdt_compatible ();
126110
@@ -133,7 +117,7 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
133117
134118 /* consider zero-termination for string length */
135119 if (stub_image -> LoadOptionsSize > sizeof (CHAR16 )) {
136- info (L"WARNING: Passed command line options ignored, only built-in used" );
120+ WARNING (L"Passed command line options ignored, only built-in used\n " );
137121 }
138122
139123 pe_header = get_pe_header (stub_image -> ImageBase );
@@ -192,14 +176,14 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
192176 status = BS -> AllocatePages (AllocateAnyPages , EfiLoaderData ,
193177 kernel_pages , & kernel_buffer );
194178 if (EFI_ERROR (status )) {
195- error (L"Error allocating memory for kernel image" , status );
179+ ERROR (L"Could not allocate memory for kernel image\n" );
196180 goto cleanup_initrd ;
197181 }
198182
199183 aligned_kernel_buffer =
200184 align_addr (kernel_buffer , pe_header -> Opt .SectionAlignment );
201185 if ((uintptr_t ) aligned_kernel_buffer != aligned_kernel_buffer ) {
202- error (L"Alignment overflow for kernel image" , EFI_LOAD_ERROR );
186+ ERROR (L"Alignment overflow for kernel image\n" );
203187 status = EFI_LOAD_ERROR ;
204188 goto cleanup_buffer ;
205189 }
@@ -216,7 +200,7 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
216200 & kernel_handle , & LoadedImageProtocol , & kernel_image ,
217201 NULL );
218202 if (EFI_ERROR (status )) {
219- error (L"Error registering kernel image" , status );
203+ ERROR (L"Registering kernel image failed (%r)\n " , status );
220204 goto cleanup_buffer ;
221205 }
222206
@@ -225,20 +209,20 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
225209 if (EFI_ERROR (status )) {
226210 goto cleanup_protocols ;
227211 }
228- info (L"Using matched embedded device tree" );
212+ INFO (L"Using matched embedded device tree\n " );
229213 } else if (fdt_compatible ) {
230214 if (has_dtbs ) {
231- info (L"WARNING: No embedded device tree matched firmware-provided one" );
215+ WARNING (L"No embedded device tree matched firmware-provided one\n " );
232216 }
233- info (L"Using firmware-provided device tree" );
217+ INFO (L"Using firmware-provided device tree\n " );
234218 }
235219
236220 UINT16 * boot_medium_uuidstr =
237221 disk_get_part_uuid (stub_image -> DeviceHandle );
238222 bg_interface_params .loader_device_part_uuid = boot_medium_uuidstr ;
239223 status = set_bg_interface_vars (& bg_interface_params );
240224 if (EFI_ERROR (status )) {
241- error (L"could not set interface vars" , status );
225+ WARNING (L"Could not set interface vars (%r)\n " , status );
242226 }
243227 FreePool (boot_medium_uuidstr );
244228
@@ -253,7 +237,7 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
253237 kernel_handle , & LoadedImageProtocol , & kernel_image ,
254238 NULL );
255239 if (EFI_ERROR (cleanup_status )) {
256- error (L"Error unregistering kernel image" , status );
240+ ERROR (L"Unregistering kernel image failed (%r)\n " , status );
257241 if (!EFI_ERROR (status )) {
258242 status = cleanup_status ;
259243 }
@@ -263,5 +247,8 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
263247cleanup_initrd :
264248 uninstall_initrd_loader ();
265249
250+ if (EFI_ERROR (status )) {
251+ (VOID ) BS -> Stall (3 * 1000 * 1000 );
252+ }
266253 return status ;
267254}
0 commit comments