[PATCH 6/7] LoongArch: Fix the use of loongarch_image_header in ELF format

Youling Tang youling.tang at linux.dev
Fri Aug 29 02:10:39 PDT 2025


From: Youling Tang <tangyouling at kylinios.cn>

loongarch_image_header should not be used in the ELF format. When the CONFIG_EFI_STUB
configuration is turned off, the ELF kernel image will not add loongarch_image_heade
processing, as can be seen from the kernel code arch/loongarch/kernel/head.S.

Thus, use the elf header content to fix this issue.

Signed-off-by: Youling Tang <tangyouling at kylinios.cn>
---
 kexec/arch/loongarch/image-header.h        |  2 +-
 kexec/arch/loongarch/kexec-elf-loongarch.c | 12 ++++--------
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/kexec/arch/loongarch/image-header.h b/kexec/arch/loongarch/image-header.h
index 223d81f..0db7615 100644
--- a/kexec/arch/loongarch/image-header.h
+++ b/kexec/arch/loongarch/image-header.h
@@ -1,5 +1,5 @@
 /*
- * LoongArch binary image header.
+ * LoongArch binary image header. (for pei/pez format)
  */
 
 #if !defined(__LOONGARCH_IMAGE_HEADER_H)
diff --git a/kexec/arch/loongarch/kexec-elf-loongarch.c b/kexec/arch/loongarch/kexec-elf-loongarch.c
index 44b63a9..92fa9f8 100644
--- a/kexec/arch/loongarch/kexec-elf-loongarch.c
+++ b/kexec/arch/loongarch/kexec-elf-loongarch.c
@@ -72,7 +72,6 @@ static bool laabs_section(const struct mem_ehdr *ehdr)
 int elf_loongarch_load(int argc, char **argv, const char *kernel_buf,
 	off_t kernel_size, struct kexec_info *info)
 {
-	const struct loongarch_image_header *header = NULL;
 	unsigned long kernel_segment;
 	struct mem_ehdr ehdr;
 	int result;
@@ -95,22 +94,19 @@ int elf_loongarch_load(int argc, char **argv, const char *kernel_buf,
 		}
 	}
 
-	/* Find and process the loongarch image header. */
 	for (i = 0; i < ehdr.e_phnum; i++) {
 		struct mem_phdr *phdr = &ehdr.e_phdr[i];
 
 		if (phdr->p_type != PT_LOAD)
 			continue;
 
-		header = (const struct loongarch_image_header *)(
-			kernel_buf + phdr->p_offset);
-
-		if (!loongarch_process_image_header(header))
-			break;
+		loongarch_mem.text_offset = virt_to_phys(phdr->p_paddr);
+		loongarch_mem.image_size = _ALIGN_UP(phdr->p_memsz, KiB(64));
+		break;
 	}
 
 	if (i == ehdr.e_phnum) {
-		dbgprintf("%s: Valid loongarch image header not found\n", __func__);
+		dbgprintf("%s: Valid loongarch phdr not found\n", __func__);
 		result = EFAILED;
 		goto exit;
 	}
-- 
2.34.1




More information about the kexec mailing list