[PATCH 3/5] arm64: change the prototype of image probe function

Pingfan Liu piliu at redhat.com
Thu May 4 19:54:35 PDT 2023


Changing the aarch64 probe's prototype  from
	typedef int (probe_t)(const char *kernel_buf, off_t kernel_size);
to
	typedef int (probe_t)(const char *kernel_buf, off_t kernel_size, struct kexec_info *info);

Later, info can be used to return both the file descriptor and parsed kernel
buffer. The fd is passed to sys_kexec_file_load, and the parsed kernel
buffer is used by image's load function.

Signed-off-by: Pingfan Liu <piliu at redhat.com>
To: kexec at lists.infradead.org
Cc: horms at verge.net.au
Cc: ardb at kernel.org
Cc: jeremy.linton at arm.com

---
 kexec/arch/arm/kexec-arm.h            |  4 ++--
 kexec/arch/arm/kexec-uImage-arm.c     |  2 +-
 kexec/arch/arm64/kexec-arm64.h        |  8 ++++----
 kexec/arch/arm64/kexec-elf-arm64.c    |  2 +-
 kexec/arch/arm64/kexec-image-arm64.c  |  2 +-
 kexec/arch/arm64/kexec-uImage-arm64.c |  2 +-
 kexec/arch/arm64/kexec-zImage-arm64.c |  2 +-
 kexec/kexec.c                         | 15 +++++++++++++--
 kexec/kexec.h                         |  6 ++++++
 9 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/kexec/arch/arm/kexec-arm.h b/kexec/arch/arm/kexec-arm.h
index a74cce2..18069f3 100644
--- a/kexec/arch/arm/kexec-arm.h
+++ b/kexec/arch/arm/kexec-arm.h
@@ -9,12 +9,12 @@
 
 extern off_t initrd_base, initrd_size;
 
-int zImage_arm_probe(const char *buf, off_t len);
+int zImage_arm_probe(const char *buf, off_t len, struct kexec_info *info);
 int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 		        struct kexec_info *info);
 void zImage_arm_usage(void);
 
-int uImage_arm_probe(const char *buf, off_t len);
+int uImage_arm_probe(const char *buf, off_t len, struct kexec_info *info);
 int uImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 		        struct kexec_info *info);
 extern int have_sysfs_fdt(void);
diff --git a/kexec/arch/arm/kexec-uImage-arm.c b/kexec/arch/arm/kexec-uImage-arm.c
index 03c2f4d..d955eb3 100644
--- a/kexec/arch/arm/kexec-uImage-arm.c
+++ b/kexec/arch/arm/kexec-uImage-arm.c
@@ -9,7 +9,7 @@
 #include "../../kexec.h"
 #include "kexec-arm.h"
 
-int uImage_arm_probe(const char *buf, off_t len)
+int uImage_arm_probe(const char *buf, off_t len, struct kexec_info *info)
 {
 	return uImage_probe_kernel(buf, len, IH_ARCH_ARM);
 }
diff --git a/kexec/arch/arm64/kexec-arm64.h b/kexec/arch/arm64/kexec-arm64.h
index 5eb9fc0..88bb508 100644
--- a/kexec/arch/arm64/kexec-arm64.h
+++ b/kexec/arch/arm64/kexec-arm64.h
@@ -29,22 +29,22 @@
 #define NOT_KV_ADDR	(0x0)
 #define NOT_PADDR	(ULONGLONG_MAX)
 
-int elf_arm64_probe(const char *kernel_buf, off_t kernel_size);
+int elf_arm64_probe(const char *kernel_buf, off_t kernel_size, struct kexec_info *info);
 int elf_arm64_load(int argc, char **argv, const char *kernel_buf,
 	off_t kernel_size, struct kexec_info *info);
 void elf_arm64_usage(void);
 
-int image_arm64_probe(const char *kernel_buf, off_t kernel_size);
+int image_arm64_probe(const char *kernel_buf, off_t kernel_size, struct kexec_info *info);
 int image_arm64_load(int argc, char **argv, const char *kernel_buf,
 	off_t kernel_size, struct kexec_info *info);
 void image_arm64_usage(void);
 
-int uImage_arm64_probe(const char *buf, off_t len);
+int uImage_arm64_probe(const char *buf, off_t len, struct kexec_info *info);
 int uImage_arm64_load(int argc, char **argv, const char *buf, off_t len,
 		      struct kexec_info *info);
 void uImage_arm64_usage(void);
 
-int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size);
+int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size, struct kexec_info *info);
 int zImage_arm64_load(int argc, char **argv, const char *kernel_buf,
 	off_t kernel_size, struct kexec_info *info);
 void zImage_arm64_usage(void);
diff --git a/kexec/arch/arm64/kexec-elf-arm64.c b/kexec/arch/arm64/kexec-elf-arm64.c
index e14f8e9..9238dd5 100644
--- a/kexec/arch/arm64/kexec-elf-arm64.c
+++ b/kexec/arch/arm64/kexec-elf-arm64.c
@@ -16,7 +16,7 @@
 #include "kexec-elf.h"
 #include "kexec-syscall.h"
 
-int elf_arm64_probe(const char *kernel_buf, off_t kernel_size)
+int elf_arm64_probe(const char *kernel_buf, off_t kernel_size, struct kexec_info *info)
 {
 	struct mem_ehdr ehdr;
 	int result;
diff --git a/kexec/arch/arm64/kexec-image-arm64.c b/kexec/arch/arm64/kexec-image-arm64.c
index aa8f2e2..84aca72 100644
--- a/kexec/arch/arm64/kexec-image-arm64.c
+++ b/kexec/arch/arm64/kexec-image-arm64.c
@@ -14,7 +14,7 @@
 #include "kexec-syscall.h"
 #include "arch/options.h"
 
-int image_arm64_probe(const char *kernel_buf, off_t kernel_size)
+int image_arm64_probe(const char *kernel_buf, off_t kernel_size, struct kexec_info *info)
 {
 	const struct arm64_image_header *h;
 
diff --git a/kexec/arch/arm64/kexec-uImage-arm64.c b/kexec/arch/arm64/kexec-uImage-arm64.c
index c466913..f5b94c8 100644
--- a/kexec/arch/arm64/kexec-uImage-arm64.c
+++ b/kexec/arch/arm64/kexec-uImage-arm64.c
@@ -9,7 +9,7 @@
 #include "../../kexec.h"
 #include "kexec-arm64.h"
 
-int uImage_arm64_probe(const char *buf, off_t len)
+int uImage_arm64_probe(const char *buf, off_t len, struct kexec_info *info)
 {
 	int ret;
 
diff --git a/kexec/arch/arm64/kexec-zImage-arm64.c b/kexec/arch/arm64/kexec-zImage-arm64.c
index 166d7ef..7877741 100644
--- a/kexec/arch/arm64/kexec-zImage-arm64.c
+++ b/kexec/arch/arm64/kexec-zImage-arm64.c
@@ -40,7 +40,7 @@
  * fd : File descriptor of the temp file containing the decompressed
  *      Image.
  */
-int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size)
+int zImage_arm64_probe(const char *kernel_buf, off_t kernel_size, struct kexec_info *info)
 {
 	int ret = -1;
 	int fd = 0;
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 614cd1d..116fb4a 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -742,14 +742,25 @@ static int my_load(const char *type, int fileind, int argc, char **argv,
 			return -1;
 		} else {
 			/* make sure our file is really of that type */
+#ifndef __aarch64__
 			if (file_type[i].probe(kernel_buf, kernel_size) < 0)
 				guess_only = 1;
+#else
+			if (file_type[i].probe(kernel_buf, kernel_size, &info) < 0)
+				guess_only = 1;
+
+#endif
 		}
 	}
 	if (!type || guess_only) {
 		for (i = 0; i < file_types; i++) {
+#ifndef __aarch64__
 			if (file_type[i].probe(kernel_buf, kernel_size) == 0)
 				break;
+#else
+			if (file_type[i].probe(kernel_buf, kernel_size, &info) == 0)
+				break;
+#endif
 		}
 		if (i == file_types) {
 			fprintf(stderr, "Cannot determine the file type "
@@ -1304,12 +1315,12 @@ static int do_kexec_file_load(int fileind, int argc, char **argv,
 #ifdef __aarch64__
 		/* handle Image.gz like cases */
 		if (is_zlib_file(kernel, &kernel_size)) {
-			if ((ret = file_type[i].probe(kernel, kernel_size)) >= 0) {
+			if ((ret = file_type[i].probe(kernel, kernel_size, &info)) >= 0) {
 				kernel_fd = ret;
 				break;
 			}
 		} else
-			if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
+			if (file_type[i].probe(kernel_buf, kernel_size, &info) >= 0)
 				break;
 #else
 		if (file_type[i].probe(kernel_buf, kernel_size) >= 0)
diff --git a/kexec/kexec.h b/kexec/kexec.h
index 0d820ad..6e8430e 100644
--- a/kexec/kexec.h
+++ b/kexec/kexec.h
@@ -191,7 +191,13 @@ unsigned long locate_hole(struct kexec_info *info,
 	unsigned long hole_min, unsigned long hole_max,
 	int hole_end);
 
+#ifndef __aarch64__
 typedef int (probe_t)(const char *kernel_buf, off_t kernel_size);
+#else
+typedef int (probe_t)(const char *kern_fname, off_t kernel_size,
+	struct kexec_info *info);
+#endif
+
 typedef int (load_t )(int argc, char **argv,
 	const char *kernel_buf, off_t kernel_size, 
 	struct kexec_info *info);
-- 
2.31.1




More information about the kexec mailing list