All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm: ramdisk uimage support for arm
@ 2015-12-16  8:06 Michele Dionisio
  2015-12-17  4:23 ` Pratyush Anand
  0 siblings, 1 reply; 4+ messages in thread
From: Michele Dionisio @ 2015-12-16  8:06 UTC (permalink / raw)
  To: kexec

[-- Attachment #1: Type: text/plain, Size: 365 bytes --]

Hi, I have add support for uboot ramdisk support in the patch attached.

the new features is implemented in:
kexec/arch/arm/kexec-uImage-arm.c
kexec/arch/arm/kexec-zImage-arm.c

but there is also a fix in
kexec/kexec-uImage.c where there is a endianes bug.

If someone can review the patch I think that it can be usefull to be 
added in the next version.

Regards.

[-- Attachment #2: 0000-fix-ramdisk-uimage.patch --]
[-- Type: text/x-patch, Size: 2880 bytes --]

diff --git a/kexec/arch/arm/kexec-uImage-arm.c b/kexec/arch/arm/kexec-uImage-arm.c
index 03c2f4d..20d71a2 100644
--- a/kexec/arch/arm/kexec-uImage-arm.c
+++ b/kexec/arch/arm/kexec-uImage-arm.c
@@ -17,6 +17,12 @@ int uImage_arm_probe(const char *buf, off_t len)
 int uImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 	struct kexec_info *info)
 {
-	return zImage_arm_load(argc, argv, buf + sizeof(struct image_header),
-	                       len - sizeof(struct image_header), info);
+    struct Image_info img;
+	int ret;
+
+	ret = uImage_load(buf, len, &img);
+	if (ret)
+		return ret;
+    
+	return zImage_arm_load(argc, argv, img.buf, img.len, info);
 }
diff --git a/kexec/arch/arm/kexec-zImage-arm.c b/kexec/arch/arm/kexec-zImage-arm.c
index d85ab9b..fda30f8 100644
--- a/kexec/arch/arm/kexec-zImage-arm.c
+++ b/kexec/arch/arm/kexec-zImage-arm.c
@@ -14,6 +14,8 @@
 #include <getopt.h>
 #include <unistd.h>
 #include <libfdt.h>
+#include <image.h>
+#include <kexec-uImage.h>
 #include <arch/options.h>
 #include "../../kexec.h"
 #include "../../kexec-syscall.h"
@@ -318,6 +320,36 @@ static int setup_dtb_prop(char **bufp, off_t *sizep, const char *node_name,
 	return 0;
 }
 
+/*
+ * Load the ramdisk into buffer.
+ *  If the supplied image is in uImage format use
+ *  uImage_load() to read the payload from the image.
+ */
+char *slurp_ramdisk_arm(const char *filename, off_t *r_size)
+{
+	struct Image_info img;
+	off_t size;
+	const unsigned char *buf = slurp_file(filename, &size);
+	int rc;
+
+	/* Check if this is a uImage RAMDisk */
+	if (!buf)
+		return buf;
+	rc = uImage_probe_ramdisk(buf, size, IH_ARCH_ARM); 
+	if (rc < 0)
+		die("uImage: Corrupted ramdisk file %s\n", filename);
+	else if (rc == 0) {
+		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 zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 	struct kexec_info *info)
 {
@@ -410,7 +442,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 			command_line_len = COMMAND_LINE_SIZE;
 	}
 	if (ramdisk)
-		ramdisk_buf = slurp_file(ramdisk, &initrd_size);
+		ramdisk_buf = slurp_ramdisk_arm(ramdisk, &initrd_size);
 
 	if (dtb_file)
 		dtb_buf = slurp_file(dtb_file, &dtb_length);
diff --git a/kexec/kexec-uImage.c b/kexec/kexec-uImage.c
index 9df601b..5b85e86 100644
--- a/kexec/kexec-uImage.c
+++ b/kexec/kexec-uImage.c
@@ -235,7 +235,7 @@ int uImage_load(const unsigned char *buf, off_t len, struct Image_info *image)
 {
 	const struct image_header *header = (const struct image_header *)buf;
 	const unsigned char *img_buf = buf + sizeof(struct image_header);
-	off_t img_len = header->ih_size;
+	off_t img_len =  cpu_to_be32(header->ih_size);
 
 	/*
 	 * Prevent loading a modified image.

[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

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

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

* Re: [PATCH] arm: ramdisk uimage support for arm
  2015-12-16  8:06 [PATCH] arm: ramdisk uimage support for arm Michele Dionisio
@ 2015-12-17  4:23 ` Pratyush Anand
  2015-12-17  7:57   ` Michele Dionisio
  0 siblings, 1 reply; 4+ messages in thread
From: Pratyush Anand @ 2015-12-17  4:23 UTC (permalink / raw)
  To: Michele Dionisio; +Cc: kexec

Hi Michele,

On 16/12/2015:09:06:36 AM, Michele Dionisio wrote:
> +/*
> + * Load the ramdisk into buffer.
> + *  If the supplied image is in uImage format use
> + *  uImage_load() to read the payload from the image.
> + */
> +char *slurp_ramdisk_arm(const char *filename, off_t *r_size)

This function is exactly as slurp_ramdisk_ppc(). So, why not we have a common
slurp_ramdisk() function usable for both arm and ppc.

~Pratyush

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

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

* Re: [PATCH] arm: ramdisk uimage support for arm
  2015-12-17  4:23 ` Pratyush Anand
@ 2015-12-17  7:57   ` Michele Dionisio
  2015-12-17  9:51     ` Pratyush Anand
  0 siblings, 1 reply; 4+ messages in thread
From: Michele Dionisio @ 2015-12-17  7:57 UTC (permalink / raw)
  To: Pratyush Anand; +Cc: kexec

yes it is true.

I'm not in the position to test ppc. So my only way to be sure to avoid 
to introduce regration is to avoid to refactor the code.

But it is true. If you are able to test ppc I can try to post the 
refactoring.

Il 17/12/2015 05:23, Pratyush Anand ha scritto:
> Hi Michele,
>
> On 16/12/2015:09:06:36 AM, Michele Dionisio wrote:
>> +/*
>> + * Load the ramdisk into buffer.
>> + *  If the supplied image is in uImage format use
>> + *  uImage_load() to read the payload from the image.
>> + */
>> +char *slurp_ramdisk_arm(const char *filename, off_t *r_size)
> This function is exactly as slurp_ramdisk_ppc(). So, why not we have a common
> slurp_ramdisk() function usable for both arm and ppc.
>
> ~Pratyush
> .
>


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

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

* Re: [PATCH] arm: ramdisk uimage support for arm
  2015-12-17  7:57   ` Michele Dionisio
@ 2015-12-17  9:51     ` Pratyush Anand
  0 siblings, 0 replies; 4+ messages in thread
From: Pratyush Anand @ 2015-12-17  9:51 UTC (permalink / raw)
  To: Michele Dionisio; +Cc: kexec

On 17/12/2015:08:57:14 AM, Michele Dionisio wrote:
> yes it is true.
> 
> I'm not in the position to test ppc. So my only way to be sure to avoid to
> introduce regration is to avoid to refactor the code.
> 
> But it is true. If you are able to test ppc I can try to post the
> refactoring.

I also do not be able to test it on ppc, but I believe refactoring would be
trivial and would not have any functionality difference. So, better to go with
that rather than duplicating the code. You may keep ppc developer in CC and ask
for ACK from  them.

~Pratyush


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

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

end of thread, other threads:[~2015-12-17  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-16  8:06 [PATCH] arm: ramdisk uimage support for arm Michele Dionisio
2015-12-17  4:23 ` Pratyush Anand
2015-12-17  7:57   ` Michele Dionisio
2015-12-17  9:51     ` Pratyush Anand

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.