Skip to content

Commit 8364f6d

Browse files
chenhuacaiardbiesheuvel
authored andcommitted
efi/loongarch: Reintroduce efi_relocate_kernel() to relocate kernel
Since Linux-6.3, LoongArch supports PIE kernel now, so let's reintroduce efi_relocate_kernel() to relocate the core kernel. Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 197b6b6 commit 8364f6d

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

drivers/firmware/efi/libstub/loongarch-stub.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,16 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
2121
efi_loaded_image_t *image,
2222
efi_handle_t image_handle)
2323
{
24-
int nr_pages = round_up(kernel_asize, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE;
25-
efi_physical_addr_t kernel_addr = EFI_KIMG_PREFERRED_ADDRESS;
2624
efi_status_t status;
25+
unsigned long kernel_addr = 0;
2726

28-
/*
29-
* Allocate space for the kernel image at the preferred offset. This is
30-
* the only location in memory from where we can execute the image, so
31-
* no point in falling back to another allocation.
32-
*/
33-
status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS,
34-
EFI_LOADER_DATA, nr_pages, &kernel_addr);
35-
if (status != EFI_SUCCESS)
36-
return status;
37-
38-
*image_addr = EFI_KIMG_PREFERRED_ADDRESS;
39-
*image_size = kernel_asize;
27+
kernel_addr = (unsigned long)&kernel_offset - kernel_offset;
28+
29+
status = efi_relocate_kernel(&kernel_addr, kernel_fsize, kernel_asize,
30+
EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0);
4031

41-
memcpy((void *)EFI_KIMG_PREFERRED_ADDRESS,
42-
(void *)&kernel_offset - kernel_offset,
43-
kernel_fsize);
32+
*image_addr = kernel_addr;
33+
*image_size = kernel_asize;
4434

4535
return status;
4636
}

0 commit comments

Comments
 (0)