Commit 5e060d8bcca86dd4b88af607396a96cf6c557ca7
1 parent
fd7029029f
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
dm: core: Add livetree definitions
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>
Showing 3 changed files with 120 additions and 0 deletions Side-by-side Diff
dts/Kconfig
... | ... | @@ -32,6 +32,17 @@ |
32 | 32 | which is not enough to support device tree. Enable this option to |
33 | 33 | allow such boards to be supported by U-Boot SPL. |
34 | 34 | |
35 | +config OF_LIVE | |
36 | + bool "Enable use of a live tree" | |
37 | + depends on OF_CONTROL | |
38 | + help | |
39 | + Normally U-Boot uses a flat device tree which saves space and | |
40 | + avoids the need to unpack the tree before use. However a flat | |
41 | + tree does not support modifcation from within U-Boot since it | |
42 | + can invalidate driver-model device tree offsets. This option | |
43 | + enables a live tree which is available after relocation, | |
44 | + and can be adjusted as needed. | |
45 | + | |
35 | 46 | choice |
36 | 47 | prompt "Provider of DTB for DT control" |
37 | 48 | depends on OF_CONTROL |
include/asm-generic/global_data.h
... | ... | @@ -72,6 +72,9 @@ |
72 | 72 | const void *fdt_blob; /* Our device tree, NULL if none */ |
73 | 73 | void *new_fdt; /* Relocated FDT */ |
74 | 74 | unsigned long fdt_size; /* Space reserved for relocated FDT */ |
75 | +#ifdef CONFIG_OF_LIVE | |
76 | + struct device_node *of_root; | |
77 | +#endif | |
75 | 78 | struct jt_funcs *jt; /* jump table */ |
76 | 79 | char env_buf[32]; /* buffer for getenv() before reloc. */ |
77 | 80 | #ifdef CONFIG_TRACE |
include/dm/of.h
1 | +/* | |
2 | + * Copyright (c) 2017 Google, Inc | |
3 | + * Written by Simon Glass <sjg@chromium.org> | |
4 | + * | |
5 | + * SPDX-License-Identifier: GPL-2.0+ | |
6 | + */ | |
7 | + | |
8 | +#ifndef _DM_OF_H | |
9 | +#define _DM_OF_H | |
10 | + | |
11 | +#include <asm/u-boot.h> | |
12 | +#include <asm/global_data.h> | |
13 | + | |
14 | +/* integer value within a device tree property which references another node */ | |
15 | +typedef u32 phandle; | |
16 | + | |
17 | +/** | |
18 | + * struct property: Device tree property | |
19 | + * | |
20 | + * @name: Property name | |
21 | + * @length: Length of property in bytes | |
22 | + * @value: Pointer to property value | |
23 | + * @next: Pointer to next property, or NULL if none | |
24 | + */ | |
25 | +struct property { | |
26 | + char *name; | |
27 | + int length; | |
28 | + void *value; | |
29 | + struct property *next; | |
30 | +}; | |
31 | + | |
32 | +/** | |
33 | + * struct device_node: Device tree node | |
34 | + * | |
35 | + * @name: Node name | |
36 | + * @type: Node type (value of device_type property) or "<NULL>" if none | |
37 | + * @phandle: Phandle value of this none, or 0 if none | |
38 | + * @full_name: Full path to node, e.g. "/bus@1/spi@1100" | |
39 | + * @properties: Pointer to head of list of properties, or NULL if none | |
40 | + * @parent: Pointer to parent node, or NULL if this is the root node | |
41 | + * @child: Pointer to head of child node list, or NULL if no children | |
42 | + * @sibling: Pointer to the next sibling node, or NULL if this is the last | |
43 | + */ | |
44 | +struct device_node { | |
45 | + const char *name; | |
46 | + const char *type; | |
47 | + phandle phandle; | |
48 | + const char *full_name; | |
49 | + | |
50 | + struct property *properties; | |
51 | + struct device_node *parent; | |
52 | + struct device_node *child; | |
53 | + struct device_node *sibling; | |
54 | +}; | |
55 | + | |
56 | +#define OF_MAX_PHANDLE_ARGS 16 | |
57 | + | |
58 | +/** | |
59 | + * struct of_phandle_args - structure to hold phandle and arguments | |
60 | + * | |
61 | + * This is used when decoding a phandle in a device tree property. Typically | |
62 | + * these look like this: | |
63 | + * | |
64 | + * wibble { | |
65 | + * phandle = <5>; | |
66 | + * }; | |
67 | + * | |
68 | + * ... | |
69 | + * some-prop = <&wibble 1 2 3> | |
70 | + * | |
71 | + * Here &node is the phandle of the node 'wibble', i.e. 5. There are three | |
72 | + * arguments: 1, 2, 3. | |
73 | + * | |
74 | + * So when decoding the phandle in some-prop, np will point to wibble, | |
75 | + * args_count will be 3 and the three arguments will be in args. | |
76 | + * | |
77 | + * @np: Node that the phandle refers to | |
78 | + * @args_count: Number of arguments | |
79 | + * @args: Argument values | |
80 | + */ | |
81 | +struct of_phandle_args { | |
82 | + struct device_node *np; | |
83 | + int args_count; | |
84 | + uint32_t args[OF_MAX_PHANDLE_ARGS]; | |
85 | +}; | |
86 | + | |
87 | +DECLARE_GLOBAL_DATA_PTR; | |
88 | + | |
89 | +/** | |
90 | + * of_live_active() - check if livetree is active | |
91 | + * | |
92 | + * @returns true if livetree is active, false it not | |
93 | + */ | |
94 | +#ifdef CONFIG_OF_LIVE | |
95 | +static inline bool of_live_active(void) | |
96 | +{ | |
97 | + return gd->of_root != NULL; | |
98 | +} | |
99 | +#else | |
100 | +static inline bool of_live_active(void) | |
101 | +{ | |
102 | + return false; | |
103 | +} | |
104 | +#endif | |
105 | + | |
106 | +#endif |