* [PATCH 0/3] kexec: pass initrd position in dtb
@ 2014-03-25 4:09 Wang Nan
2014-03-25 4:09 ` [PATCH 1/3] kexec: introduce helpers for computing dtb size Wang Nan
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Wang Nan @ 2014-03-25 4:09 UTC (permalink / raw)
To: Dave Young; +Cc: Wang Nan, Simon Horman, kexec, Geng Hui
The main goal of this patch series is to pass initrd position to
secondary kernel. To makes code clear, patch 2/3 introduce a new
function to handle fdt related operations.
Without these two patches, kexec failed to work on arm.
Change from v1:
- Remove #include "libfdt_internal.h" since it is for internal use
for libfdt.
Change from v2:
- Split into two logically independent patches.
- Compute memory consumption more accurate.
Change from v3:
- Introduces helpers in libfdt for memory usage computation.
Wang Nan (3):
kexec: introduce helpers for computing dtb size
kexec: introduce setup_dtb_prop to make code clear
kexec: pass initrd position by dtb
kexec/arch/arm/kexec-zImage-arm.c | 106 +++++++++++++++++++++++++++++---------
kexec/libfdt/libfdt.h | 24 +++++++++
kexec/libfdt/libfdt_internal.h | 3 --
3 files changed, 105 insertions(+), 28 deletions(-)
--
1.8.4
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] kexec: introduce helpers for computing dtb size
2014-03-25 4:09 [PATCH 0/3] kexec: pass initrd position in dtb Wang Nan
@ 2014-03-25 4:09 ` Wang Nan
2014-03-25 4:09 ` [PATCH 2/3] kexec: introduce setup_dtb_prop to make code clear Wang Nan
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Wang Nan @ 2014-03-25 4:09 UTC (permalink / raw)
To: Dave Young; +Cc: Wang Nan, Simon Horman, kexec, Geng Hui
This patch introduce fdt_node_len and fdt_prop_len to help for computing
memory requirement when operating dtb.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Simon Horman <horms@verge.net.au>
Cc: Dave Young <dyoung@redhat.com>
Cc: Geng Hui <hui.geng@huawei.com>
---
kexec/libfdt/libfdt.h | 24 ++++++++++++++++++++++++
kexec/libfdt/libfdt_internal.h | 3 ---
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/kexec/libfdt/libfdt.h b/kexec/libfdt/libfdt.h
index ce80e4f..87a24ab 100644
--- a/kexec/libfdt/libfdt.h
+++ b/kexec/libfdt/libfdt.h
@@ -1073,4 +1073,28 @@ int fdt_del_node(void *fdt, int nodeoffset);
const char *fdt_strerror(int errval);
+#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
+#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE))
+
+/*
+ * if add a new subnode:
+ * see: fdt_add_subnode -> fdt_add_subnode_namelen
+ */
+static inline int fdt_node_len(const char* node_name)
+{
+ return sizeof(struct fdt_node_header) +
+ FDT_TAGALIGN(strlen(node_name) + 1) + FDT_TAGSIZE;
+}
+
+/*
+ * if add a new prop: (assume prop_name not exist in strtab)
+ * see: fdt_setprop -> _fdt_add_property
+ */
+static inline int fdt_prop_len(const char* prop_name, int len)
+{
+ return (strlen(prop_name) + 1) +
+ sizeof(struct fdt_property) +
+ FDT_TAGALIGN(len);
+}
+
#endif /* _LIBFDT_H */
diff --git a/kexec/libfdt/libfdt_internal.h b/kexec/libfdt/libfdt_internal.h
index 46eb93e..7e6c4c8 100644
--- a/kexec/libfdt/libfdt_internal.h
+++ b/kexec/libfdt/libfdt_internal.h
@@ -52,9 +52,6 @@
*/
#include <fdt.h>
-#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
-#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE))
-
#define FDT_CHECK_HEADER(fdt) \
{ \
int err; \
--
1.8.4
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] kexec: introduce setup_dtb_prop to make code clear
2014-03-25 4:09 [PATCH 0/3] kexec: pass initrd position in dtb Wang Nan
2014-03-25 4:09 ` [PATCH 1/3] kexec: introduce helpers for computing dtb size Wang Nan
@ 2014-03-25 4:09 ` Wang Nan
2014-03-25 4:09 ` [PATCH 3/3] kexec: pass initrd position by dtb Wang Nan
2014-03-27 1:14 ` [PATCH 0/3] kexec: pass initrd position in dtb Dave Young
3 siblings, 0 replies; 6+ messages in thread
From: Wang Nan @ 2014-03-25 4:09 UTC (permalink / raw)
To: Dave Young; +Cc: Wang Nan, Simon Horman, kexec, Geng Hui
This patch introduces setup_dtb_prop(), which is used for dtb operations. The
code is extracted from zImage_arm_load, and this patch makes memory grown
computation more accurate.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Simon Horman <horms@verge.net.au>
Cc: Dave Young <dyoung@redhat.com>
Cc: Geng Hui <hui.geng@huawei.com>
---
kexec/arch/arm/kexec-zImage-arm.c | 93 ++++++++++++++++++++++++++++-----------
1 file changed, 68 insertions(+), 25 deletions(-)
diff --git a/kexec/arch/arm/kexec-zImage-arm.c b/kexec/arch/arm/kexec-zImage-arm.c
index 8a35018..aea1278 100644
--- a/kexec/arch/arm/kexec-zImage-arm.c
+++ b/kexec/arch/arm/kexec-zImage-arm.c
@@ -216,6 +216,67 @@ int atag_arm_load(struct kexec_info *info, unsigned long base,
return 0;
}
+static int setup_dtb_prop(char **bufp, off_t *sizep, const char *node_name,
+ const char *prop_name, const void *val, int len)
+{
+ char *dtb_buf;
+ off_t dtb_size;
+ int off;
+ int prop_len = 0;
+ const struct fdt_property *prop;
+
+ if ((bufp == NULL) || (sizep == NULL) || (*bufp == NULL))
+ die("Internal error\n");
+
+ dtb_buf = *bufp;
+ dtb_size = *sizep;
+
+ /* check if the subnode has already exist */
+ off = fdt_path_offset(dtb_buf, node_name);
+ if (off == -FDT_ERR_NOTFOUND) {
+ dtb_size += fdt_node_len(node_name);
+ fdt_set_totalsize(dtb_buf, dtb_size);
+ dtb_buf = xrealloc(dtb_buf, dtb_size);
+ if (dtb_buf == NULL)
+ die("xrealloc failed\n");
+ off = fdt_add_subnode(dtb_buf, off, node_name);
+ }
+
+ if (off < 0) {
+ fprintf(stderr, "FDT: Error adding %s node.\n", node_name);
+ return -1;
+ }
+
+ prop = fdt_get_property(dtb_buf, off, prop_name, &prop_len);
+ if ((prop == NULL) && (prop_len != -FDT_ERR_NOTFOUND)) {
+ die("FDT: fdt_get_property");
+ } else if (prop == NULL) {
+ /* prop_len == -FDT_ERR_NOTFOUND */
+ /* prop doesn't exist */
+ dtb_size += fdt_prop_len(prop_name, len);
+ } else {
+ if (prop_len < len)
+ dtb_size += len - prop_len;
+ }
+
+ if (fdt_totalsize(dtb_buf) < dtb_size) {
+ fdt_set_totalsize(dtb_buf, dtb_size);
+ dtb_buf = xrealloc(dtb_buf, dtb_size);
+ if (dtb_buf == NULL)
+ die("xrealloc failed\n");
+ }
+
+ if (fdt_setprop(dtb_buf, off, prop_name,
+ val, len) != 0) {
+ fprintf(stderr, "FDT: Error setting %s/%s property.\n",
+ node_name, prop_name);
+ return -1;
+ }
+ *bufp = dtb_buf;
+ *sizep = dtb_size;
+ return 0;
+}
+
int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
struct kexec_info *info)
{
@@ -375,32 +436,14 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
}
if (command_line) {
- const char *node_name = "/chosen";
- const char *prop_name = "bootargs";
- int off;
-
- dtb_length = fdt_totalsize(dtb_buf) + 1024 +
- strlen(command_line);
- 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;
- }
-
- if (fdt_setprop(dtb_buf, off, prop_name,
- command_line, strlen(command_line) + 1) != 0) {
- fprintf(stderr, "FDT: Error setting %s/%s property.\n",
- node_name, prop_name);
+ /*
+ * Error should have been reported so
+ * directly return -1
+ */
+ if (setup_dtb_prop(&dtb_buf, &dtb_length, "/chosen",
+ "bootargs", command_line,
+ strlen(command_line) + 1))
return -1;
- }
}
} else {
/*
--
1.8.4
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] kexec: pass initrd position by dtb
2014-03-25 4:09 [PATCH 0/3] kexec: pass initrd position in dtb Wang Nan
2014-03-25 4:09 ` [PATCH 1/3] kexec: introduce helpers for computing dtb size Wang Nan
2014-03-25 4:09 ` [PATCH 2/3] kexec: introduce setup_dtb_prop to make code clear Wang Nan
@ 2014-03-25 4:09 ` Wang Nan
2014-03-27 1:14 ` [PATCH 0/3] kexec: pass initrd position in dtb Dave Young
3 siblings, 0 replies; 6+ messages in thread
From: Wang Nan @ 2014-03-25 4:09 UTC (permalink / raw)
To: Dave Young; +Cc: Wang Nan, Simon Horman, kexec, Geng Hui
This patch append the position of initrd to dtb when loading arm kernel
and initrd without using atag.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Simon Horman <horms@verge.net.au>
Cc: Dave Young <dyoung@redhat.com>
Cc: Geng Hui <hui.geng@huawei.com>
---
kexec/arch/arm/kexec-zImage-arm.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/kexec/arch/arm/kexec-zImage-arm.c b/kexec/arch/arm/kexec-zImage-arm.c
index aea1278..bfbf290 100644
--- a/kexec/arch/arm/kexec-zImage-arm.c
+++ b/kexec/arch/arm/kexec-zImage-arm.c
@@ -460,6 +460,19 @@ 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);
+
+ unsigned long start, end;
+ start = cpu_to_be32((unsigned long)(initrd_base));
+ end = cpu_to_be32((unsigned long)(initrd_base + initrd_size));
+
+ if (setup_dtb_prop(&dtb_buf, &dtb_length, "/chosen",
+ "linux,initrd-start", &start,
+ sizeof(start)))
+ return -1;
+ if (setup_dtb_prop(&dtb_buf, &dtb_length, "/chosen",
+ "linux,initrd-end", &end,
+ sizeof(end)))
+ return -1;
}
/* Stick the dtb at the end of the initrd and page
--
1.8.4
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] kexec: pass initrd position in dtb
2014-03-25 4:09 [PATCH 0/3] kexec: pass initrd position in dtb Wang Nan
` (2 preceding siblings ...)
2014-03-25 4:09 ` [PATCH 3/3] kexec: pass initrd position by dtb Wang Nan
@ 2014-03-27 1:14 ` Dave Young
2014-03-28 16:49 ` Simon Horman
3 siblings, 1 reply; 6+ messages in thread
From: Dave Young @ 2014-03-27 1:14 UTC (permalink / raw)
To: Wang Nan; +Cc: Simon Horman, kexec, Geng Hui
On 03/25/14 at 12:09pm, Wang Nan wrote:
> The main goal of this patch series is to pass initrd position to
> secondary kernel. To makes code clear, patch 2/3 introduce a new
> function to handle fdt related operations.
>
> Without these two patches, kexec failed to work on arm.
>
>
> Change from v1:
>
> - Remove #include "libfdt_internal.h" since it is for internal use
> for libfdt.
>
> Change from v2:
>
> - Split into two logically independent patches.
> - Compute memory consumption more accurate.
>
> Change from v3:
>
> - Introduces helpers in libfdt for memory usage computation.
>
>
> Wang Nan (3):
> kexec: introduce helpers for computing dtb size
> kexec: introduce setup_dtb_prop to make code clear
> kexec: pass initrd position by dtb
>
> kexec/arch/arm/kexec-zImage-arm.c | 106 +++++++++++++++++++++++++++++---------
> kexec/libfdt/libfdt.h | 24 +++++++++
> kexec/libfdt/libfdt_internal.h | 3 --
> 3 files changed, 105 insertions(+), 28 deletions(-)
>
Thanks for the update.
Acked-by: Dave Young <dyoung@redhat.com>
Thanks
Dave
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] kexec: pass initrd position in dtb
2014-03-27 1:14 ` [PATCH 0/3] kexec: pass initrd position in dtb Dave Young
@ 2014-03-28 16:49 ` Simon Horman
0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2014-03-28 16:49 UTC (permalink / raw)
To: Dave Young; +Cc: Wang Nan, kexec, Geng Hui
On Thu, Mar 27, 2014 at 09:14:34AM +0800, Dave Young wrote:
> On 03/25/14 at 12:09pm, Wang Nan wrote:
> > The main goal of this patch series is to pass initrd position to
> > secondary kernel. To makes code clear, patch 2/3 introduce a new
> > function to handle fdt related operations.
> >
> > Without these two patches, kexec failed to work on arm.
> >
> >
> > Change from v1:
> >
> > - Remove #include "libfdt_internal.h" since it is for internal use
> > for libfdt.
> >
> > Change from v2:
> >
> > - Split into two logically independent patches.
> > - Compute memory consumption more accurate.
> >
> > Change from v3:
> >
> > - Introduces helpers in libfdt for memory usage computation.
> >
> >
> > Wang Nan (3):
> > kexec: introduce helpers for computing dtb size
> > kexec: introduce setup_dtb_prop to make code clear
> > kexec: pass initrd position by dtb
> >
> > kexec/arch/arm/kexec-zImage-arm.c | 106 +++++++++++++++++++++++++++++---------
> > kexec/libfdt/libfdt.h | 24 +++++++++
> > kexec/libfdt/libfdt_internal.h | 3 --
> > 3 files changed, 105 insertions(+), 28 deletions(-)
> >
>
> Thanks for the update.
>
> Acked-by: Dave Young <dyoung@redhat.com>
Thanks, applied.
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-03-28 16:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-25 4:09 [PATCH 0/3] kexec: pass initrd position in dtb Wang Nan
2014-03-25 4:09 ` [PATCH 1/3] kexec: introduce helpers for computing dtb size Wang Nan
2014-03-25 4:09 ` [PATCH 2/3] kexec: introduce setup_dtb_prop to make code clear Wang Nan
2014-03-25 4:09 ` [PATCH 3/3] kexec: pass initrd position by dtb Wang Nan
2014-03-27 1:14 ` [PATCH 0/3] kexec: pass initrd position in dtb Dave Young
2014-03-28 16:49 ` Simon Horman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox