Skip to contentSkip to conversation

kexec: Support for uImage RAMDisks

PATCH Superseded Suzuki K. Poulose 3 participants 14 messages Jan 11, 2013 – Jan 27, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover kexec: Support for uImage RAMDisks

The following series adds support for uImage RAMDisks in kexec-tools.

The first two patches in the series modifies the common uImage handling code.

The third patch in the series adds PPC support for processing the ramdisks.

NOTE: Tested *only* on PPC. Though the other archs are not affected much, I would appreciate some help in (compile) testing these patches on ARM and SH, just to make sure we are safe there.

With these patches, one can easily add support in other archs for supporting the uImage RAMDisks.

---

Suzuki K. Poulose (3):
kexec/uImage: Return the image type for uImage_probe kexec/uImage: Recognize uImage RAM Disks ppc/uImage: Add support for RAM Disks

 kexec/arch/arm/kexec-uImage-arm.c |    8 +++++++-
 kexec/arch/ppc/kexec-uImage-ppc.c |   30 ++++++++++++++++++++++++++++--
 kexec/arch/sh/kexec-uImage-sh.c   |    9 ++++++++-
 kexec/kexec-uImage.c              |   18 ++++++++++++------
 4 files changed, 55 insertions(+), 10 deletions(-)
Signature · 7 lines
Suzuki


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

PATCH 1/3 kexec/uImage: Return the image type for uImage_probe

From: Suzuki K. Poulose <[email protected]>

uImage supports different types of payloads, including kernel, ramdisks etc. uImage_probe() as of now checks whether the supplied payload is of type KERNEL ( i.e, IH_TYPE_KERNEL or IH_TYPE_KERNEL_NOLOAD ).

Change this behaviour to return the image type, if it is one of the supported payloads. This change is in prepartion to support ramdisks in uImage format.

Also, I have changed the code to check for the OS type only for the kernel images.

Is this check really needed ? We shouldn't bother what OS is being loaded. Isn't it ?

This change would allow the user to decide if the image is of their interest.

---
 kexec/arch/arm/kexec-uImage-arm.c |    8 +++++++-
 kexec/arch/ppc/kexec-uImage-ppc.c |    8 +++++++-
 kexec/arch/sh/kexec-uImage-sh.c   |    9 ++++++++-
 kexec/kexec-uImage.c              |   16 ++++++++++------
 4 files changed, 32 insertions(+), 9 deletions(-)
kexec/arch/arm/kexec-uImage-arm.c +7 -1
index 4875185..dc1bcb8 100644
@@ -11,7 +11,13 @@
 
 int uImage_arm_probe(const char *buf, off_t len)
 {
-	return uImage_probe(buf, len, IH_ARCH_ARM);
+	int type;
+	int rc = -1;
+
+	type = uImage_probe(buf, len, IH_ARCH_ARM);
+	if (type == IH_TYPE_KERNEL || type == IH_TYPE_KERNEL_NOLOAD)
+		rc = 0;
+	return rc;
 }
 
 int uImage_arm_load(int argc, char **argv, const char *buf, off_t len,
kexec/arch/ppc/kexec-uImage-ppc.c +7 -1
index e55bf94..eaea3c1 100644
@@ -48,7 +48,13 @@ void uImage_ppc_usage(void)
 
 int uImage_ppc_probe(const char *buf, off_t len)
 {
-	return uImage_probe(buf, len, IH_ARCH_PPC);
+	int type;
+	int rc = -1;
+
+	type = uImage_probe(buf, len, IH_ARCH_PPC);
+	if (type == IH_TYPE_KERNEL || type == IH_TYPE_KERNEL_NOLOAD)
+		rc = 0;
+	return rc;
 }
 
 static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
kexec/arch/sh/kexec-uImage-sh.c +8 -1
index e983165..54bb073 100644
@@ -13,7 +13,14 @@
 
 int uImage_sh_probe(const char *buf, off_t len)
 {
-	return uImage_probe(buf, len, IH_ARCH_SH);
+	int type;
+	int rc = -1;
+
+	type = uImage_probe(buf, len, IH_ARCH_SH);
+	if (type == IH_TYPE_KERNEL || type == IH_TYPE_KERNEL_NOLOAD)
+		rc = uImage_probe(buf, len, IH_ARCH_SH);
+
+	return rc;
 }
 
 int uImage_sh_load(int argc, char **argv, const char *buf, off_t len,
kexec/kexec-uImage.c +10 -6
index 3bc85c5..dcbd635 100644
@@ -16,6 +16,10 @@
  * Basic uImage loader. Not rocket science.
  */
 
+/*
+ * Returns the image type if everything goes well. This would
+ * allow the user to decide if the image is of their interest.
+ */
 int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch)
 {
 	struct image_header header;
@@ -42,17 +46,17 @@ int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch)
 	switch (header.ih_type) {
 	case IH_TYPE_KERNEL:
 	case IH_TYPE_KERNEL_NOLOAD:
+		/* XXX: Should we really check this ? */
+		if (header.ih_os != IH_OS_LINUX) {
+			printf("uImage os %d unsupported\n", header.ih_os);
+			return -1;
+		}
 		break;
 	default:
 		printf("uImage type %d unsupported\n", header.ih_type);
 		return -1;
 	}
 
-	if (header.ih_os != IH_OS_LINUX) {
-		printf("uImage os %d unsupported\n", header.ih_os);
-		return -1;
-	}
-
 	if (header.ih_arch != arch) {
 		printf("uImage arch %d unsupported\n", header.ih_arch);
 		return -1;
@@ -84,7 +88,7 @@ int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch)
 		return -1;
 	}
 #endif
-	return 0;
+	return (int)header.ih_type;
 }
 
 #ifdef HAVE_LIBZ

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw

Re: [PATCH 1/3] kexec/uImage: Return the image type for uImage_probe

Quoted 6 lines · * Suzuki K. Poulose | 2013-01-11 12:11:36 [+0530]:

From: Suzuki K. Poulose <[email protected]>

uImage supports different types of payloads, including kernel, ramdisks etc. uImage_probe() as of now checks whether the supplied payload is of type KERNEL ( i.e, IH_TYPE_KERNEL or IH_TYPE_KERNEL_NOLOAD ).

Quoted 6 lines

Change this behaviour to return the image type, if it is one of the supported payloads. This change is in prepartion to support ramdisks in uImage format.

Also, I have changed the code to check for the OS type only for the kernel images.

Is this check really needed ? We shouldn't bother what OS is being loaded. Isn't it ?

We should bother because mostly linux is supported. Other operating systems like NetBSD might have other ABI for the enter point or some special requirements. The entry ABI for linux comapared to WindowsCE is different for ARM just to name one example.

Quoted 53 lines

This change would allow the user to decide if the image is of their interest.

---

kexec/arch/arm/kexec-uImage-arm.c |    8 +++++++-
kexec/arch/ppc/kexec-uImage-ppc.c |    8 +++++++-
kexec/arch/sh/kexec-uImage-sh.c   |    9 ++++++++-
kexec/kexec-uImage.c              |   16 ++++++++++------
4 files changed, 32 insertions(+), 9 deletions(-)
kexec/arch/arm/kexec-uImage-arm.c +7 -1
index 4875185..dc1bcb8 100644
@@ -11,7 +11,13 @@
 
 int uImage_arm_probe(const char *buf, off_t len)
 {
-	return uImage_probe(buf, len, IH_ARCH_ARM);
+	int type;
+	int rc = -1;
+
+	type = uImage_probe(buf, len, IH_ARCH_ARM);
+	if (type == IH_TYPE_KERNEL || type == IH_TYPE_KERNEL_NOLOAD)
+		rc = 0;
+	return rc;
 }
 
 int uImage_arm_load(int argc, char **argv, const char *buf, off_t len,
kexec/arch/ppc/kexec-uImage-ppc.c +7 -1
index e55bf94..eaea3c1 100644
@@ -48,7 +48,13 @@ void uImage_ppc_usage(void)
 
 int uImage_ppc_probe(const char *buf, off_t len)
 {
-	return uImage_probe(buf, len, IH_ARCH_PPC);
+	int type;
+	int rc = -1;
+
+	type = uImage_probe(buf, len, IH_ARCH_PPC);
+	if (type == IH_TYPE_KERNEL || type == IH_TYPE_KERNEL_NOLOAD)
+		rc = 0;
+	return rc;
 }
 
 static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
kexec/arch/sh/kexec-uImage-sh.c +0 -0
index e983165..54bb073 100644

kexec/arch/sh/kexec-uImage-sh.c line 21

Quoted 10 lines
kexec/arch/sh/kexec-uImage-sh.c +6 -1
@@ -13,7 +13,14 @@
 
 int uImage_sh_probe(const char *buf, off_t len)
 {
-	return uImage_probe(buf, len, IH_ARCH_SH);
+	int type;
+	int rc = -1;
+
+	type = uImage_probe(buf, len, IH_ARCH_SH);
+	if (type == IH_TYPE_KERNEL || type == IH_TYPE_KERNEL_NOLOAD)
+		rc = uImage_probe(buf, len, IH_ARCH_SH);

This looks like a typo compared to ppc/arm above. If so you could create uImage_probe_kernel() which has the type == check.

Quoted 21 lines
kexec/arch/sh/kexec-uImage-sh.c +2 -0
+
+	return rc;
 }
 
 int uImage_sh_load(int argc, char **argv, const char *buf, off_t len,
kexec/kexec-uImage.c +4 -0
index 3bc85c5..dcbd635 100644
@@ -16,6 +16,10 @@
 * Basic uImage loader. Not rocket science.
 */
 
+/*
+ * Returns the image type if everything goes well. This would
+ * allow the user to decide if the image is of their interest.
+ */
 int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch)
 {
 	struct image_header header;

kexec/kexec-uImage.c int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch) · line 49

Quoted 4 lines
kexec/kexec-uImage.c +1 -0
@@ -42,17 +46,17 @@ int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch)
 	switch (header.ih_type) {
 	case IH_TYPE_KERNEL:
 	case IH_TYPE_KERNEL_NOLOAD:
+		/* XXX: Should we really check this ? */

Yes.

kexec/kexec-uImage.c int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch) · line 53

Quoted 4 lines
kexec/kexec-uImage.c +4 -0
+		if (header.ih_os != IH_OS_LINUX) {
+			printf("uImage os %d unsupported\n", header.ih_os);
+			return -1;
+		}

Why did move this piece. Is it because ramdisk does not have an OS selected?

Quoted 15 lines
kexec/kexec-uImage.c +0 -5
 		break;
 	default:
 		printf("uImage type %d unsupported\n", header.ih_type);
 		return -1;
 	}
 
-	if (header.ih_os != IH_OS_LINUX) {
-		printf("uImage os %d unsupported\n", header.ih_os);
-		return -1;
-	}
-
 	if (header.ih_arch != arch) {
 		printf("uImage arch %d unsupported\n", header.ih_arch);
 		return -1;

kexec/kexec-uImage.c int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch) · line 91

Quoted 5 lines
kexec/kexec-uImage.c +1 -1
@@ -84,7 +88,7 @@ int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch)
 		return -1;
 	}
 #endif
-	return 0;
+	return (int)header.ih_type;

Why do you return type here?

kexec/kexec-uImage.c int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch) · line 94

Quoted 4 lines
kexec/kexec-uImage.c +0 -0
 }
 
 #ifdef HAVE_LIBZ

Sebastian

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw

Re: [PATCH 1/3] kexec/uImage: Return the image type for uImage_probe

Quoted 11 lines · Sebastian Andrzej Siewior
Quoted 9 lines · * Suzuki K. Poulose | 2013-01-11 12:11:36 [+0530]:

From: Suzuki K. Poulose <[email protected]>

uImage supports different types of payloads, including kernel, ramdisks etc. uImage_probe() as of now checks whether the supplied payload is of type KERNEL ( i.e, IH_TYPE_KERNEL or IH_TYPE_KERNEL_NOLOAD ).

Change this behaviour to return the image type, if it is one of the supported payloads. This change is in prepartion to support ramdisks in uImage format.

Quoted 9 lines
Quoted 3 lines

Also, I have changed the code to check for the OS type only for the kernel images.

Is this check really needed ? We shouldn't bother what OS is being loaded. Isn't it ?

We should bother because mostly linux is supported. Other operating systems like NetBSD might have other ABI for the enter point or some special requirements. The entry ABI for linux comapared to WindowsCE is different for ARM just to name one example.

Ok. Makes sense now. Thanks for the clarification.

Quoted 54 lines
Quoted 54 lines

This change would allow the user to decide if the image is of their interest.

---

kexec/arch/arm/kexec-uImage-arm.c |    8 +++++++-
kexec/arch/ppc/kexec-uImage-ppc.c |    8 +++++++-
kexec/arch/sh/kexec-uImage-sh.c   |    9 ++++++++-
kexec/kexec-uImage.c              |   16 ++++++++++------
4 files changed, 32 insertions(+), 9 deletions(-)
kexec/arch/arm/kexec-uImage-arm.c +7 -1
index 4875185..dc1bcb8 100644
@@ -11,7 +11,13 @@
 
 int uImage_arm_probe(const char *buf, off_t len)
 {
-	return uImage_probe(buf, len, IH_ARCH_ARM);
+	int type;
+	int rc = -1;
+
+	type = uImage_probe(buf, len, IH_ARCH_ARM);
+	if (type == IH_TYPE_KERNEL || type == IH_TYPE_KERNEL_NOLOAD)
+		rc = 0;
+	return rc;
 }
 
 int uImage_arm_load(int argc, char **argv, const char *buf, off_t len,
kexec/arch/ppc/kexec-uImage-ppc.c +7 -1
index e55bf94..eaea3c1 100644
@@ -48,7 +48,13 @@ void uImage_ppc_usage(void)
 
 int uImage_ppc_probe(const char *buf, off_t len)
 {
-	return uImage_probe(buf, len, IH_ARCH_PPC);
+	int type;
+	int rc = -1;
+
+	type = uImage_probe(buf, len, IH_ARCH_PPC);
+	if (type == IH_TYPE_KERNEL || type == IH_TYPE_KERNEL_NOLOAD)
+		rc = 0;
+	return rc;
 }
 
 static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
kexec/arch/sh/kexec-uImage-sh.c +0 -0
index e983165..54bb073 100644
@@ -13,7 +13,14 @@
 
Quoted 13 lines

kexec/arch/sh/kexec-uImage-sh.c line 21

Quoted 9 lines
kexec/arch/sh/kexec-uImage-sh.c +6 -1
 int uImage_sh_probe(const char *buf, off_t len)
 {
-	return uImage_probe(buf, len, IH_ARCH_SH);
+	int type;
+	int rc = -1;
+
+	type = uImage_probe(buf, len, IH_ARCH_SH);
+	if (type == IH_TYPE_KERNEL || type == IH_TYPE_KERNEL_NOLOAD)
+		rc = uImage_probe(buf, len, IH_ARCH_SH);

This looks like a typo compared to ppc/arm above. If so you could create uImage_probe_kernel() which has the type == check.

Yes, indeed. Thanks for catching that. Will fix that. It should have been :

	rc = 0;
Quoted 26 lines
Quoted 21 lines
kexec/arch/sh/kexec-uImage-sh.c +2 -0
+
+	return rc;
 }
 
 int uImage_sh_load(int argc, char **argv, const char *buf, off_t len,
kexec/kexec-uImage.c +4 -0
index 3bc85c5..dcbd635 100644
@@ -16,6 +16,10 @@
  * Basic uImage loader. Not rocket science.
  */
 
+/*
+ * Returns the image type if everything goes well. This would
+ * allow the user to decide if the image is of their interest.
+ */
 int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch)
 {
 	struct image_header header;

kexec/kexec-uImage.c int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch) · line 49

Quoted 4 lines
kexec/kexec-uImage.c +1 -0
@@ -42,17 +46,17 @@ int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch)
 	switch (header.ih_type) {
 	case IH_TYPE_KERNEL:
 	case IH_TYPE_KERNEL_NOLOAD:
+		/* XXX: Should we really check this ? */

Yes.

Quoted 8 lines

kexec/kexec-uImage.c int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch) · line 53

Quoted 4 lines
kexec/kexec-uImage.c +4 -0
+		if (header.ih_os != IH_OS_LINUX) {
+			printf("uImage os %d unsupported\n", header.ih_os);
+			return -1;
+		}

Why did move this piece. Is it because ramdisk does not have an OS selected?

To be frank, I don't know. Is it otherwise ?

Quoted 6 lines
Quoted 6 lines
kexec/kexec-uImage.c +0 -0
 		break;
 	default:
 		printf("uImage type %d unsupported\n", header.ih_type);
 		return -1;
 	}
 
Quoted 17 lines
Quoted 9 lines
kexec/kexec-uImage.c +0 -5
-	if (header.ih_os != IH_OS_LINUX) {
-		printf("uImage os %d unsupported\n", header.ih_os);
-		return -1;
-	}
-
 	if (header.ih_arch != arch) {
 		printf("uImage arch %d unsupported\n", header.ih_arch);
 		return -1;

kexec/kexec-uImage.c int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch) · line 91

Quoted 5 lines
kexec/kexec-uImage.c +1 -1
@@ -84,7 +88,7 @@ int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch)
 		return -1;
 	}
 #endif
-	return 0;
+	return (int)header.ih_type;

Why do you return type here?

This will help the caller to decide if the target is of his interest, and deal with it. This will be used in the later patches in the series to check for a RAMDISK type. See patch 2/3 and 3/3.

Thanks
Suzuki

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw

PATCH 2/3 kexec/uImage: Recognize uImage RAM Disks

In reply to Suzuki K. Poulose

From: Suzuki K. Poulose <[email protected]>

Add IH_TYPE_RAMDISK as a recognized image type.

---
 kexec/kexec-uImage.c |    2 ++
 1 file changed, 2 insertions(+)
kexec/kexec-uImage.c +2 -0
index dcbd635..701eeb1 100644
@@ -52,6 +52,8 @@ int uImage_probe(const unsigned char *buf, off_t len, unsigned int arch)
 			return -1;
 		}
 		break;
+	case IH_TYPE_RAMDISK:
+		break;
 	default:
 		printf("uImage type %d unsupported\n", header.ih_type);
 		return -1;

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#5 lore raw

PATCH 3/3 ppc/uImage: Add support for RAM Disks

In reply to Suzuki K. Poulose

From: Suzuki K. Poulose <[email protected]>

Handle the RAM Disks in uImage format

---
 kexec/arch/ppc/kexec-uImage-ppc.c |   22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
kexec/arch/ppc/kexec-uImage-ppc.c +21 -1
index eaea3c1..58935c0 100644
@@ -46,6 +46,26 @@ void uImage_ppc_usage(void)
 	);
 }
 
+char* slurp_ramdisk_ppc(const char *filename, off_t *r_size)
+{
+	struct Image_info img;
+	off_t size;
+	const unsigned char *buf = 
+			(const unsigned char *)slurp_file(filename, &size);
+
+	/* Check if this is a uImage RAMDisk */
+	if (buf != (void*)0 &&
+		uImage_probe(buf, size, IH_ARCH_PPC) == IH_TYPE_RAMDISK) {
+		if (uImage_load(buf, size, &img) != 0)
+			die ("uImage: Reading %ld bytes from %s failed\n", size, filename);
+		buf = img.buf;
+		size = img.len;
+	}
+
+	*r_size = size;
+	return buf;
+}
+	
 int uImage_ppc_probe(const char *buf, off_t len)
 {
 	int type;
@@ -196,7 +216,7 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
 	blob_buf = fixup_dtb_init(info, blob_buf, &blob_size, load_addr, &dtb_addr);
 
 	if (ramdisk) {
-		seg_buf = slurp_file(ramdisk, &seg_size);
+		seg_buf = slurp_ramdisk_ppc(ramdisk, &seg_size);
 		/* Load ramdisk at top of memory */
 		hole_addr = add_buffer(info, seg_buf, seg_size, seg_size,
 				0, dtb_addr + blob_size, max_addr, -1);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw

Re: [PATCH 3/3] ppc/uImage: Add support for RAM Disks

Quoted 3 lines · Suzuki K. Poulose

From: Suzuki K. Poulose <[email protected]>

Handle the RAM Disks in uImage format

As opposed to simple ext2.gz ramdisk?

-M

Quoted 48 lines
---
 kexec/arch/ppc/kexec-uImage-ppc.c |   22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
kexec/arch/ppc/kexec-uImage-ppc.c +21 -1
index eaea3c1..58935c0 100644
@@ -46,6 +46,26 @@ void uImage_ppc_usage(void)
        );
 }
 
+char* slurp_ramdisk_ppc(const char *filename, off_t *r_size)
+{
+       struct Image_info img;
+       off_t size;
+       const unsigned char *buf =
+                       (const unsigned char *)slurp_file(filename, &size);
+
+       /* Check if this is a uImage RAMDisk */
+       if (buf != (void*)0 &&
+               uImage_probe(buf, size, IH_ARCH_PPC) == IH_TYPE_RAMDISK) {
+               if (uImage_load(buf, size, &img) != 0)
+                       die ("uImage: Reading %ld bytes from %s failed\n", size, filename);
+               buf = img.buf;
+               size = img.len;
+       }
+
+       *r_size = size;
+       return buf;
+}
+
 int uImage_ppc_probe(const char *buf, off_t len)
 {
        int type;
@@ -196,7 +216,7 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
        blob_buf = fixup_dtb_init(info, blob_buf, &blob_size, load_addr, &dtb_addr);
 
        if (ramdisk) {
-               seg_buf = slurp_file(ramdisk, &seg_size);
+               seg_buf = slurp_ramdisk_ppc(ramdisk, &seg_size);
                /* Load ramdisk at top of memory */
                hole_addr = add_buffer(info, seg_buf, seg_size, seg_size,
                                0, dtb_addr + blob_size, max_addr, -1);
Quoted 4 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#7 lore raw

Re: [PATCH 3/3] ppc/uImage: Add support for RAM Disks

Quoted 6 lines · On 01/11/2013 12:41 PM, McClintock Matthew-B29882 wrote:
Quoted 3 lines · Suzuki K. Poulose

From: Suzuki K. Poulose <[email protected]>

Handle the RAM Disks in uImage format

As opposed to simple ext2.gz ramdisk?

Yep. Any supported ramdisk format can be wrapped up in a uImage file.

Thanks
Suzuki

Quoted 51 lines

-M

Quoted 48 lines
---
  kexec/arch/ppc/kexec-uImage-ppc.c |   22 +++++++++++++++++++++-
  1 file changed, 21 insertions(+), 1 deletion(-)
kexec/arch/ppc/kexec-uImage-ppc.c +21 -1
index eaea3c1..58935c0 100644
@@ -46,6 +46,26 @@ void uImage_ppc_usage(void)
         );
  }
 
+char* slurp_ramdisk_ppc(const char *filename, off_t *r_size)
+{
+       struct Image_info img;
+       off_t size;
+       const unsigned char *buf =
+                       (const unsigned char *)slurp_file(filename, &size);
+
+       /* Check if this is a uImage RAMDisk */
+       if (buf != (void*)0 &&
+               uImage_probe(buf, size, IH_ARCH_PPC) == IH_TYPE_RAMDISK) {
+               if (uImage_load(buf, size, &img) != 0)
+                       die ("uImage: Reading %ld bytes from %s failed\n", size, filename);
+               buf = img.buf;
+               size = img.len;
+       }
+
+       *r_size = size;
+       return buf;
+}
+
  int uImage_ppc_probe(const char *buf, off_t len)
  {
         int type;
@@ -196,7 +216,7 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
         blob_buf = fixup_dtb_init(info, blob_buf, &blob_size, load_addr, &dtb_addr);
 
         if (ramdisk) {
-               seg_buf = slurp_file(ramdisk, &seg_size);
+               seg_buf = slurp_ramdisk_ppc(ramdisk, &seg_size);
                 /* Load ramdisk at top of memory */
                 hole_addr = add_buffer(info, seg_buf, seg_size, seg_size,
                                 0, dtb_addr + blob_size, max_addr, -1);
Quoted 10 lines
Quoted 4 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#8 lore raw

Re: [PATCH 3/3] ppc/uImage: Add support for RAM Disks

Quoted 11 lines · Suzuki K. Poulose
Quoted 10 lines · On 01/11/2013 12:41 PM, McClintock Matthew-B29882 wrote:
Quoted 4 lines · Suzuki K. Poulose

From: Suzuki K. Poulose <[email protected]>

Handle the RAM Disks in uImage format

As opposed to simple ext2.gz ramdisk?

OK - it's been a while but we only supported uImage for kernel image not ramdisk. That's what threw me off when I wrote this email I believe.

-M

Quoted 79 lines

Yep. Any supported ramdisk format can be wrapped up in a uImage file.

Thanks
Suzuki

Quoted 58 lines

-M

Quoted 55 lines
---
  kexec/arch/ppc/kexec-uImage-ppc.c |   22 +++++++++++++++++++++-
  1 file changed, 21 insertions(+), 1 deletion(-)
kexec/arch/ppc/kexec-uImage-ppc.c +20 -0
index eaea3c1..58935c0 100644
@@ -46,6 +46,26 @@ void uImage_ppc_usage(void)
         );
  }
 
+char* slurp_ramdisk_ppc(const char *filename, off_t *r_size)
+{
+       struct Image_info img;
+       off_t size;
+       const unsigned char *buf =
+                       (const unsigned char *)slurp_file(filename,
 &size);
+
+       /* Check if this is a uImage RAMDisk */
+       if (buf != (void*)0 &&
+               uImage_probe(buf, size, IH_ARCH_PPC) == IH_TYPE_RAMDISK)
 {
+               if (uImage_load(buf, size, &img) != 0)
+                       die ("uImage: Reading %ld bytes from %s
 failed\n", size, filename);
+               buf = img.buf;
+               size = img.len;
+       }
+
+       *r_size = size;
+       return buf;
+}
+
  int uImage_ppc_probe(const char *buf, off_t len)
  {
         int type;
kexec/arch/ppc/kexec-uImage-ppc.c +1 -1
@@ -196,7 +216,7 @@ static int ppc_load_bare_bits(int argc, char **argv,
 const char *buf,
         blob_buf = fixup_dtb_init(info, blob_buf, &blob_size, load_addr,
 &dtb_addr);
 
         if (ramdisk) {
-               seg_buf = slurp_file(ramdisk, &seg_size);
+               seg_buf = slurp_ramdisk_ppc(ramdisk, &seg_size);
                 /* Load ramdisk at top of memory */

hole_addr = add_buffer(info, seg_buf, seg_size,
seg_size,

                                 0, dtb_addr + blob_size, max_addr, -1);
Quoted 11 lines
Quoted 4 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Quoted 4 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#9 lore raw

Re: [PATCH 3/3] ppc/uImage: Add support for RAM Disks

Quoted 8 lines · * McClintock Matthew-B29882 | 2013-01-14 15:14:16 [+0000]:
Quoted 7 lines · Suzuki K. Poulose
Quoted 6 lines · On 01/11/2013 12:41 PM, McClintock Matthew-B29882 wrote:
Quoted 3 lines · Suzuki K. Poulose

From: Suzuki K. Poulose <[email protected]>

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

Handle the RAM Disks in uImage format

As opposed to simple ext2.gz ramdisk?

OK - it's been a while but we only supported uImage for kernel image not ramdisk. That's what threw me off when I wrote this email I believe.

Who is "we"? Did you use kexec and pass ext2.gz as a ramdisk?

u-boot supports this like for ever. You start the kernel via
bootm x y z

where y is the address of the ramdisk / initrd. passing the address the ext2.gz files does not work.
As an alternative to this you can only pass x to bootm and the image has the "uImage.FIT" format which can contain the kernel, device tree and a ramdisk in one piece.

Quoted 1 line

-M

Sebastian

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#11 lore raw

Re: [PATCH 3/3] ppc/uImage: Add support for RAM Disks

In reply to Suzuki K. Poulose

* Suzuki K. Poulose | 2013-01-11 12:12:11 [+0530]:

only some stylish comments…

kexec/arch/ppc/kexec-uImage-ppc.c void uImage_ppc_usage(void) · line 49

Quoted 9 lines
kexec/arch/ppc/kexec-uImage-ppc.c +1 -0
index eaea3c1..58935c0 100644
@@ -46,6 +46,26 @@ void uImage_ppc_usage(void)
 	);
 }
 
+char* slurp_ramdisk_ppc(const char *filename, off_t *r_size)

char *slurp_ramdisk_ppc(const char *filename, off_t *r_size) ?

kexec/arch/ppc/kexec-uImage-ppc.c void uImage_ppc_usage(void) · line 54

Quoted 5 lines
kexec/arch/ppc/kexec-uImage-ppc.c +5 -0
+{
+	struct Image_info img;
+	off_t size;
+	const unsigned char *buf = 
+			(const unsigned char *)slurp_file(filename, &size);

is the const cast required here?

kexec/arch/ppc/kexec-uImage-ppc.c void uImage_ppc_usage(void) · line 57

Quoted 2 lines
kexec/arch/ppc/kexec-uImage-ppc.c +2 -0
+	/* Check if this is a uImage RAMDisk */
+	if (buf != (void*)0 &&

this should be NULL if at all

kexec/arch/ppc/kexec-uImage-ppc.c void uImage_ppc_usage(void) · line 58

Quoted 1 line
kexec/arch/ppc/kexec-uImage-ppc.c +1 -0
+		uImage_probe(buf, size, IH_ARCH_PPC) == IH_TYPE_RAMDISK) {

and maybe splitted in more than one line

kexec/arch/ppc/kexec-uImage-ppc.c void uImage_ppc_usage(void) · line 60

Quoted 2 lines
kexec/arch/ppc/kexec-uImage-ppc.c +2 -0
+		if (uImage_load(buf, size, &img) != 0)
+			die ("uImage: Reading %ld bytes from %s failed\n", size, filename);

no space between the function.

Quoted 12 lines
kexec/arch/ppc/kexec-uImage-ppc.c +8 -0
+		buf = img.buf;
+		size = img.len;
+	}
+
+	*r_size = size;
+	return buf;
+}
+	
 int uImage_ppc_probe(const char *buf, off_t len)
 {
 	int type;

kexec/arch/ppc/kexec-uImage-ppc.c static int ppc_load_bare_bits(int argc, char **argv, const char *buf, · line 219

Quoted 5 lines
kexec/arch/ppc/kexec-uImage-ppc.c +1 -1
@@ -196,7 +216,7 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
 	blob_buf = fixup_dtb_init(info, blob_buf, &blob_size, load_addr, &dtb_addr);
 
 	if (ramdisk) {
-		seg_buf = slurp_file(ramdisk, &seg_size);
+		seg_buf = slurp_ramdisk_ppc(ramdisk, &seg_size);

I'm not sure but this kinda breaks the case where someone was using a plain file without the uImage header. I don't know if someone used this at all but it seems we have code for this. The way you load the uImage is very generic and I would expect to load it the same way on ARM or SH.

One thing that is different compared to kernel: If the compression is set to GZ on a ramdisk image you should not uncompress it. I think that uImage_load() decompresses the .gz part for you but I am not sure.

kexec/arch/ppc/kexec-uImage-ppc.c static int ppc_load_bare_bits(int argc, char **argv, const char *buf, · line 222

Quoted 4 lines
kexec/arch/ppc/kexec-uImage-ppc.c +0 -0
 		/* Load ramdisk at top of memory */
 		hole_addr = add_buffer(info, seg_buf, seg_size, seg_size,
 				0, dtb_addr + blob_size, max_addr, -1);

Sebastian

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#12 lore raw

Re: [PATCH 3/3] ppc/uImage: Add support for RAM Disks

Quoted 12 lines · Sebastian Andrzej Siewior

* Suzuki K. Poulose | 2013-01-11 12:12:11 [+0530]:

only some stylish comments…

Quoted 8 lines
kexec/arch/ppc/kexec-uImage-ppc.c +0 -0
index eaea3c1..58935c0 100644
@@ -46,6 +46,26 @@ void uImage_ppc_usage(void)
 	);
 }
 
Quoted 3 lines

kexec/arch/ppc/kexec-uImage-ppc.c void uImage_ppc_usage(void) · line 49

Quoted 1 line
kexec/arch/ppc/kexec-uImage-ppc.c +1 -0
+char* slurp_ramdisk_ppc(const char *filename, off_t *r_size)

char *slurp_ramdisk_ppc(const char *filename, off_t *r_size) ?

OK

Quoted 8 lines

kexec/arch/ppc/kexec-uImage-ppc.c void uImage_ppc_usage(void) · line 54

Quoted 6 lines
kexec/arch/ppc/kexec-uImage-ppc.c +5 -0
+{
+	struct Image_info img;
+	off_t size;
+	const unsigned char *buf =
+			(const unsigned char *)slurp_file(filename, &size);

is the const cast required here?

Yes, the uImage_probe() expects (const unsigned char *) as the first argument.

Quoted 5 lines

kexec/arch/ppc/kexec-uImage-ppc.c void uImage_ppc_usage(void) · line 57

Quoted 3 lines
kexec/arch/ppc/kexec-uImage-ppc.c +2 -0
+	/* Check if this is a uImage RAMDisk */
+	if (buf != (void*)0 &&

this should be NULL if at all

OK

Quoted 3 lines

kexec/arch/ppc/kexec-uImage-ppc.c void uImage_ppc_usage(void) · line 58

Quoted 1 line
kexec/arch/ppc/kexec-uImage-ppc.c +1 -0
+		uImage_probe(buf, size, IH_ARCH_PPC) == IH_TYPE_RAMDISK) {

and maybe splitted in more than one line

OK

Quoted 4 lines

kexec/arch/ppc/kexec-uImage-ppc.c void uImage_ppc_usage(void) · line 60

Quoted 2 lines
kexec/arch/ppc/kexec-uImage-ppc.c +2 -0
+		if (uImage_load(buf, size, &img) != 0)
+			die ("uImage: Reading %ld bytes from %s failed\n", size, filename);

no space between the function.

OK

Quoted 14 lines
Quoted 14 lines
kexec/arch/ppc/kexec-uImage-ppc.c +8 -0
+		buf = img.buf;
+		size = img.len;
+	}
+
+	*r_size = size;
+	return buf;
+}
+	
 int uImage_ppc_probe(const char *buf, off_t len)
 {
 	int type;
@@ -196,7 +216,7 @@ static int ppc_load_bare_bits(int argc, char **argv, const char *buf,
 	blob_buf = fixup_dtb_init(info, blob_buf, &blob_size, load_addr, &dtb_addr);
 
Quoted 9 lines

kexec/arch/ppc/kexec-uImage-ppc.c static int ppc_load_bare_bits(int argc, char **argv, const char *buf, · line 219

Quoted 3 lines
kexec/arch/ppc/kexec-uImage-ppc.c +1 -1
 	if (ramdisk) {
-		seg_buf = slurp_file(ramdisk, &seg_size);
+		seg_buf = slurp_ramdisk_ppc(ramdisk, &seg_size);

I'm not sure but this kinda breaks the case where someone was using a plain file without the uImage header. I don't know if someone used this at all but it seems we have code for this. The way you load the uImage is very generic and I would expect to load it the same way on ARM or SH.

If the ramdisk doesn't have uImage header, the slurp_ramdisk_ppc() defaults to the original behaviour. i.e, it just does a slurp_file() as it used to do earlier.

Quoted 4 lines

One thing that is different compared to kernel: If the compression is set to GZ on a ramdisk image you should not uncompress it. I think that uImage_load() decompresses the .gz part for you but I am not sure.

Did you mean, uImage_load() shouldn't do a decompression for ramdisk ? We rely on uImage_load to get what is required.

Quoted 5 lines

kexec/arch/ppc/kexec-uImage-ppc.c static int ppc_load_bare_bits(int argc, char **argv, const char *buf, · line 222

Quoted 4 lines
kexec/arch/ppc/kexec-uImage-ppc.c +0 -0
 		/* Load ramdisk at top of memory */
 		hole_addr = add_buffer(info, seg_buf, seg_size, seg_size,
 				0, dtb_addr + blob_size, max_addr, -1);

Thanks for the detailed review.

Suzuki

Quoted 7 lines

Sebastian

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#13 lore raw

Re: [PATCH 3/3] ppc/uImage: Add support for RAM Disks

Quoted 10 lines · Suzuki K. Poulose
Quoted 7 lines

kexec/arch/ppc/kexec-uImage-ppc.c void uImage_ppc_usage(void) · line 54

Quoted 5 lines
kexec/arch/ppc/kexec-uImage-ppc.c +5 -0
+{
+    struct Image_info img;
+    off_t size;
+    const unsigned char *buf =
+            (const unsigned char *)slurp_file(filename, &size);

is the const cast required here?

Yes, the uImage_probe() expects (const unsigned char *) as the first argument.

That is okay, you can pass a non-const pointer to function that expects a const pointer. You just can't pass a const pointer to a non-const function and you should not cast in that situtation as well.

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
kexec/arch/ppc/kexec-uImage-ppc.c +8 -0
+        buf = img.buf;
+        size = img.len;
+    }
+
+    *r_size = size;
+    return buf;
+}
+   

int uImage_ppc_probe(const char *buf, off_t len)

{
    int type;
(quoted diff) +0 -0
@@ -196,7 +216,7 @@ static int ppc_load_bare_bits(int argc, char
 **argv, const char *buf,
    blob_buf = fixup_dtb_init(info, blob_buf, &blob_size, load_addr,
 &dtb_addr);
 
Quoted 9 lines

kexec/arch/ppc/kexec-uImage-ppc.c static int ppc_load_bare_bits(int argc, char **argv, const char *buf, · line 219

Quoted 3 lines
kexec/arch/ppc/kexec-uImage-ppc.c +1 -1
    if (ramdisk) {
-        seg_buf = slurp_file(ramdisk, &seg_size);
+        seg_buf = slurp_ramdisk_ppc(ramdisk, &seg_size);

I'm not sure but this kinda breaks the case where someone was using a plain file without the uImage header. I don't know if someone used this at all but it seems we have code for this. The way you load the uImage is very generic and I would expect to load it the same way on ARM or SH.

Quoted 3 lines

If the ramdisk doesn't have uImage header, the slurp_ramdisk_ppc() defaults to the original behaviour. i.e, it just does a slurp_file() as it used to do earlier.

that is okay then.

Quoted 6 lines
Quoted 4 lines

One thing that is different compared to kernel: If the compression is set to GZ on a ramdisk image you should not uncompress it. I think that uImage_load() decompresses the .gz part for you but I am not sure.

Did you mean, uImage_load() shouldn't do a decompression for ramdisk ?

Yes. If you look at u-boot source, you will notice that it will decompress a kernel if it is gzip/bzip2/whatever compressed and ignore the compression field in case of a ramdisk. I think you should behave like u-boot does.

Sebastian

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec