@@ -397,17 +397,13 @@ static void __noreturn efi_exit(efi_handle_t handle, efi_status_t status)
397
397
asm("hlt" );
398
398
}
399
399
400
- void __noreturn efi_stub_entry (efi_handle_t handle ,
401
- efi_system_table_t * sys_table_arg ,
402
- struct boot_params * boot_params );
403
-
404
400
/*
405
401
* Because the x86 boot code expects to be passed a boot_params we
406
402
* need to create one ourselves (usually the bootloader would create
407
403
* one for us).
408
404
*/
409
- efi_status_t __efiapi efi_pe_entry (efi_handle_t handle ,
410
- efi_system_table_t * sys_table_arg )
405
+ static efi_status_t efi_allocate_bootparams (efi_handle_t handle ,
406
+ struct boot_params * * bp )
411
407
{
412
408
efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID ;
413
409
struct boot_params * boot_params ;
@@ -416,21 +412,15 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
416
412
unsigned long alloc ;
417
413
char * cmdline_ptr ;
418
414
419
- efi_system_table = sys_table_arg ;
420
-
421
- /* Check if we were booted by the EFI firmware */
422
- if (efi_system_table -> hdr .signature != EFI_SYSTEM_TABLE_SIGNATURE )
423
- efi_exit (handle , EFI_INVALID_PARAMETER );
424
-
425
415
status = efi_bs_call (handle_protocol , handle , & proto , (void * * )& image );
426
416
if (status != EFI_SUCCESS ) {
427
417
efi_err ("Failed to get handle for LOADED_IMAGE_PROTOCOL\n" );
428
- efi_exit ( handle , status ) ;
418
+ return status ;
429
419
}
430
420
431
421
status = efi_allocate_pages (PARAM_SIZE , & alloc , ULONG_MAX );
432
422
if (status != EFI_SUCCESS )
433
- efi_exit ( handle , status ) ;
423
+ return status ;
434
424
435
425
boot_params = memset ((void * )alloc , 0x0 , PARAM_SIZE );
436
426
hdr = & boot_params -> hdr ;
@@ -446,14 +436,14 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
446
436
cmdline_ptr = efi_convert_cmdline (image );
447
437
if (!cmdline_ptr ) {
448
438
efi_free (PARAM_SIZE , alloc );
449
- efi_exit ( handle , EFI_OUT_OF_RESOURCES ) ;
439
+ return EFI_OUT_OF_RESOURCES ;
450
440
}
451
441
452
442
efi_set_u64_split ((unsigned long )cmdline_ptr , & hdr -> cmd_line_ptr ,
453
443
& boot_params -> ext_cmd_line_ptr );
454
444
455
- efi_stub_entry ( handle , sys_table_arg , boot_params ) ;
456
- /* not reached */
445
+ * bp = boot_params ;
446
+ return EFI_SUCCESS ;
457
447
}
458
448
459
449
static void add_e820ext (struct boot_params * params ,
@@ -740,13 +730,16 @@ static efi_status_t parse_options(const char *cmdline)
740
730
return efi_parse_options (cmdline );
741
731
}
742
732
743
- static efi_status_t efi_decompress_kernel (unsigned long * kernel_entry )
733
+ static efi_status_t efi_decompress_kernel (unsigned long * kernel_entry ,
734
+ struct boot_params * boot_params )
744
735
{
745
736
unsigned long virt_addr = LOAD_PHYSICAL_ADDR ;
746
737
unsigned long addr , alloc_size , entry ;
747
738
efi_status_t status ;
748
739
u32 seed [2 ] = {};
749
740
741
+ boot_params_ptr = boot_params ;
742
+
750
743
/* determine the required size of the allocation */
751
744
alloc_size = ALIGN (max_t (unsigned long , output_len , kernel_total_size ),
752
745
MIN_KERNEL_ALIGN );
@@ -777,7 +770,7 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)
777
770
seed [0 ] = 0 ;
778
771
}
779
772
780
- boot_params_ptr -> hdr .loadflags |= KASLR_FLAG ;
773
+ boot_params -> hdr .loadflags |= KASLR_FLAG ;
781
774
}
782
775
783
776
status = efi_random_alloc (alloc_size , CONFIG_PHYSICAL_ALIGN , & addr ,
@@ -815,20 +808,27 @@ static void __noreturn enter_kernel(unsigned long kernel_addr,
815
808
void __noreturn efi_stub_entry (efi_handle_t handle ,
816
809
efi_system_table_t * sys_table_arg ,
817
810
struct boot_params * boot_params )
811
+
818
812
{
819
813
efi_guid_t guid = EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID ;
820
- struct setup_header * hdr = & boot_params -> hdr ;
821
814
const struct linux_efi_initrd * initrd = NULL ;
822
815
unsigned long kernel_entry ;
816
+ struct setup_header * hdr ;
823
817
efi_status_t status ;
824
818
825
- boot_params_ptr = boot_params ;
826
-
827
819
efi_system_table = sys_table_arg ;
828
820
/* Check if we were booted by the EFI firmware */
829
821
if (efi_system_table -> hdr .signature != EFI_SYSTEM_TABLE_SIGNATURE )
830
822
efi_exit (handle , EFI_INVALID_PARAMETER );
831
823
824
+ if (!IS_ENABLED (CONFIG_EFI_HANDOVER_PROTOCOL ) || !boot_params ) {
825
+ status = efi_allocate_bootparams (handle , & boot_params );
826
+ if (status != EFI_SUCCESS )
827
+ efi_exit (handle , status );
828
+ }
829
+
830
+ hdr = & boot_params -> hdr ;
831
+
832
832
if (have_unsupported_snp_features ())
833
833
efi_exit (handle , EFI_UNSUPPORTED );
834
834
@@ -870,7 +870,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
870
870
if (efi_mem_encrypt > 0 )
871
871
hdr -> xloadflags |= XLF_MEM_ENCRYPTION ;
872
872
873
- status = efi_decompress_kernel (& kernel_entry );
873
+ status = efi_decompress_kernel (& kernel_entry , boot_params );
874
874
if (status != EFI_SUCCESS ) {
875
875
efi_err ("Failed to decompress kernel\n" );
876
876
goto fail ;
@@ -940,6 +940,12 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
940
940
efi_exit (handle , status );
941
941
}
942
942
943
+ efi_status_t __efiapi efi_pe_entry (efi_handle_t handle ,
944
+ efi_system_table_t * sys_table_arg )
945
+ {
946
+ efi_stub_entry (handle , sys_table_arg , NULL );
947
+ }
948
+
943
949
#ifdef CONFIG_EFI_HANDOVER_PROTOCOL
944
950
void efi_handover_entry (efi_handle_t handle , efi_system_table_t * sys_table_arg ,
945
951
struct boot_params * boot_params )
0 commit comments