Skip to content

Commit

Permalink
efi/loongarch: Directly position the loaded image file
Browse files Browse the repository at this point in the history
[ Upstream commit 174a0c5 ]

The use of the 'kernel_offset' variable to position the image file that
has been loaded by UEFI or GRUB is unnecessary, because we can directly
position the loaded image file through using the image_base field of the
efi_loaded_image struct provided by UEFI.

Replace kernel_offset with image_base to position the image file that has
been loaded by UEFI or GRUB.

Signed-off-by: Wang Yao <[email protected]>
Signed-off-by: Ard Biesheuvel <[email protected]>
Stable-dep-of: beb2800 ("LoongArch: Fix entry point in kernel image header")
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
AlooGS authored and gregkh committed Jun 27, 2024
1 parent d9a5d5c commit eae6e7d
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
2 changes: 0 additions & 2 deletions arch/loongarch/include/asm/efi.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ static inline unsigned long efi_get_kimg_min_align(void)

#define EFI_KIMG_PREFERRED_ADDRESS PHYSADDR(VMLINUX_LOAD_ADDRESS)

unsigned long kernel_entry_address(unsigned long kernel_addr);

#endif /* _ASM_LOONGARCH_EFI_H */
1 change: 0 additions & 1 deletion arch/loongarch/kernel/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pe_header:

SYM_DATA(kernel_asize, .long _kernel_asize);
SYM_DATA(kernel_fsize, .long _kernel_fsize);
SYM_DATA(kernel_offset, .long _kernel_offset);

#endif

Expand Down
1 change: 0 additions & 1 deletion arch/loongarch/kernel/image-vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ __efistub_strcmp = strcmp;
__efistub_kernel_entry = kernel_entry;
__efistub_kernel_asize = kernel_asize;
__efistub_kernel_fsize = kernel_fsize;
__efistub_kernel_offset = kernel_offset;
__efistub_screen_info = screen_info;

#endif
Expand Down
1 change: 0 additions & 1 deletion arch/loongarch/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ SECTIONS
_kernel_fsize = _edata - _text;
_kernel_vsize = _end - __initdata_begin;
_kernel_rsize = _edata - __initdata_begin;
_kernel_offset = kernel_offset - _text;
#endif

.gptab.sdata : {
Expand Down
9 changes: 5 additions & 4 deletions drivers/firmware/efi/libstub/loongarch-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include <asm/efi.h>
#include <asm/addrspace.h>
#include "efistub.h"
#include "loongarch-stub.h"

extern int kernel_asize;
extern int kernel_fsize;
extern int kernel_offset;
extern int kernel_entry;

efi_status_t handle_kernel_image(unsigned long *image_addr,
Expand All @@ -24,7 +24,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
efi_status_t status;
unsigned long kernel_addr = 0;

kernel_addr = (unsigned long)&kernel_offset - kernel_offset;
kernel_addr = (unsigned long)image->image_base;

status = efi_relocate_kernel(&kernel_addr, kernel_fsize, kernel_asize,
EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0);
Expand All @@ -35,9 +35,10 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
return status;
}

unsigned long kernel_entry_address(unsigned long kernel_addr)
unsigned long kernel_entry_address(unsigned long kernel_addr,
efi_loaded_image_t *image)
{
unsigned long base = (unsigned long)&kernel_offset - kernel_offset;
unsigned long base = (unsigned long)image->image_base;

return (unsigned long)&kernel_entry - base + kernel_addr;
}
4 changes: 4 additions & 0 deletions drivers/firmware/efi/libstub/loongarch-stub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* SPDX-License-Identifier: GPL-2.0-only */

unsigned long kernel_entry_address(unsigned long kernel_addr,
efi_loaded_image_t *image);
6 changes: 4 additions & 2 deletions drivers/firmware/efi/libstub/loongarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <asm/efi.h>
#include <asm/addrspace.h>
#include "efistub.h"
#include "loongarch-stub.h"

typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline,
unsigned long systab);
Expand Down Expand Up @@ -37,7 +38,8 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
return EFI_SUCCESS;
}

unsigned long __weak kernel_entry_address(unsigned long kernel_addr)
unsigned long __weak kernel_entry_address(unsigned long kernel_addr,
efi_loaded_image_t *image)
{
return *(unsigned long *)(kernel_addr + 8) - VMLINUX_LOAD_ADDRESS + kernel_addr;
}
Expand Down Expand Up @@ -73,7 +75,7 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0);
csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1);

real_kernel_entry = (void *)kernel_entry_address(kernel_addr);
real_kernel_entry = (void *)kernel_entry_address(kernel_addr, image);

real_kernel_entry(true, (unsigned long)cmdline_ptr,
(unsigned long)efi_system_table);
Expand Down

0 comments on commit eae6e7d

Please sign in to comment.