Revert "Merge patch series "pxe: Precursor series for supporting read_all() in extlinux / PXE""

This reverts commit 8bc3542384e3a1219e5ffb62b79d16dddc1b1fb9, reversing
changes made to 698edd63eca090a2e299cd3facf90a0b97bed677.

There are still problems with this series to work out.

Link: https://lore.kernel.org/u-boot/CAFLszTjw_MJbK9tpzVYi3XKGazcv55auBAdgVzcAVUta7dRqcg@mail.gmail.com/
Signed-off-by: Tom Rini <trini@konsulko.com>
diff --git a/arch/arm/lib/image.c b/arch/arm/lib/image.c
index d78d704..1f672ee 100644
--- a/arch/arm/lib/image.c
+++ b/arch/arm/lib/image.c
@@ -28,13 +28,6 @@
 	uint32_t	res5;
 };
 
-bool booti_is_valid(const void *img)
-{
-	const struct Image_header *ih = img;
-
-	return ih->magic == le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC);
-}
-
 int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
 		bool force_reloc)
 {
@@ -46,7 +39,7 @@
 
 	ih = (struct Image_header *)map_sysmem(image, 0);
 
-	if (!booti_is_valid(ih)) {
+	if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) {
 		puts("Bad Linux ARM64 Image magic!\n");
 		return 1;
 	}
diff --git a/arch/riscv/lib/image.c b/arch/riscv/lib/image.c
index 859326c..a82f48e 100644
--- a/arch/riscv/lib/image.c
+++ b/arch/riscv/lib/image.c
@@ -32,13 +32,6 @@
 	uint32_t	res4;		/* reserved */
 };
 
-bool booti_is_valid(const void *img)
-{
-	const struct linux_image_h *lhdr = img;
-
-	return lhdr->magic == LINUX_RISCV_IMAGE_MAGIC;
-}
-
 int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
 		bool force_reloc)
 {
@@ -46,7 +39,7 @@
 
 	lhdr = (struct linux_image_h *)map_sysmem(image, 0);
 
-	if (!booti_is_valid(lhdr)) {
+	if (lhdr->magic != LINUX_RISCV_IMAGE_MAGIC) {
 		puts("Bad Linux RISCV Image magic!\n");
 		return -EINVAL;
 	}
diff --git a/arch/sandbox/lib/bootm.c b/arch/sandbox/lib/bootm.c
index 8ed9237..44ba8b5 100644
--- a/arch/sandbox/lib/bootm.c
+++ b/arch/sandbox/lib/bootm.c
@@ -89,8 +89,3 @@
 
 	return 1;
 }
-
-bool booti_is_valid(const void *img)
-{
-	return false;
-}
diff --git a/arch/x86/include/asm/zimage.h b/arch/x86/include/asm/zimage.h
index 4ed6d8d..8b54260 100644
--- a/arch/x86/include/asm/zimage.h
+++ b/arch/x86/include/asm/zimage.h
@@ -10,8 +10,6 @@
 #include <asm/bootparam.h>
 #include <asm/e820.h>
 
-struct bootm_info;
-
 /* linux i386 zImage/bzImage header. Offsets relative to
  * the start of the image */
 
@@ -44,28 +42,65 @@
 	ZBOOT_STATE_COUNT	= 5,
 };
 
+/**
+ * struct zboot_state - Current state of the boot
+ *
+ * @bzimage_addr: Address of the bzImage to boot, or 0 if the image has already
+ *	been loaded and does not exist (as a cohesive whole) in memory
+ * @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
+ * @load_address: Address where the bzImage is moved before booting, either
+ *	BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
+ *	This is set up when loading the zimage
+ * @base_ptr: Pointer to the boot parameters, typically at address
+ *	DEFAULT_SETUP_BASE
+ *	This is set up when loading the zimage
+ * @cmdline: Environment variable containing the 'override' command line, or
+ *	NULL to use the one in the setup block
+ */
+struct zboot_state {
+	ulong bzimage_addr;
+	ulong bzimage_size;
+	ulong initrd_addr;
+	ulong initrd_size;
+	ulong load_address;
+	struct boot_params *base_ptr;
+	const char *cmdline;
+};
+
+extern struct zboot_state state;
+
 /**
+ * zimage_dump() - Dump information about a zimage
+ *
+ * @base_ptr: Pointer to the boot parameters
+ * @show_cmdline: true to show the kernel command line
+ */
+void zimage_dump(struct boot_params *base_ptr, bool show_cmdline);
+
+/**
  * zboot_load() - Load a zimage
  *
  * Load the zimage into the correct place
  *
  * Return: 0 if OK, -ve on error
  */
-int zboot_load(struct bootm_info *bmi);
+int zboot_load(void);
 
 /**
  * zboot_setup() - Set up the zboot image reeady for booting
  *
  * Return: 0 if OK, -ve on error
  */
-int zboot_setup(struct bootm_info *bmi);
+int zboot_setup(void);
 
 /**
  * zboot_go() - Start the image
  *
  * Return: 0 if OK, -ve on error
  */
-int zboot_go(struct bootm_info *bmi);
+int zboot_go(void);
 
 /**
  * load_zimage() - Load a zImage or bzImage
@@ -104,7 +139,6 @@
  *
  * Record information about a zimage so it can be booted
  *
- * @bmi: Bootm information
  * @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
@@ -115,17 +149,14 @@
  * @cmdline: Environment variable containing the 'override' command line, or
  *	NULL to use the one in the setup block
  */
-void zboot_start(struct bootm_info *bmi, ulong bzimage_addr, ulong bzimage_size,
-		 ulong initrd_addr, ulong initrd_size, ulong base_addr,
-		 const char *cmdline);
+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 where the kernel was loaded and also the setup base
- *
- * @bmi: Bootm information
+ * Shows wherer the kernel was loaded and also the setup base
  */
-void zboot_info(struct bootm_info *bmi);
+void zboot_info(void);
 
 #endif
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 8f1c18e..2ea9bcf 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -55,6 +55,9 @@
 
 #define COMMAND_LINE_SIZE	2048
 
+/* Current state of the boot */
+struct zboot_state state;
+
 static void build_command_line(char *command_line, int auto_boot)
 {
 	char *env_command_line;
@@ -366,54 +369,54 @@
 	return 0;
 }
 
-int zboot_load(struct bootm_info *bmi)
+int zboot_load(void)
 {
 	struct boot_params *base_ptr;
 	int ret;
 
-	if (bmi->base_ptr) {
-		struct boot_params *from = (struct boot_params *)bmi->base_ptr;
+	if (state.base_ptr) {
+		struct boot_params *from = (struct boot_params *)state.base_ptr;
 
 		base_ptr = (struct boot_params *)DEFAULT_SETUP_BASE;
 		log_debug("Building boot_params at %lx\n", (ulong)base_ptr);
 		memset(base_ptr, '\0', sizeof(*base_ptr));
 		base_ptr->hdr = from->hdr;
 	} else {
-		base_ptr = load_zimage((void *)bmi->bzimage_addr,
-				       bmi->bzimage_size, &bmi->load_address);
+		base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size,
+				       &state.load_address);
 		if (!base_ptr) {
 			puts("## Kernel loading failed ...\n");
 			return -EINVAL;
 		}
 	}
-	bmi->base_ptr = base_ptr;
+	state.base_ptr = base_ptr;
 
-	ret = env_set_hex("zbootbase", map_to_sysmem(bmi->base_ptr));
+	ret = env_set_hex("zbootbase", map_to_sysmem(state.base_ptr));
 	if (!ret)
-		ret = env_set_hex("zbootaddr", bmi->load_address);
+		ret = env_set_hex("zbootaddr", state.load_address);
 	if (ret)
 		return ret;
 
 	return 0;
 }
 
-int zboot_setup(struct bootm_info *bmi)
+int zboot_setup(void)
 {
-	struct boot_params *base_ptr = bmi->base_ptr;
+	struct boot_params *base_ptr = state.base_ptr;
 	int ret;
 
 	ret = setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
-			   0, bmi->initrd_addr, bmi->initrd_size,
-			   (ulong)bmi->cmdline);
+			   0, state.initrd_addr, state.initrd_size,
+			   (ulong)state.cmdline);
 	if (ret)
 		return -EINVAL;
 
 	return 0;
 }
 
-int zboot_go(struct bootm_info *bmi)
+int zboot_go(void)
 {
-	struct boot_params *params = bmi->base_ptr;
+	struct boot_params *params = state.base_ptr;
 	struct setup_header *hdr = &params->hdr;
 	bool image_64bit;
 	ulong entry;
@@ -421,7 +424,7 @@
 
 	disable_interrupts();
 
-	entry = bmi->load_address;
+	entry = state.load_address;
 	image_64bit = false;
 	if (IS_ENABLED(CONFIG_X86_64) &&
 	    (hdr->xloadflags & XLF_KERNEL_64)) {
@@ -429,43 +432,30 @@
 	}
 
 	/* we assume that the kernel is in place */
-	ret = boot_linux_kernel((ulong)bmi->base_ptr, entry, image_64bit);
+	ret = boot_linux_kernel((ulong)state.base_ptr, entry, image_64bit);
 
 	return ret;
 }
 
-int zboot_run(struct bootm_info *bmi)
+int zboot_run(ulong addr, ulong size, ulong initrd, ulong initrd_size,
+	      ulong base, char *cmdline)
 {
 	int ret;
 
-	ret = zboot_load(bmi);
+	zboot_start(addr, size, initrd, initrd_size, base, cmdline);
+	ret = zboot_load();
 	if (ret)
 		return log_msg_ret("ld", ret);
-	ret = zboot_setup(bmi);
+	ret = zboot_setup();
 	if (ret)
 		return log_msg_ret("set", ret);
-	ret = zboot_go(bmi);
+	ret = zboot_go();
 	if (ret)
 		return log_msg_ret("go", ret);
 
 	return -EFAULT;
 }
 
-int zboot_run_args(ulong addr, ulong size, ulong initrd, ulong initrd_size,
-		   ulong base, char *cmdline)
-{
-	struct bootm_info bmi;
-	int ret;
-
-	bootm_init(&bmi);
-	zboot_start(&bmi, addr, size, initrd, initrd_size, base, cmdline);
-	ret = zboot_run(&bmi);
-	if (ret)
-		return log_msg_ret("zra", ret);
-
-	return 0;
-}
-
 static void print_num(const char *name, ulong value)
 {
 	printf("%-20s: %lx\n", name, value);
@@ -559,12 +549,11 @@
 	printf("\n");
 }
 
-void zimage_dump(struct bootm_info *bmi, bool show_cmdline)
+void zimage_dump(struct boot_params *base_ptr, bool show_cmdline)
 {
-	struct boot_params *base_ptr;
 	struct setup_header *hdr;
+	const char *version;
 
-	base_ptr = bmi->base_ptr;
 	printf("Setup located at %p:\n\n", base_ptr);
 	print_num64("ACPI RSDP addr", base_ptr->acpi_rsdp_addr);
 
@@ -590,14 +579,10 @@
 	print_num("Real mode switch", hdr->realmode_swtch);
 	print_num("Start sys seg", hdr->start_sys_seg);
 	print_num("Kernel version", hdr->kernel_version);
-	if (bmi->bzimage_addr) {
-		const char *version;
-
-		version = zimage_get_kernel_version(base_ptr,
-						    (void *)bmi->bzimage_addr);
-		if (version)
-			printf("   @%p: %s\n", version, version);
-	}
+	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);
 	show_loader(hdr);
 	print_num("Load flags", hdr->loadflags);
@@ -638,24 +623,25 @@
 		print_num("Kernel info offset", hdr->kernel_info_offset);
 }
 
-void zboot_start(struct bootm_info *bmi, ulong bzimage_addr, ulong bzimage_size,
-		 ulong initrd_addr, ulong initrd_size, ulong base_addr,
-		 const char *cmdline)
+void zboot_start(ulong bzimage_addr, ulong bzimage_size, ulong initrd_addr,
+		 ulong initrd_size, ulong base_addr, const char *cmdline)
 {
-	bmi->bzimage_size = bzimage_size;
-	bmi->initrd_addr = initrd_addr;
-	bmi->initrd_size = initrd_size;
+	memset(&state, '\0', sizeof(state));
+
+	state.bzimage_size = bzimage_size;
+	state.initrd_addr = initrd_addr;
+	state.initrd_size = initrd_size;
 	if (base_addr) {
-		bmi->base_ptr = map_sysmem(base_addr, 0);
-		bmi->load_address = bzimage_addr;
+		state.base_ptr = map_sysmem(base_addr, 0);
+		state.load_address = bzimage_addr;
 	} else {
-		bmi->bzimage_addr = bzimage_addr;
+		state.bzimage_addr = bzimage_addr;
 	}
-	bmi->cmdline = cmdline;
+	state.cmdline = cmdline;
 }
 
-void zboot_info(struct bootm_info *bmi)
+void zboot_info(void)
 {
 	printf("Kernel loaded at %08lx, setup_base=%p\n",
-	       bmi->load_address, bmi->base_ptr);
+	       state.load_address, state.base_ptr);
 }