diff mbox series

[v3,2/2] efi/loongarch: load address is not equal to link address

Message ID 20231205060345.7742-3-wangyao@lemote.com
State New
Headers show
Series Use load address to calculate kernel entry | expand

Commit Message

wangyao@lemote.com Dec. 5, 2023, 6:03 a.m. UTC
From: Wang Yao <wangyao@lemote.com>

This is a test patch for PIE kernel that load address is not equal to
link address.

Signed-off-by: Wang Yao <wangyao@lemote.com>
---
 drivers/firmware/efi/libstub/loongarch-stub.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c
index d6ec5d4b8dbe..c13c022d18cf 100644
--- a/drivers/firmware/efi/libstub/loongarch-stub.c
+++ b/drivers/firmware/efi/libstub/loongarch-stub.c
@@ -22,12 +22,22 @@  efi_status_t handle_kernel_image(unsigned long *image_addr,
 				 efi_handle_t image_handle)
 {
 	efi_status_t status;
-	unsigned long kernel_addr = 0;
+	unsigned long kernel_addr = 0, tmp_addr = 0;
 
 	kernel_addr = (unsigned long)&kernel_offset - kernel_offset;
 
+	/*
+	 * Allocate 2M space at 0x200000(EFI_KIMG_PREFERRED_ADDRESS) for
+	 * test, this will lead to the kernel be loaded at 0x4000000.
+	 */
+	status = efi_relocate_kernel(&tmp_addr, 0x100000, 0x200000,
+		     EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0);
+	efi_info("@@@[%s] tmp_addr: 0x%lx\n", __func__, tmp_addr);
+
+	/* kernel_addr == 0x400000 */
 	status = efi_relocate_kernel(&kernel_addr, kernel_fsize, kernel_asize,
 		     EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0);
+	efi_info("@@@[%s] kernel_addr: 0x%lx\n", __func__, kernel_addr);
 
 	*image_addr = kernel_addr;
 	*image_size = kernel_asize;