Skip to content

Commit 271f2a4

Browse files
AlooGSardbiesheuvel
authored andcommitted
efi/loongarch: Use load address to calculate kernel entry address
The efi_relocate_kernel() may load the PIE kernel to anywhere, the loaded address may not be equal to link address or EFI_KIMG_PREFERRED_ADDRESS. Acked-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Wang Yao <wangyao@lemote.com> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 01b1e3c commit 271f2a4

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

arch/loongarch/include/asm/efi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ static inline unsigned long efi_get_kimg_min_align(void)
3232

3333
#define EFI_KIMG_PREFERRED_ADDRESS PHYSADDR(VMLINUX_LOAD_ADDRESS)
3434

35-
unsigned long kernel_entry_address(void);
35+
unsigned long kernel_entry_address(unsigned long kernel_addr);
3636

3737
#endif /* _ASM_LOONGARCH_EFI_H */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
3535
return status;
3636
}
3737

38-
unsigned long kernel_entry_address(void)
38+
unsigned long kernel_entry_address(unsigned long kernel_addr)
3939
{
4040
unsigned long base = (unsigned long)&kernel_offset - kernel_offset;
4141

42-
return (unsigned long)&kernel_entry - base + VMLINUX_LOAD_ADDRESS;
42+
return (unsigned long)&kernel_entry - base + kernel_addr;
4343
}

drivers/firmware/efi/libstub/loongarch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
3737
return EFI_SUCCESS;
3838
}
3939

40-
unsigned long __weak kernel_entry_address(void)
40+
unsigned long __weak kernel_entry_address(unsigned long kernel_addr)
4141
{
42-
return *(unsigned long *)(PHYSADDR(VMLINUX_LOAD_ADDRESS) + 8);
42+
return *(unsigned long *)(kernel_addr + 8) - VMLINUX_LOAD_ADDRESS + kernel_addr;
4343
}
4444

4545
efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
@@ -73,7 +73,7 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
7373
csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0);
7474
csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1);
7575

76-
real_kernel_entry = (void *)kernel_entry_address();
76+
real_kernel_entry = (void *)kernel_entry_address(kernel_addr);
7777

7878
real_kernel_entry(true, (unsigned long)cmdline_ptr,
7979
(unsigned long)efi_system_table);

0 commit comments

Comments
 (0)