diff mbox series

[11/13] x86: zboot: Separate logic functions from commands

Message ID 20231204002944.897949-11-sjg@chromium.org
State Accepted
Commit 9ad5fdf1a8a10d2c3daad33ba69cd88b7f7ea86b
Delegated to: Tom Rini
Headers show
Series Complete decoupling of zboot logic from commands | expand

Commit Message

Simon Glass Dec. 4, 2023, 12:29 a.m. UTC
Move zboot_start() and zboot_info() in with the other logic functions.

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

 arch/x86/include/asm/zimage.h | 25 +++++++++++++++++++++++++
 arch/x86/lib/zimage.c         | 23 +++++++++++++++++++++++
 cmd/x86/zboot.c               | 32 ++++----------------------------
 3 files changed, 52 insertions(+), 28 deletions(-)

Comments

Tom Rini Dec. 9, 2023, 3:49 p.m. UTC | #1
On Sun, Dec 03, 2023 at 05:29:36PM -0700, Simon Glass wrote:

> Move zboot_start() and zboot_info() in with the other logic functions.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Tom Rini <trini@konsulko.com>
diff mbox series

Patch

diff --git a/arch/x86/include/asm/zimage.h b/arch/x86/include/asm/zimage.h
index ac6683ea9ef3..8b5426051701 100644
--- a/arch/x86/include/asm/zimage.h
+++ b/arch/x86/include/asm/zimage.h
@@ -134,4 +134,29 @@  struct boot_params *load_zimage(char *image, unsigned long kernel_size,
 int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 		 ulong initrd_addr, ulong initrd_size, ulong cmdline_force);
 
+/**
+ * zboot_start() - Prepare to boot a zimage
+ *
+ * Record information about a zimage so it can be booted
+ *
+ * @bzimage_addr: Address of the bzImage to boot
+ * @bzimage_size: Size of the bzImage, or 0 to detect this
+ * @initrd_addr: Address of the initial ramdisk, or 0 if none
+ * @initrd_size: Size of the initial ramdisk, or 0 if none
+ * @base_addr: If non-zero, this indicates that the boot parameters have already
+ *	been loaded by the caller to this address, so the load_zimage() call
+ *	in zboot_load() will be skipped when booting
+ * @cmdline: Environment variable containing the 'override' command line, or
+ *	NULL to use the one in the setup block
+ */
+void zboot_start(ulong bzimage_addr, ulong bzimage_size, ulong initrd_addr,
+		 ulong initrd_size, ulong base_addr, const char *cmdline);
+
+/**
+ * zboot_info() - Show simple info about a zimage
+ *
+ * Shows wherer the kernel was loaded and also the setup base
+ */
+void zboot_info(void);
+
 #endif
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index e8a1849947e6..f2d4f3b50162 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -652,3 +652,26 @@  void zimage_dump(struct boot_params *base_ptr, bool show_cmdline)
 	if (get_boot_protocol(hdr, false) >= 0x215)
 		print_num("Kernel info offset", hdr->kernel_info_offset);
 }
+
+void zboot_start(ulong bzimage_addr, ulong bzimage_size, ulong initrd_addr,
+		 ulong initrd_size, ulong base_addr, const char *cmdline)
+{
+	memset(&state, '\0', sizeof(state));
+
+	state.bzimage_size = bzimage_size;
+	state.initrd_addr = initrd_addr;
+	state.initrd_size = initrd_size;
+	if (base_addr) {
+		state.base_ptr = map_sysmem(base_addr, 0);
+		state.load_address = bzimage_addr;
+	} else {
+		state.bzimage_addr = bzimage_addr;
+	}
+	state.cmdline = cmdline;
+}
+
+void zboot_info(void)
+{
+	printf("Kernel loaded at %08lx, setup_base=%p\n",
+	       state.load_address, state.base_ptr);
+}
diff --git a/cmd/x86/zboot.c b/cmd/x86/zboot.c
index 572b58a5537d..addf28cb4aae 100644
--- a/cmd/x86/zboot.c
+++ b/cmd/x86/zboot.c
@@ -10,26 +10,6 @@ 
 #include <vsprintf.h>
 #include <asm/zimage.h>
 
-static int zboot_start(ulong bzimage_addr, ulong bzimage_size,
-		       ulong initrd_addr, ulong initrd_size, ulong base_addr,
-		       const char *cmdline)
-{
-	memset(&state, '\0', sizeof(state));
-
-	state.bzimage_size = bzimage_size;
-	state.initrd_addr = initrd_addr;
-	state.initrd_size = initrd_size;
-	if (base_addr) {
-		state.base_ptr = map_sysmem(base_addr, 0);
-		state.load_address = bzimage_addr;
-	} else {
-		state.bzimage_addr = bzimage_addr;
-	}
-	state.cmdline = cmdline;
-
-	return 0;
-}
-
 static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 			  char *const argv[])
 {
@@ -47,8 +27,10 @@  static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 	base_addr = argc > 5 ? hextoul(argv[5], NULL) : 0;
 	cmdline = argc > 6 ? env_get(argv[6]) : NULL;
 
-	return zboot_start(bzimage_addr, bzimage_size, initrd_addr, initrd_size,
-			   base_addr, cmdline);
+	zboot_start(bzimage_addr, bzimage_size, initrd_addr, initrd_size,
+		    base_addr, cmdline);
+
+	return 0;
 }
 
 static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -81,12 +63,6 @@  static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static void zboot_info(void)
-{
-	printf("Kernel loaded at %08lx, setup_base=%p\n",
-	       state.load_address, state.base_ptr);
-}
-
 static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
 			 char *const argv[])
 {