77
88#include "efistub.h"
99
10- static unsigned char zboot_heap [SZ_256K ] __aligned (64 );
11- static unsigned long free_mem_ptr , free_mem_end_ptr ;
12-
13- #define STATIC static
14- #if defined(CONFIG_KERNEL_GZIP )
15- #include "../../../../lib/decompress_inflate.c"
16- #elif defined(CONFIG_KERNEL_LZ4 )
17- #include "../../../../lib/decompress_unlz4.c"
18- #elif defined(CONFIG_KERNEL_LZMA )
19- #include "../../../../lib/decompress_unlzma.c"
20- #elif defined(CONFIG_KERNEL_LZO )
21- #include "../../../../lib/decompress_unlzo.c"
22- #elif defined(CONFIG_KERNEL_XZ )
23- #undef memcpy
24- #define memcpy memcpy
25- #undef memmove
26- #define memmove memmove
27- #include "../../../../lib/decompress_unxz.c"
28- #elif defined(CONFIG_KERNEL_ZSTD )
29- #include "../../../../lib/decompress_unzstd.c"
30- #endif
31-
32- extern char efi_zboot_header [];
33- extern char _gzdata_start [], _gzdata_end [];
34-
35- static void error (char * x )
36- {
37- efi_err ("EFI decompressor: %s\n" , x );
38- }
39-
4010static unsigned long alloc_preferred_address (unsigned long alloc_size )
4111{
4212#ifdef EFI_KIMG_PREFERRED_ADDRESS
@@ -64,22 +34,17 @@ struct screen_info *alloc_screen_info(void)
6434asmlinkage efi_status_t __efiapi
6535efi_zboot_entry (efi_handle_t handle , efi_system_table_t * systab )
6636{
67- unsigned long compressed_size = _gzdata_end - _gzdata_start ;
37+ char * cmdline_ptr __free ( efi_pool ) = NULL ;
6838 unsigned long image_base , alloc_size ;
6939 efi_loaded_image_t * image ;
7040 efi_status_t status ;
71- char * cmdline_ptr ;
72- int ret ;
7341
7442 WRITE_ONCE (efi_system_table , systab );
7543
76- free_mem_ptr = (unsigned long )& zboot_heap ;
77- free_mem_end_ptr = free_mem_ptr + sizeof (zboot_heap );
78-
7944 status = efi_bs_call (handle_protocol , handle ,
8045 & LOADED_IMAGE_PROTOCOL_GUID , (void * * )& image );
8146 if (status != EFI_SUCCESS ) {
82- error ("Failed to locate parent's loaded image protocol" );
47+ efi_err ("Failed to locate parent's loaded image protocol\n " );
8348 return status ;
8449 }
8550
@@ -89,9 +54,9 @@ efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab)
8954
9055 efi_info ("Decompressing Linux Kernel...\n" );
9156
92- // SizeOfImage from the compressee's PE/COFF header
93- alloc_size = round_up ( get_unaligned_le32 ( _gzdata_end - 4 ),
94- EFI_ALLOC_ALIGN ) ;
57+ status = efi_zboot_decompress_init ( & alloc_size );
58+ if ( status != EFI_SUCCESS )
59+ return status ;
9560
9661 // If the architecture has a preferred address for the image,
9762 // try that first.
@@ -122,26 +87,14 @@ efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab)
12287 seed , EFI_LOADER_CODE , 0 , EFI_ALLOC_LIMIT );
12388 if (status != EFI_SUCCESS ) {
12489 efi_err ("Failed to allocate memory\n" );
125- goto free_cmdline ;
90+ return status ;
12691 }
12792 }
12893
129- // Decompress the payload into the newly allocated buffer.
130- ret = __decompress (_gzdata_start , compressed_size , NULL , NULL ,
131- (void * )image_base , alloc_size , NULL , error );
132- if (ret < 0 ) {
133- error ("Decompression failed" );
134- status = EFI_DEVICE_ERROR ;
135- goto free_image ;
136- }
137-
138- efi_cache_sync_image (image_base , alloc_size );
139-
140- status = efi_stub_common (handle , image , image_base , cmdline_ptr );
94+ // Decompress the payload into the newly allocated buffer
95+ status = efi_zboot_decompress ((void * )image_base , alloc_size ) ?:
96+ efi_stub_common (handle , image , image_base , cmdline_ptr );
14197
142- free_image :
14398 efi_free (alloc_size , image_base );
144- free_cmdline :
145- efi_bs_call (free_pool , cmdline_ptr );
14699 return status ;
147100}
0 commit comments