]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
dm: core: Add livetree definitions
authorSimon Glass <sjg@chromium.org>
Fri, 19 May 2017 02:08:53 +0000 (20:08 -0600)
committerSimon Glass <sjg@chromium.org>
Thu, 1 Jun 2017 13:03:06 +0000 (07:03 -0600)
Add a Kconfig option to enable a live device tree, built at run time from
the flat tree. Also add structure definitions and a root node.

Signed-off-by: Simon Glass <sjg@chromium.org>
dts/Kconfig
include/asm-generic/global_data.h
include/dm/of.h [new file with mode: 0644]

index 9a0622154ad0befb28ba76509b6a310e7dfe089d..b3009af03f593e1fe10de352150b050b0ab24c88 100644 (file)
@@ -32,6 +32,17 @@ config SPL_OF_CONTROL
          which is not enough to support device tree. Enable this option to
          allow such boards to be supported by U-Boot SPL.
 
+config OF_LIVE
+       bool "Enable use of a live tree"
+       depends on OF_CONTROL
+       help
+         Normally U-Boot uses a flat device tree which saves space and
+         avoids the need to unpack the tree before use. However a flat
+         tree does not support modifcation from within U-Boot since it
+         can invalidate driver-model device tree offsets. This option
+         enables a live tree which is available after relocation,
+         and can be adjusted as needed.
+
 choice
        prompt "Provider of DTB for DT control"
        depends on OF_CONTROL
index 51838b5ead6631cc601509046eec53bc9664bbd3..e6f905110e3adec84b6067ca694b3dd6953ada72 100644 (file)
@@ -72,6 +72,9 @@ typedef struct global_data {
        const void *fdt_blob;           /* Our device tree, NULL if none */
        void *new_fdt;                  /* Relocated FDT */
        unsigned long fdt_size;         /* Space reserved for relocated FDT */
+#ifdef CONFIG_OF_LIVE
+       struct device_node *of_root;
+#endif
        struct jt_funcs *jt;            /* jump table */
        char env_buf[32];               /* buffer for getenv() before reloc. */
 #ifdef CONFIG_TRACE
diff --git a/include/dm/of.h b/include/dm/of.h
new file mode 100644 (file)
index 0000000..6b5afab
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2017 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef _DM_OF_H
+#define _DM_OF_H
+
+#include <asm/u-boot.h>
+#include <asm/global_data.h>
+
+/* integer value within a device tree property which references another node */
+typedef u32 phandle;
+
+/**
+ * struct property: Device tree property
+ *
+ * @name: Property name
+ * @length: Length of property in bytes
+ * @value: Pointer to property value
+ * @next: Pointer to next property, or NULL if none
+ */
+struct property {
+       char *name;
+       int length;
+       void *value;
+       struct property *next;
+};
+
+/**
+ * struct device_node: Device tree node
+ *
+ * @name: Node name
+ * @type: Node type (value of device_type property) or "<NULL>" if none
+ * @phandle: Phandle value of this none, or 0 if none
+ * @full_name: Full path to node, e.g. "/bus@1/spi@1100"
+ * @properties: Pointer to head of list of properties, or NULL if none
+ * @parent: Pointer to parent node, or NULL if this is the root node
+ * @child: Pointer to head of child node list, or NULL if no children
+ * @sibling: Pointer to the next sibling node, or NULL if this is the last
+ */
+struct device_node {
+       const char *name;
+       const char *type;
+       phandle phandle;
+       const char *full_name;
+
+       struct property *properties;
+       struct device_node *parent;
+       struct device_node *child;
+       struct device_node *sibling;
+};
+
+#define OF_MAX_PHANDLE_ARGS 16
+
+/**
+ * struct of_phandle_args - structure to hold phandle and arguments
+ *
+ * This is used when decoding a phandle in a device tree property. Typically
+ * these look like this:
+ *
+ * wibble {
+ *    phandle = <5>;
+ * };
+ *
+ * ...
+ * some-prop = <&wibble 1 2 3>
+ *
+ * Here &node is the phandle of the node 'wibble', i.e. 5. There are three
+ * arguments: 1, 2, 3.
+ *
+ * So when decoding the phandle in some-prop, np will point to wibble,
+ * args_count will be 3 and the three arguments will be in args.
+ *
+ * @np: Node that the phandle refers to
+ * @args_count: Number of arguments
+ * @args: Argument values
+ */
+struct of_phandle_args {
+       struct device_node *np;
+       int args_count;
+       uint32_t args[OF_MAX_PHANDLE_ARGS];
+};
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/**
+ * of_live_active() - check if livetree is active
+ *
+ * @returns true if livetree is active, false it not
+ */
+#ifdef CONFIG_OF_LIVE
+static inline bool of_live_active(void)
+{
+       return gd->of_root != NULL;
+}
+#else
+static inline bool of_live_active(void)
+{
+       return false;
+}
+#endif
+
+#endif