diff mbox series

[15/18] x86: zimage: Export the function to obtain the cmdline

Message ID 20230428191819.3070393-11-sjg@chromium.org
State Superseded
Delegated to: Bin Meng
Headers show
Series bootstd: Add a bootmeth for ChromiumOS on x86 | expand

Commit Message

Simon Glass April 28, 2023, 7:18 p.m. UTC
Allow reading the command line from a zimage, so that it can be recorded
in the bootflow.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/x86/include/asm/zimage.h | 10 ++++++++++
 arch/x86/lib/zimage.c         | 11 ++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

Comments

Bin Meng May 15, 2023, 10:51 a.m. UTC | #1
On Sat, Apr 29, 2023 at 3:18 AM Simon Glass <sjg@chromium.org> wrote:
>
> Allow reading the command line from a zimage, so that it can be recorded
> in the bootflow.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/x86/include/asm/zimage.h | 10 ++++++++++
>  arch/x86/lib/zimage.c         | 11 ++++++++---
>  2 files changed, 18 insertions(+), 3 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
diff mbox series

Patch

diff --git a/arch/x86/include/asm/zimage.h b/arch/x86/include/asm/zimage.h
index 966d7224eb1..9ad74dc0b94 100644
--- a/arch/x86/include/asm/zimage.h
+++ b/arch/x86/include/asm/zimage.h
@@ -89,4 +89,14 @@  void zimage_dump(struct boot_params *base_ptr);
 int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size,
 		ulong base, char *cmdline);
 
+/*
+ * zimage_get_kernel_version() - Get the version string from a kernel
+ *
+ * @params: boot_params pointer
+ * @kernel_base: base address of kernel
+ * Return: Kernel version as a NUL-terminated string
+ */
+const char *zimage_get_kernel_version(struct boot_params *params,
+				      void *kernel_base);
+
 #endif
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 540d4d888bc..062e3d3e315 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -181,7 +181,7 @@  static int setup_device_tree(struct setup_header *hdr, const void *fdt_blob)
 	return 0;
 }
 
-static const char *get_kernel_version(struct boot_params *params,
+const char *zimage_get_kernel_version(struct boot_params *params,
 				      void *kernel_base)
 {
 	struct setup_header *hdr = &params->hdr;
@@ -189,10 +189,14 @@  static const char *get_kernel_version(struct boot_params *params,
 	const char *s, *end;
 
 	bootproto = get_boot_protocol(hdr, false);
+	log_debug("bootproto %x, hdr->setup_sects %x\n", bootproto,
+		  hdr->setup_sects);
 	if (bootproto < 0x0200 || hdr->setup_sects < 15)
 		return NULL;
 
 	/* sanity-check the kernel version in case it is missing */
+	log_debug("hdr->kernel_version %x, str at %p\n", hdr->kernel_version,
+		  kernel_base + hdr->kernel_version + 0x200);
 	for (s = kernel_base + hdr->kernel_version + 0x200, end = s + 0x100; *s;
 	     s++) {
 		if (!isprint(*s))
@@ -239,7 +243,7 @@  struct boot_params *load_zimage(char *image, unsigned long kernel_size,
 	log_debug("Using boot protocol version %x.%02x\n",
 		  (bootproto & 0xff00) >> 8, bootproto & 0xff);
 
-	version = get_kernel_version(params, image);
+	version = zimage_get_kernel_version(params, image);
 	if (version)
 		printf("Linux kernel version %s\n", version);
 	else
@@ -728,7 +732,8 @@  void zimage_dump(struct boot_params *base_ptr)
 	print_num("Real mode switch", hdr->realmode_swtch);
 	print_num("Start sys seg", hdr->start_sys_seg);
 	print_num("Kernel version", hdr->kernel_version);
-	version = get_kernel_version(base_ptr, (void *)state.bzimage_addr);
+	version = zimage_get_kernel_version(base_ptr,
+					    (void *)state.bzimage_addr);
 	if (version)
 		printf("   @%p: %s\n", version, version);
 	print_num("Type of loader", hdr->type_of_loader);