All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] ARM: read kernel size from zImage
@ 2017-10-23 10:08 Russell King
  2017-11-01  8:10 ` Simon Horman
  0 siblings, 1 reply; 3+ messages in thread
From: Russell King @ 2017-10-23 10:08 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec

Read the new extension data which tells the boot agent about the
requirements for booting the kernel image, such as how much RAM
will be consumed by the kernel through decompression and booting.
This is necessary to control the placement of the DTB and
compressed RAM disk to avoid these objects being corrupted.

Tested-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Russell King <rmk@armlinux.org.uk>
---
 kexec/arch/arm/kexec-zImage-arm.c | 51 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/kexec/arch/arm/kexec-zImage-arm.c b/kexec/arch/arm/kexec-zImage-arm.c
index c6ecb04..a8c40cb 100644
--- a/kexec/arch/arm/kexec-zImage-arm.c
+++ b/kexec/arch/arm/kexec-zImage-arm.c
@@ -34,6 +34,15 @@ struct zimage_header {
 #define ZIMAGE_MAGIC cpu_to_le32(0x016f2818)
 	uint32_t start;
 	uint32_t end;
+	uint32_t endian;
+
+	/* Extension to the data passed to the boot agent.  The offset
+	 * points at a tagged table following a similar format to the
+	 * ATAGs.
+	 */
+	uint32_t magic2;
+#define ZIMAGE_MAGIC2 (0x45454545)
+	uint32_t extension_tag_offset;
 };
 
 struct android_image {
@@ -114,6 +123,17 @@ struct tag {
 #define byte_size(t)    ((t)->hdr.size << 2)
 #define tag_size(type)  ((sizeof(struct tag_header) + sizeof(struct type) + 3) >> 2)
 
+struct zimage_tag {
+	struct tag_header hdr;
+	union {
+#define ZIMAGE_TAG_KRNL_SIZE cpu_to_le32(0x5a534c4b)
+		struct zimage_krnl_size {
+			uint32_t size_ptr;
+			uint32_t bss_size;
+		} krnl_size;
+	} u;
+};
+
 int zImage_arm_probe(const char *UNUSED(buf), off_t UNUSED(len))
 {
 	/* 
@@ -434,7 +454,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 	if (dtb_file)
 		dtb_buf = slurp_file(dtb_file, &dtb_length);
 
-	if (len > 0x34) {
+	if (len > sizeof(struct zimage_header)) {
 		const struct zimage_header *hdr;
 		off_t size;
 
@@ -460,6 +480,35 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 			if (size < len)
 				len = size;
 		}
+
+		/* Do we have an extension table? */
+		if (hdr->magic2 == ZIMAGE_MAGIC2 && !kexec_arm_image_size) {
+			uint32_t offset = hdr->extension_tag_offset;
+			uint32_t max = len - sizeof(struct tag_header);
+			struct zimage_tag *tag;
+
+			dbgprintf("zImage has tags\n");
+
+			for (offset = hdr->extension_tag_offset;
+			     (tag = (void *)(buf + offset)) != NULL &&
+			     offset < max && byte_size(tag) &&
+				offset + byte_size(tag) < len;
+			     offset += byte_size(tag)) {
+				dbgprintf("  offset 0x%08x tag 0x%08x size %u\n",
+					  offset, tag->hdr.tag, byte_size(tag));
+				if (tag->hdr.tag == ZIMAGE_TAG_KRNL_SIZE) {
+					uint32_t *p = (void *)buf +
+						tag->u.krnl_size.size_ptr;
+
+					kexec_arm_image_size =
+						get_unaligned(p) +
+						tag->u.krnl_size.bss_size;
+				}
+			}
+
+			dbgprintf("kernel image size: 0x%08x\n",
+				  kexec_arm_image_size);
+		}
 	}
 
 	/* Handle android images, 2048 is the minimum page size */
-- 
2.7.4


-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up
According to speedtest.net: 8.21Mbps down 510kbps up

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] ARM: read kernel size from zImage
  2017-10-23 10:08 [PATCH 2/2] ARM: read kernel size from zImage Russell King
@ 2017-11-01  8:10 ` Simon Horman
  2017-11-01 10:56   ` Russell King
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Horman @ 2017-11-01  8:10 UTC (permalink / raw)
  To: Russell King; +Cc: kexec

On Mon, Oct 23, 2017 at 11:08:34AM +0100, Russell King wrote:
> Read the new extension data which tells the boot agent about the
> requirements for booting the kernel image, such as how much RAM
> will be consumed by the kernel through decompression and booting.
> This is necessary to control the placement of the DTB and
> compressed RAM disk to avoid these objects being corrupted.
> 
> Tested-by: Tony Lindgren <tony@atomide.com>
> Signed-off-by: Russell King <rmk@armlinux.org.uk>

Thanks, applied.

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] ARM: read kernel size from zImage
  2017-11-01  8:10 ` Simon Horman
@ 2017-11-01 10:56   ` Russell King
  0 siblings, 0 replies; 3+ messages in thread
From: Russell King @ 2017-11-01 10:56 UTC (permalink / raw)
  To: Simon Horman, Daniel Kiper; +Cc: kexec

On Wed, Nov 01, 2017 at 09:10:36AM +0100, Simon Horman wrote:
> On Mon, Oct 23, 2017 at 11:08:34AM +0100, Russell King wrote:
> > Read the new extension data which tells the boot agent about the
> > requirements for booting the kernel image, such as how much RAM
> > will be consumed by the kernel through decompression and booting.
> > This is necessary to control the placement of the DTB and
> > compressed RAM disk to avoid these objects being corrupted.
> > 
> > Tested-by: Tony Lindgren <tony@atomide.com>
> > Signed-off-by: Russell King <rmk@armlinux.org.uk>
> 
> Thanks, applied.

Thanks, since I rebased my tree, I've realised that wasn't quite the
patch I intended, but it'll do for now.

Building the latest tree gives me a new warning:

gcc -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes -I./include -I./util_lib/include -Iinclude/ -I./kexec/libfdt -D_FILE_OFFSET_BITS=64 -I./kexec/arch/arm/include  -c -MD -o kexec/kexec.o kexec/kexec.c
kexec/kexec.c: In function ■print_crashkernel_region_size■:
kexec/kexec.c:1232:9: warning: format ■%lu■ expects argument of type ■long unsigned int■, but argument 2 has type ■uint64_t {aka long long unsigned int}■ [-Wformat=]
  printf("%lu\n", (start != end) ? (end - start + 1) : 0UL);
         ^

caused by:

commit 76b31203222a9833f424e98a134603c2f840c82b
Author: Daniel Kiper <daniel.kiper@oracle.com>
Date:   Fri Feb 17 16:47:25 2017 -0600

    kexec: Add option to get crash kernel region size

On 32-bit architectures, "%lu" expects an unsigned long, but uint64_t is
an unsigned long long.  On 64-bit architectures, "%lu" also expects an
unsigned long, but uint64_t is unsigned long, so there's no warning.

The problem for ARM here is that a 64-bit value is passed as an
even-odd register pair, so for the above printf, that would be r2, r3.
However, "%lu" will expect the value in the first register following
the format pointer, that being r1.  So we end up printing garbage here.

Either we use "%llu" and cast the value to an unsigned long long
(needlessly widening on 64-bit arches), or "%lu" and cast to unsigned
long (truncating) or we need a definition of the format to be used for
uint64_t types (tends to be messy.)

-- 
Russell King

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-01 10:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-23 10:08 [PATCH 2/2] ARM: read kernel size from zImage Russell King
2017-11-01  8:10 ` Simon Horman
2017-11-01 10:56   ` Russell King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.