diff mbox series

[2/4] bootm: Move arm64-image processing later

Message ID 20231105130351.2.Ie34b75c75347a1c04bffa780220afe9011b0e2bb@changeid
State Changes Requested
Delegated to: Tom Rini
Headers show
Series bootm: Handle compressed arm64 images with bootm | expand

Commit Message

Simon Glass Nov. 5, 2023, 8:03 p.m. UTC
If the image is compressed, then the existing check fails, since the
header is wrong.

Move the check later in the boot process, after the kernel is
decompressed. This allows use of bootm with compressed kernels, while
still permitting an uncompressed kernel to be used.

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

 boot/bootm.c | 51 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 21 deletions(-)

Comments

Tom Rini Nov. 5, 2023, 9:20 p.m. UTC | #1
On Sun, Nov 05, 2023 at 01:03:52PM -0700, Simon Glass wrote:

> If the image is compressed, then the existing check fails, since the
> header is wrong.
> 
> Move the check later in the boot process, after the kernel is
> decompressed. This allows use of bootm with compressed kernels, while
> still permitting an uncompressed kernel to be used.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

How are we getting in to this case exactly?
Simon Glass Nov. 6, 2023, 5:25 p.m. UTC | #2
Hi Tom,

On Sun, 5 Nov 2023 at 14:20, Tom Rini <trini@konsulko.com> wrote:
>
> On Sun, Nov 05, 2023 at 01:03:52PM -0700, Simon Glass wrote:
>
> > If the image is compressed, then the existing check fails, since the
> > header is wrong.
> >
> > Move the check later in the boot process, after the kernel is
> > decompressed. This allows use of bootm with compressed kernels, while
> > still permitting an uncompressed kernel to be used.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
>
> How are we getting in to this case exactly?

By using a compressed ARM64 image, e.g. Image.gz

Regards,
Simon
diff mbox series

Patch

diff --git a/boot/bootm.c b/boot/bootm.c
index 7583be5a4515..8c35afb09937 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -245,27 +245,6 @@  static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc,
 		return 1;
 	}
 
-	if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
-		if (IS_ENABLED(CONFIG_CMD_BOOTI) &&
-		    images.os.arch == IH_ARCH_ARM64 &&
-		    images.os.os == IH_OS_LINUX) {
-			ulong image_addr;
-			ulong image_size;
-
-			ret = booti_setup(images.os.image_start, &image_addr,
-					  &image_size, true);
-			if (ret != 0)
-				return 1;
-
-			images.os.type = IH_TYPE_KERNEL;
-			images.os.load = image_addr;
-			images.ep = image_addr;
-		} else {
-			images.os.load = images.os.image_start;
-			images.ep += images.os.image_start;
-		}
-	}
-
 	images.os.start = map_to_sysmem(os_hdr);
 
 	return 0;
@@ -472,6 +451,36 @@  static int bootm_load_os(struct bootm_headers *images, int boot_progress)
 		}
 	}
 
+	if (IS_ENABLED(CONFIG_CMD_BOOTI) &&
+	    images->os.type == IH_TYPE_KERNEL_NOLOAD &&
+	    images->os.arch == IH_ARCH_ARM64 &&
+	    images->os.os == IH_OS_LINUX) {
+		ulong relocated_addr;
+		ulong image_size;
+		int ret;
+
+		ret = booti_setup(load, &relocated_addr, &image_size,
+				  false);
+		if (ret) {
+			printf("Failed to prep arm64 kernel (err=%d)\n",
+			       ret);
+			return BOOTM_ERR_RESET;
+		}
+
+		/* Handle BOOTM_STATE_LOADOS */
+		if (relocated_addr != load) {
+			printf("Moving Image from 0x%lx to 0x%lx, end=%lx\n",
+			       load,
+				relocated_addr, relocated_addr + image_size);
+			memmove((void *)relocated_addr,
+				load_buf, image_size);
+		}
+
+		images->ep = relocated_addr;
+		images->os.start = relocated_addr;
+		images->os.end = relocated_addr + image_size;
+	}
+
 	lmb_reserve(&images->lmb, images->os.load, (load_end -
 						    images->os.load));
 	return 0;