All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 03/71] dm: core: Add livetree definitions
Date: Wed, 10 May 2017 08:20:42 -0600	[thread overview]
Message-ID: <20170510142150.30515-4-sjg@chromium.org> (raw)
In-Reply-To: <20170510142150.30515-1-sjg@chromium.org>

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>
---

Changes in v2: None

 dts/Kconfig                       |  11 ++++
 include/asm-generic/global_data.h |   3 ++
 include/dm/of.h                   | 103 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
 create mode 100644 include/dm/of.h

diff --git a/dts/Kconfig b/dts/Kconfig
index 6fe7a5bc08..4d8e476831 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -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
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 1a77c982fa..28c6cab831 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -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
index 0000000000..102565018e
--- /dev/null
+++ b/include/dm/of.h
@@ -0,0 +1,103 @@
+/*
+ * 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
+
+/* 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 at 1/spi at 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
-- 
2.13.0.rc2.291.g57267f2277-goog

  parent reply	other threads:[~2017-05-10 14:20 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-10 14:20 [U-Boot] [PATCH v2 00/71] dm: Add support for a 'live' device tree Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 01/71] dm: core: Set return value first in lists_bind_fdt() Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 02/71] Update WARN_ON() to return a value Simon Glass
2017-05-10 14:20 ` Simon Glass [this message]
2017-05-10 14:20 ` [U-Boot] [PATCH v2 04/71] dm: core: Add livetree access functions Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 05/71] dm: Add a function to create a 'live' device tree Simon Glass
2017-05-11 14:59   ` Lothar Waßmann
2017-05-15  3:03     ` Simon Glass
2017-05-15  7:34       ` Lothar Waßmann
2017-05-16  0:18         ` Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 06/71] dm: Build a live tree after relocation Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 07/71] dm: core: Rename of_device_is_compatible() Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 08/71] dm: core: Add operations on device tree references Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 09/71] dm: core: Add livetree address functions Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 10/71] fdt: Update fdt_get_base_address() to use const Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 11/71] dm: core: Add address operations on device tree references Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 12/71] dm: core: Add a place to put extra device-tree reading functions Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 13/71] dm: core: Add device-based 'read' functions to access DT Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 14/71] dm: core: Implement live tree 'read' functions Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 15/71] dm: core: Allow binding a device from a live tree Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 16/71] dm: core: Update lists_bind_fdt() to use ofnode Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 17/71] dm: core: Update device_bind_driver_to_node() " Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 18/71] dm: core: Scan the live tree when setting up driver model Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 19/71] dm: core: Add a way to find a device by ofnode Simon Glass
2017-05-10 14:20 ` [U-Boot] [PATCH v2 20/71] dm: regmap: Add support for livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 21/71] dm: simple-bus: " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 22/71] dm: core: Update uclass_find_device_by_phandle() " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 23/71] sandbox: Add a way to reset sandbox state for tests Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 24/71] dm: test: Move test running code into a separate function Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 25/71] dm: test: Show the test filename when running Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 26/71] dm: test: Add support for running tests with livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 27/71] dm: core: Run tests with both livetree and flat tree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 28/71] dm: gpio: Refactor to prepare for live tree support Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 29/71] dm: gpio: Drop blank line in gpio_xlate_offs_flags() comment Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 30/71] dm: gpio: sandbox: Use dev_read...() functions to access DT Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 31/71] dm: gpio: Add live tree support Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 32/71] cros_ec: Fix debug() statement in ec_command_inptr() Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 33/71] cros_ec: Convert to support live tree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 34/71] sandbox: Add a new sandbox_flattree board Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 35/71] test: Update 'make test' to run more tests Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 36/71] fdt: Rename a few functions in fdt_support Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 37/71] dm: Add more livetree helpers and definitions Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 38/71] string: Add strchrnul() Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 39/71] string: Add strcspn() Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 40/71] dm: i2c: Convert uclass to livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 41/71] dm: pmic: " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 42/71] sandbox: pmic: Convert pmic emulator to support livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 43/71] dm: regulator: Convert regulator uclass " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 44/71] dm: regulator: Update fixed regulator " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 45/71] dm: mmc: Convert uclass to livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 46/71] dm: adc: " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 47/71] dm: usb: " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 48/71] sandbox: usb: Convert emulators " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 49/71] clk: Modify xlate() method for livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 50/71] dm: clk: Update uclass to support livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 51/71] dm: clk: fixed: Update " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 52/71] dm: test: Separate out the bus DT offset test Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 53/71] dm: test: Disable the fdt_offset test with livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 54/71] dm: phy: Update tests to use ut_asserteq() Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 55/71] dm: mailbox: Update uclass to support livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 56/71] dm: phy: " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 57/71] sandbox: phy: Update driver for livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 58/71] dm: power-domain: Update uclass to support livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 59/71] dm: reset: " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 60/71] dm: pci: " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 61/71] dm: Update the I2C eeprom driver for livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 62/71] cros_ec: Update the cros_ec keyboard driver to livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 63/71] dm: spi: Convert uclass " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 64/71] dm: sandbox: i2c: Drop fdtdec.h header Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 65/71] dm: sandbox: i2c_rtc: " Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 66/71] dm: spi-flash: Convert uclass to livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 67/71] dm: sandbox: spi: Convert driver to support livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 68/71] dm: sandbox: sysreset: Convert driver to livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 69/71] dm: test: Fix nit with position of backslash Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 70/71] dm: gpio: power: Convert pm8916 drivers to livetree Simon Glass
2017-05-10 14:21 ` [U-Boot] [PATCH v2 71/71] sandbox: Move to use live tree Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170510142150.30515-4-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.