|
|
a6d77e |
From 1fb6841aa15407dbf371589d7abca7bc2d35815c Mon Sep 17 00:00:00 2001
|
|
|
a6d77e |
Message-Id: <1fb6841aa15407dbf371589d7abca7bc2d35815c.1431592766.git.panand@redhat.com>
|
|
|
a6d77e |
From: Geoff Levand <geoff@infradead.org>
|
|
|
a6d77e |
Date: Fri, 17 Apr 2015 10:54:55 -0700
|
|
|
a6d77e |
Subject: [PATCH 01/17] kexec: Add common device tree routines
|
|
|
a6d77e |
|
|
|
a6d77e |
Signed-off-by: Geoff Levand <geoff@infradead.org>
|
|
|
a6d77e |
---
|
|
|
a6d77e |
kexec/Makefile | 4 ++
|
|
|
a6d77e |
kexec/dt-ops.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
a6d77e |
kexec/dt-ops.h | 13 ++++++
|
|
|
a6d77e |
3 files changed, 153 insertions(+)
|
|
|
a6d77e |
create mode 100644 kexec/dt-ops.c
|
|
|
a6d77e |
create mode 100644 kexec/dt-ops.h
|
|
|
a6d77e |
|
|
|
a6d77e |
diff --git a/kexec/Makefile b/kexec/Makefile
|
|
|
a6d77e |
index a758b4aae13a..6937a4dbb38b 100644
|
|
|
a6d77e |
--- a/kexec/Makefile
|
|
|
a6d77e |
+++ b/kexec/Makefile
|
|
|
a6d77e |
@@ -69,6 +69,10 @@ dist += kexec/fs2dt.c kexec/fs2dt.h
|
|
|
a6d77e |
$(ARCH)_FS2DT =
|
|
|
a6d77e |
KEXEC_SRCS += $($(ARCH)_FS2DT)
|
|
|
a6d77e |
|
|
|
a6d77e |
+dist += kexec/dt-ops.c kexec/dt-ops.h
|
|
|
a6d77e |
+$(ARCH)_DT_OPS =
|
|
|
a6d77e |
+KEXEC_SRCS += $($(ARCH)_DT_OPS)
|
|
|
a6d77e |
+
|
|
|
a6d77e |
include $(srcdir)/kexec/arch/alpha/Makefile
|
|
|
a6d77e |
include $(srcdir)/kexec/arch/arm/Makefile
|
|
|
a6d77e |
include $(srcdir)/kexec/arch/i386/Makefile
|
|
|
a6d77e |
diff --git a/kexec/dt-ops.c b/kexec/dt-ops.c
|
|
|
a6d77e |
new file mode 100644
|
|
|
a6d77e |
index 000000000000..bbba986cfbb4
|
|
|
a6d77e |
--- /dev/null
|
|
|
a6d77e |
+++ b/kexec/dt-ops.c
|
|
|
a6d77e |
@@ -0,0 +1,136 @@
|
|
|
a6d77e |
+#include <assert.h>
|
|
|
a6d77e |
+#include <errno.h>
|
|
|
a6d77e |
+#include <inttypes.h>
|
|
|
a6d77e |
+#include <libfdt.h>
|
|
|
a6d77e |
+#include <stdio.h>
|
|
|
a6d77e |
+#include <stdlib.h>
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+#include "kexec.h"
|
|
|
a6d77e |
+#include "dt-ops.h"
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+static const char n_chosen[] = "/chosen";
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+static const char p_bootargs[] = "bootargs";
|
|
|
a6d77e |
+static const char p_initrd_start[] = "linux,initrd-start";
|
|
|
a6d77e |
+static const char p_initrd_end[] = "linux,initrd-end";
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+int dtb_set_initrd(char **dtb, off_t *dtb_size, off_t start, off_t end)
|
|
|
a6d77e |
+{
|
|
|
a6d77e |
+ int result;
|
|
|
a6d77e |
+ uint64_t value;
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ dbgprintf("%s: start %jd, end %jd, size %jd (%jd KiB)\n",
|
|
|
a6d77e |
+ __func__, (intmax_t)start, (intmax_t)end,
|
|
|
a6d77e |
+ (intmax_t)(end - start),
|
|
|
a6d77e |
+ (intmax_t)(end - start) / 1024);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ value = cpu_to_fdt64(start);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ result = dtb_set_property(dtb, dtb_size, n_chosen, p_initrd_start,
|
|
|
a6d77e |
+ &value, sizeof(value));
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ if (result)
|
|
|
a6d77e |
+ return result;
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ value = cpu_to_fdt64(end);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ result = dtb_set_property(dtb, dtb_size, n_chosen, p_initrd_end,
|
|
|
a6d77e |
+ &value, sizeof(value));
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ if (result) {
|
|
|
a6d77e |
+ dtb_delete_property(*dtb, n_chosen, p_initrd_start);
|
|
|
a6d77e |
+ return result;
|
|
|
a6d77e |
+ }
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ return 0;
|
|
|
a6d77e |
+}
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+int dtb_set_bootargs(char **dtb, off_t *dtb_size, const char *command_line)
|
|
|
a6d77e |
+{
|
|
|
a6d77e |
+ return dtb_set_property(dtb, dtb_size, n_chosen, p_bootargs,
|
|
|
a6d77e |
+ command_line, strlen(command_line) + 1);
|
|
|
a6d77e |
+}
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
|
|
|
a6d77e |
+ const char *prop, const void *value, int value_len)
|
|
|
a6d77e |
+{
|
|
|
a6d77e |
+ int result;
|
|
|
a6d77e |
+ int nodeoffset;
|
|
|
a6d77e |
+ void *new_dtb;
|
|
|
a6d77e |
+ int new_size;
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ value_len = FDT_TAGALIGN(value_len);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ new_size = FDT_TAGALIGN(*dtb_size + fdt_node_len(node)
|
|
|
a6d77e |
+ + fdt_prop_len(prop, value_len));
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ new_dtb = malloc(new_size);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ if (!new_dtb) {
|
|
|
a6d77e |
+ dbgprintf("%s: malloc failed\n", __func__);
|
|
|
a6d77e |
+ return -ENOMEM;
|
|
|
a6d77e |
+ }
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ result = fdt_open_into(*dtb, new_dtb, new_size);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ if (result) {
|
|
|
a6d77e |
+ dbgprintf("%s: fdt_open_into failed: %s\n", __func__,
|
|
|
a6d77e |
+ fdt_strerror(result));
|
|
|
a6d77e |
+ goto on_error;
|
|
|
a6d77e |
+ }
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ nodeoffset = fdt_path_offset(new_dtb, node);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ if (nodeoffset == -FDT_ERR_NOTFOUND) {
|
|
|
a6d77e |
+ result = fdt_add_subnode(new_dtb, nodeoffset, node);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ if (result) {
|
|
|
a6d77e |
+ dbgprintf("%s: fdt_add_subnode failed: %s\n", __func__,
|
|
|
a6d77e |
+ fdt_strerror(result));
|
|
|
a6d77e |
+ goto on_error;
|
|
|
a6d77e |
+ }
|
|
|
a6d77e |
+ } else if (nodeoffset < 0) {
|
|
|
a6d77e |
+ dbgprintf("%s: fdt_path_offset failed: %s\n", __func__,
|
|
|
a6d77e |
+ fdt_strerror(nodeoffset));
|
|
|
a6d77e |
+ goto on_error;
|
|
|
a6d77e |
+ }
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ result = fdt_setprop(new_dtb, nodeoffset, prop, value, value_len);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ if (result) {
|
|
|
a6d77e |
+ dbgprintf("%s: fdt_setprop failed: %s\n", __func__,
|
|
|
a6d77e |
+ fdt_strerror(result));
|
|
|
a6d77e |
+ goto on_error;
|
|
|
a6d77e |
+ }
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ free(*dtb);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ *dtb = new_dtb;
|
|
|
a6d77e |
+ *dtb_size = new_size;
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ return 0;
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+on_error:
|
|
|
a6d77e |
+ free(new_dtb);
|
|
|
a6d77e |
+ return result;
|
|
|
a6d77e |
+}
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+int dtb_delete_property(char *dtb, const char *node, const char *prop)
|
|
|
a6d77e |
+{
|
|
|
a6d77e |
+ int result;
|
|
|
a6d77e |
+ int nodeoffset = fdt_path_offset(dtb, node);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ if (nodeoffset < 0) {
|
|
|
a6d77e |
+ dbgprintf("%s: fdt_path_offset failed: %s\n", __func__,
|
|
|
a6d77e |
+ fdt_strerror(nodeoffset));
|
|
|
a6d77e |
+ return nodeoffset;
|
|
|
a6d77e |
+ }
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ result = fdt_delprop(dtb, nodeoffset, prop);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ if (result)
|
|
|
a6d77e |
+ dbgprintf("%s: fdt_delprop failed: %s\n", __func__,
|
|
|
a6d77e |
+ fdt_strerror(nodeoffset));
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+ return result;
|
|
|
a6d77e |
+}
|
|
|
a6d77e |
diff --git a/kexec/dt-ops.h b/kexec/dt-ops.h
|
|
|
a6d77e |
new file mode 100644
|
|
|
a6d77e |
index 000000000000..e70d15d8ffbf
|
|
|
a6d77e |
--- /dev/null
|
|
|
a6d77e |
+++ b/kexec/dt-ops.h
|
|
|
a6d77e |
@@ -0,0 +1,13 @@
|
|
|
a6d77e |
+#if !defined(KEXEC_DT_OPS_H)
|
|
|
a6d77e |
+#define KEXEC_DT_OPS_H
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+#include <sys/types.h>
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+int dtb_set_initrd(char **dtb, off_t *dtb_size, off_t start, off_t end);
|
|
|
a6d77e |
+int dtb_set_bootargs(char **dtb, off_t *dtb_size, const char *command_line);
|
|
|
a6d77e |
+int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
|
|
|
a6d77e |
+ const char *prop, const void *value, int value_len);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+int dtb_delete_property(char *dtb, const char *node, const char *prop);
|
|
|
a6d77e |
+
|
|
|
a6d77e |
+#endif
|
|
|
a6d77e |
--
|
|
|
a6d77e |
2.1.0
|
|
|
a6d77e |
|