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

Wang Nan wangnan0 at huawei.com
Wed Jan 22 05:52:03 EST 2014


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

Signed-off-by: Wang Nan <wangnan0 at huawei.com>
Cc: Simon Horman <horms at verge.net.au>
Cc: Dave Young <dyoung at redhat.com>
Cc: Geng Hui <hui.geng at huawei.com>
---
 kexec/arch/arm/kexec-zImage-arm.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/kexec/arch/arm/kexec-zImage-arm.c b/kexec/arch/arm/kexec-zImage-arm.c
index 4547765..6d6b239 100644
--- a/kexec/arch/arm/kexec-zImage-arm.c
+++ b/kexec/arch/arm/kexec-zImage-arm.c
@@ -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
-- 
1.8.4




More information about the kexec mailing list