Skip to contentSkip to conversation

kexec-tools: fix bugs and pass initrd position for arm

PATCH In review Wang Nan 2 participants 13 messages Jan 22, 2014 – Feb 6, 2014

Subsystems (2)
lore
Share & tools
lore

Wang Nan

author
#0 lore raw

cover kexec-tools: fix bugs and pass initrd position for arm

Hi,

This patch series contains following bug fixes and cleanups for kexec-tools on arm platform:

Wang Nan (3):
kexec: align initrd when no --image-size
kexec: pass initrd position in dtb
kexec: increase zImage compress ratio from 4 to 5

 kexec/arch/arm/kexec-zImage-arm.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
Cc Simon Horman <[email protected]>
Cc Dave Young <[email protected]>
Cc Geng Hui <[email protected]>
Signature · 7 lines
1.8.4


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

PATCH 1/3 kexec: align initrd when no --image-size

Before this patch, when no --image-size passed, initrd_base is caculated using base + len * 4, which is unaligned, and unable to pass check in add_segment_phys_virt():

	if (base & (pagesize -1)) {
		die("Base address: 0x%lx is not page aligned\n", base);
	}
Cc Simon Horman <[email protected]>
Cc Dave Young <[email protected]>
Cc Geng Hui <[email protected]>
---
 kexec/arch/arm/kexec-zImage-arm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kexec/arch/arm/kexec-zImage-arm.c +1 -1
index 792187a..4547765 100644
@@ -351,7 +351,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 	} else {
 		/* Otherwise, assume the maximum kernel compression ratio
 		 * is 4, and just to be safe, place ramdisk after that */
-		initrd_base = base + len * 4;
+		initrd_base =  base + _ALIGN(len * 4, 4096);
 	}
 
 	if (use_atags) {
Signature · 7 lines
1.8.4


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

Re: [PATCH 1/3] kexec: align initrd when no --image-size

Quoted 21 lines · Wang Nan

Before this patch, when no --image-size passed, initrd_base is caculated using base + len * 4, which is unaligned, and unable to pass check in add_segment_phys_virt():

	if (base & (pagesize -1)) {
		die("Base address: 0x%lx is not page aligned\n", base);
	}
Cc Simon Horman <[email protected]>
Cc Dave Young <[email protected]>
Cc Geng Hui <[email protected]>
---
 kexec/arch/arm/kexec-zImage-arm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kexec/arch/arm/kexec-zImage-arm.c +0 -0
index 792187a..4547765 100644

kexec/arch/arm/kexec-zImage-arm.c int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, · line 354

Quoted 5 lines
kexec/arch/arm/kexec-zImage-arm.c +1 -1
@@ -351,7 +351,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 	} else {
 		/* Otherwise, assume the maximum kernel compression ratio
 		 * is 4, and just to be safe, place ramdisk after that */
-		initrd_base = base + len * 4;
+		initrd_base =  base + _ALIGN(len * 4, 4096);

get_page_size should be used instead of 4096, otherwise it looks good to me.

Thanks
Dave

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

author
#3 lore raw

PATCH 2/3 kexec: pass initrd position in dtb

In reply to Wang Nan

This patch append the position of initrd to dtb when loading arm kernel and initrd without using atag.

Cc Simon Horman <[email protected]>
Cc Dave Young <[email protected]>
Cc Geng Hui <[email protected]>
---
 kexec/arch/arm/kexec-zImage-arm.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
kexec/arch/arm/kexec-zImage-arm.c +35 -0
index 4547765..6d6b239 100644
@@ -417,6 +417,41 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 		if (ramdisk) {
 			add_segment(info, ramdisk_buf, initrd_size,
 			            initrd_base, initrd_size);
+			const char *node_name = "/chosen";
+			const char *prop_start_name = "linux,initrd-start";
+			const char *prop_end_name = "linux,initrd-end";
+			int off;
+
+			dtb_length = fdt_totalsize(dtb_buf) + 1024 + 8;
+			dtb_buf = xrealloc(dtb_buf, dtb_length);
+			fdt_set_totalsize(dtb_buf, dtb_length);
+
+			/* check if a /choosen subnode already exists */
+			off = fdt_path_offset(dtb_buf, node_name);
+
+			if (off == -FDT_ERR_NOTFOUND)
+				off = fdt_add_subnode(dtb_buf, off, node_name);
+
+			if (off < 0) {
+				fprintf(stderr, "FDT: Error adding %s node.\n", node_name);
+				return -1;
+			}
+
+			unsigned long start, end;
+			start = cpu_to_be32((unsigned long)(initrd_base));
+			end = cpu_to_be32((unsigned long)(initrd_base + initrd_size));
+			if (fdt_setprop(dtb_buf, off, prop_start_name,
+						&start, sizeof(start)) != 0) {
+				fprintf(stderr, "FDT: Error setting %s/%s property.\n",
+						node_name, prop_start_name);
+				return -1;
+			}
+			if (fdt_setprop(dtb_buf, off, prop_end_name,
+						&end, sizeof(end)) != 0) {
+				fprintf(stderr, "FDT: Error setting %s/%s property.\n",
+						node_name, prop_end_name);
+				return -1;
+			}
 		}
 
 		/* Stick the dtb at the end of the initrd and page
Signature · 7 lines
1.8.4


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

Re: [PATCH 2/3] kexec: pass initrd position in dtb

Quoted 16 lines · Wang Nan

This patch append the position of initrd to dtb when loading arm kernel and initrd without using atag.

Cc Simon Horman <[email protected]>
Cc Dave Young <[email protected]>
Cc Geng Hui <[email protected]>
---
 kexec/arch/arm/kexec-zImage-arm.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
kexec/arch/arm/kexec-zImage-arm.c +0 -0
index 4547765..6d6b239 100644

kexec/arch/arm/kexec-zImage-arm.c int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, · line 425

Quoted 9 lines
kexec/arch/arm/kexec-zImage-arm.c +6 -0
@@ -417,6 +417,41 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 		if (ramdisk) {
 			add_segment(info, ramdisk_buf, initrd_size,
 			            initrd_base, initrd_size);
+			const char *node_name = "/chosen";
+			const char *prop_start_name = "linux,initrd-start";
+			const char *prop_end_name = "linux,initrd-end";
+			int off;
+
+			dtb_length = fdt_totalsize(dtb_buf) + 1024 + 8;

why +8 here? is it the "/chosen" string size? if yes please change to use strlen.

kexec/arch/arm/kexec-zImage-arm.c int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, · line 426

Quoted 1 line
kexec/arch/arm/kexec-zImage-arm.c +1 -0
+			dtb_buf = xrealloc(dtb_buf, dtb_length);

Should check xrealloc return value here.

Since it is very similar with the code for appending cmdline, at least creating a share function for adding a new node looks better.

Quoted 39 lines
kexec/arch/arm/kexec-zImage-arm.c +28 -0
+			fdt_set_totalsize(dtb_buf, dtb_length);
+
+			/* check if a /choosen subnode already exists */
+			off = fdt_path_offset(dtb_buf, node_name);
+
+			if (off == -FDT_ERR_NOTFOUND)
+				off = fdt_add_subnode(dtb_buf, off, node_name);
+
+			if (off < 0) {
+				fprintf(stderr, "FDT: Error adding %s node.\n", node_name);
+				return -1;
+			}
+
+			unsigned long start, end;
+			start = cpu_to_be32((unsigned long)(initrd_base));
+			end = cpu_to_be32((unsigned long)(initrd_base + initrd_size));
+			if (fdt_setprop(dtb_buf, off, prop_start_name,
+						&start, sizeof(start)) != 0) {
+				fprintf(stderr, "FDT: Error setting %s/%s property.\n",
+						node_name, prop_start_name);
+				return -1;
+			}
+			if (fdt_setprop(dtb_buf, off, prop_end_name,
+						&end, sizeof(end)) != 0) {
+				fprintf(stderr, "FDT: Error setting %s/%s property.\n",
+						node_name, prop_end_name);
+				return -1;
+			}
 		}
 
 		/* Stick the dtb at the end of the initrd and page
Signature · 7 lines
1.8.4


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

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

author
#5 lore raw

PATCH 3/3 kexec: increase zImage compression ratio from 4 to 5

In reply to Wang Nan

Old code assume the zImage compression ration is 4, it is not enough, 5 shall be better.

Cc Simon Horman <[email protected]>
Cc Dave Young <[email protected]>
Cc Geng Hui <[email protected]>
---
 kexec/arch/arm/kexec-zImage-arm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kexec/arch/arm/kexec-zImage-arm.c +1 -1
index 6d6b239..6e5e12b 100644
@@ -351,7 +351,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 	} else {
 		/* Otherwise, assume the maximum kernel compression ratio
 		 * is 4, and just to be safe, place ramdisk after that */
-		initrd_base =  base + _ALIGN(len * 4, 4096);
+		initrd_base =  base + _ALIGN(len * 5, 4096);
 	}
 
 	if (use_atags) {
Signature · 7 lines
1.8.4


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

Re: [PATCH 3/3] kexec: increase zImage compression ratio from 4 to 5

Quoted 2 lines · Wang Nan

Old code assume the zImage compression ration is 4, it is not enough, 5 shall be better.

4 works well during my test. Do you have real test case to reproduce this problem?

Quoted 30 lines
Cc Simon Horman <[email protected]>
Cc Dave Young <[email protected]>
Cc Geng Hui <[email protected]>
---
 kexec/arch/arm/kexec-zImage-arm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kexec/arch/arm/kexec-zImage-arm.c +1 -1
index 6d6b239..6e5e12b 100644
@@ -351,7 +351,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
 	} else {
 		/* Otherwise, assume the maximum kernel compression ratio
 		 * is 4, and just to be safe, place ramdisk after that */
-		initrd_base =  base + _ALIGN(len * 4, 4096);
+		initrd_base =  base + _ALIGN(len * 5, 4096);
 	}
 
 	if (use_atags) {
Signature · 7 lines
1.8.4


_______________________________________________
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
In reply to Wang Nan
Quoted 5 lines · Wang Nan

Hi,

This patch series contains following bug fixes and cleanups for kexec-tools on arm platform:

Quoted 7 lines

Wang Nan (3):
kexec: align initrd when no --image-size
kexec: pass initrd position in dtb
kexec: increase zImage compress ratio from 4 to 5

 kexec/arch/arm/kexec-zImage-arm.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

Previously I tested arm kexec on virtual machine, there's some breakage. But due to lack of time I did not get chance to continue on it. I will have a test with your patches and review the patches.

Thanks
Dave

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

#8 lore raw
In reply to Wang Nan
Quoted 9 lines · Wang Nan

Hi,

This patch series contains following bug fixes and cleanups for kexec-tools on arm platform:

Wang Nan (3):
kexec: align initrd when no --image-size
kexec: pass initrd position in dtb
kexec: increase zImage compress ratio from 4 to 5

One question:
Is these kexec-tools patches enough for kexec work or still need the kernel patches you sent?

Thanks
Dave

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

author
#9 lore raw
Quoted 11 lines · Dave Young
Quoted 9 lines · Wang Nan

Hi,

This patch series contains following bug fixes and cleanups for kexec-tools on arm platform:

Wang Nan (3):
kexec: align initrd when no --image-size
kexec: pass initrd position in dtb
kexec: increase zImage compress ratio from 4 to 5

Quoted 7 lines

One question:
Is these kexec-tools patches enough for kexec work or still need the kernel patches you sent?

Thanks
Dave

kexec will work without the kernel side patches, but the atag, kernel cmdline, dtb information and kernel configuration must be carefully adjusted.

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

#10 lore raw
Quoted 16 lines · Wang Nan
Quoted 15 lines · Dave Young
Quoted 9 lines · Wang Nan

Hi,

This patch series contains following bug fixes and cleanups for kexec-tools on arm platform:

Wang Nan (3):
kexec: align initrd when no --image-size
kexec: pass initrd position in dtb
kexec: increase zImage compress ratio from 4 to 5

One question:
Is these kexec-tools patches enough for kexec work or still need the kernel patches you sent?

Quoted 8 lines
Quoted 3 lines

Thanks
Dave

kexec will work without the kernel side patches, but the atag, kernel cmdline, dtb information and kernel configuration must be carefully adjusted.

It does not work for me with below:
kexec -l /boot/vmlinuz-uname -r --append=cat /proc/cmdline --dtb vexpress-v2p-ca9.dtb

The dtb and kexec kernel are exactly same with the 1st kernel.
Is there any other things for setup in qemu, but probably it's different from your hardware setup..

Thanks
Dave

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

author
#11 lore raw
Quoted 29 lines · Dave Young
Quoted 16 lines · Wang Nan
Quoted 15 lines · Dave Young
Quoted 9 lines · Wang Nan

Hi,

This patch series contains following bug fixes and cleanups for kexec-tools on arm platform:

Wang Nan (3):
kexec: align initrd when no --image-size
kexec: pass initrd position in dtb
kexec: increase zImage compress ratio from 4 to 5

One question:
Is these kexec-tools patches enough for kexec work or still need the kernel patches you sent?

Quoted 8 lines
Quoted 3 lines

Thanks
Dave

kexec will work without the kernel side patches, but the atag, kernel cmdline, dtb information and kernel configuration must be carefully adjusted.

It does not work for me with below:
kexec -l /boot/vmlinuz-uname -r --append=cat /proc/cmdline --dtb vexpress-v2p-ca9.dtb

Quoted 7 lines

The dtb and kexec kernel are exactly same with the 1st kernel.
Is there any other things for setup in qemu, but probably it's different from your hardware setup..

Thanks
Dave

I only tried crash dump case. In my testing, following things need to be check:

1. When using dtb, the second kernel should disable CONFIG_ATAGS and CONFIG_ARM_APPENDED_DTB
2. In the second kernel, the memory information must be reconfigured using dtb or cmdline.

for example:

first kernel:
memory {
device_type = "memory";
reg = <0x80000000 0x40000000>;
};

if you want to load the second kernel at 0xa0000000: second kernel:
memory {
device_type = "memory";
reg = <0xa0000000 0x20000000>;
};

Pass a mem= option may also work, but when loading crash kernel, kexec-tools also append mem= option to cmdline, they may conflict with each other.

The 3rd patch of my kernel patch is used to avoid the device tree reconfiguration, but it has not been accepted.

Another thing: arm kernel must be loaded at a 128MB aligned position.

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

#12 lore raw
Quoted 34 lines · Wang Nan
Quoted 33 lines · Dave Young
Quoted 16 lines · Wang Nan
Quoted 15 lines · Dave Young
Quoted 9 lines · Wang Nan

Hi,

This patch series contains following bug fixes and cleanups for kexec-tools on arm platform:

Wang Nan (3):
kexec: align initrd when no --image-size
kexec: pass initrd position in dtb
kexec: increase zImage compress ratio from 4 to 5

One question:
Is these kexec-tools patches enough for kexec work or still need the kernel patches you sent?

Quoted 8 lines
Quoted 3 lines

Thanks
Dave

kexec will work without the kernel side patches, but the atag, kernel cmdline, dtb information and kernel configuration must be carefully adjusted.

It does not work for me with below:
kexec -l /boot/vmlinuz-uname -r --append=cat /proc/cmdline --dtb vexpress-v2p-ca9.dtb

The dtb and kexec kernel are exactly same with the 1st kernel.
Is there any other things for setup in qemu, but probably it's different from your hardware setup..

Quoted 5 lines
Quoted 3 lines

Thanks
Dave

I only tried crash dump case. In my testing, following things need to be check:

Thanks for your suggestion.

Quoted 2 lines

1. When using dtb, the second kernel should disable CONFIG_ATAGS and CONFIG_ARM_APPENDED_DTB

Will try though I think it should be fixed and detected automaticlly.

Quoted 16 lines

2. In the second kernel, the memory information must be reconfigured using dtb or cmdline.

for example:

first kernel:
memory {
device_type = "memory";
reg = <0x80000000 0x40000000>;
};

if you want to load the second kernel at 0xa0000000: second kernel:
memory {
device_type = "memory";
reg = <0xa0000000 0x20000000>;
};

Quoted 5 lines

Pass a mem= option may also work, but when loading crash kernel, kexec-tools also append mem= option to cmdline, they may conflict with each other.

The 3rd patch of my kernel patch is used to avoid the device tree reconfiguration, but it has not been accepted.

Great, will take a look and try your patch.

Thanks
Dave

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