aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dtc/dtc.h
diff options
context:
space:
mode:
authorJohn Bonesio <bones@secretlab.ca>2010-11-17 18:28:20 -0500
committerGrant Likely <grant.likely@secretlab.ca>2011-01-03 18:02:49 -0500
commit658f29a51e9830e620bb9a1ce3534b318a38bfeb (patch)
treee6cc7cd9b9e17d97308619fd8516b77bcc038114 /scripts/dtc/dtc.h
parentcd1e65044d4473cca9a01bae7b7938f065044a4b (diff)
of/flattree: Update dtc to current mainline.
Pull in recent changes from the main dtc repository. These changes primarily allow multiple device trees to be declared which are merged by dtc. This feature allows us to include a basic dts file and then provide more information for the specific system through the merging functionality. Changes pulled from git://git.jdl.com/software/dtc.git commit id: 37c0b6a0, "dtc: Add code to make diffing trees easier" Signed-off-by: John Bonesio <bones@secretlab.ca> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'scripts/dtc/dtc.h')
-rw-r--r--scripts/dtc/dtc.h77
1 files changed, 38 insertions, 39 deletions
diff --git a/scripts/dtc/dtc.h b/scripts/dtc/dtc.h
index 08d54c87008..f37c97eb3df 100644
--- a/scripts/dtc/dtc.h
+++ b/scripts/dtc/dtc.h
@@ -34,7 +34,17 @@
34#include <libfdt_env.h> 34#include <libfdt_env.h>
35#include <fdt.h> 35#include <fdt.h>
36 36
37#include "util.h"
38
39#ifdef DEBUG
40#define debug(fmt,args...) printf(fmt, ##args)
41#else
42#define debug(fmt,args...)
43#endif
44
45
37#define DEFAULT_FDT_VERSION 17 46#define DEFAULT_FDT_VERSION 17
47
38/* 48/*
39 * Command line options 49 * Command line options
40 */ 50 */
@@ -42,36 +52,11 @@ extern int quiet; /* Level of quietness */
42extern int reservenum; /* Number of memory reservation slots */ 52extern int reservenum; /* Number of memory reservation slots */
43extern int minsize; /* Minimum blob size */ 53extern int minsize; /* Minimum blob size */
44extern int padsize; /* Additional padding to blob */ 54extern int padsize; /* Additional padding to blob */
55extern int phandle_format; /* Use linux,phandle or phandle properties */
45 56
46static inline void __attribute__((noreturn)) die(char * str, ...) 57#define PHANDLE_LEGACY 0x1
47{ 58#define PHANDLE_EPAPR 0x2
48 va_list ap; 59#define PHANDLE_BOTH 0x3
49
50 va_start(ap, str);
51 fprintf(stderr, "FATAL ERROR: ");
52 vfprintf(stderr, str, ap);
53 exit(1);
54}
55
56static inline void *xmalloc(size_t len)
57{
58 void *new = malloc(len);
59
60 if (! new)
61 die("malloc() failed\n");
62
63 return new;
64}
65
66static inline void *xrealloc(void *p, size_t len)
67{
68 void *new = realloc(p, len);
69
70 if (! new)
71 die("realloc() failed (len=%d)\n", len);
72
73 return new;
74}
75 60
76typedef uint32_t cell_t; 61typedef uint32_t cell_t;
77 62
@@ -140,13 +125,18 @@ int data_is_one_string(struct data d);
140#define MAX_NODENAME_LEN 31 125#define MAX_NODENAME_LEN 31
141 126
142/* Live trees */ 127/* Live trees */
128struct label {
129 char *label;
130 struct label *next;
131};
132
143struct property { 133struct property {
144 char *name; 134 char *name;
145 struct data val; 135 struct data val;
146 136
147 struct property *next; 137 struct property *next;
148 138
149 char *label; 139 struct label *labels;
150}; 140};
151 141
152struct node { 142struct node {
@@ -163,22 +153,28 @@ struct node {
163 cell_t phandle; 153 cell_t phandle;
164 int addr_cells, size_cells; 154 int addr_cells, size_cells;
165 155
166 char *label; 156 struct label *labels;
167}; 157};
168 158
159#define for_each_label(l0, l) \
160 for ((l) = (l0); (l); (l) = (l)->next)
161
169#define for_each_property(n, p) \ 162#define for_each_property(n, p) \
170 for ((p) = (n)->proplist; (p); (p) = (p)->next) 163 for ((p) = (n)->proplist; (p); (p) = (p)->next)
171 164
172#define for_each_child(n, c) \ 165#define for_each_child(n, c) \
173 for ((c) = (n)->children; (c); (c) = (c)->next_sibling) 166 for ((c) = (n)->children; (c); (c) = (c)->next_sibling)
174 167
175struct property *build_property(char *name, struct data val, char *label); 168void add_label(struct label **labels, char *label);
169
170struct property *build_property(char *name, struct data val);
176struct property *chain_property(struct property *first, struct property *list); 171struct property *chain_property(struct property *first, struct property *list);
177struct property *reverse_properties(struct property *first); 172struct property *reverse_properties(struct property *first);
178 173
179struct node *build_node(struct property *proplist, struct node *children); 174struct node *build_node(struct property *proplist, struct node *children);
180struct node *name_node(struct node *node, char *name, char *label); 175struct node *name_node(struct node *node, char *name);
181struct node *chain_node(struct node *first, struct node *list); 176struct node *chain_node(struct node *first, struct node *list);
177struct node *merge_nodes(struct node *old_node, struct node *new_node);
182 178
183void add_property(struct node *node, struct property *prop); 179void add_property(struct node *node, struct property *prop);
184void add_child(struct node *parent, struct node *child); 180void add_child(struct node *parent, struct node *child);
@@ -186,6 +182,10 @@ void add_child(struct node *parent, struct node *child);
186const char *get_unitname(struct node *node); 182const char *get_unitname(struct node *node);
187struct property *get_property(struct node *node, const char *propname); 183struct property *get_property(struct node *node, const char *propname);
188cell_t propval_cell(struct property *prop); 184cell_t propval_cell(struct property *prop);
185struct property *get_property_by_label(struct node *tree, const char *label,
186 struct node **node);
187struct marker *get_marker_label(struct node *tree, const char *label,
188 struct node **node, struct property **prop);
189struct node *get_subnode(struct node *node, const char *nodename); 189struct node *get_subnode(struct node *node, const char *nodename);
190struct node *get_node_by_path(struct node *tree, const char *path); 190struct node *get_node_by_path(struct node *tree, const char *path);
191struct node *get_node_by_label(struct node *tree, const char *label); 191struct node *get_node_by_label(struct node *tree, const char *label);
@@ -193,6 +193,8 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
193struct node *get_node_by_ref(struct node *tree, const char *ref); 193struct node *get_node_by_ref(struct node *tree, const char *ref);
194cell_t get_node_phandle(struct node *root, struct node *node); 194cell_t get_node_phandle(struct node *root, struct node *node);
195 195
196uint32_t guess_boot_cpuid(struct node *tree);
197
196/* Boot info (tree plus memreserve information */ 198/* Boot info (tree plus memreserve information */
197 199
198struct reserve_info { 200struct reserve_info {
@@ -200,10 +202,10 @@ struct reserve_info {
200 202
201 struct reserve_info *next; 203 struct reserve_info *next;
202 204
203 char *label; 205 struct label *labels;
204}; 206};
205 207
206struct reserve_info *build_reserve_entry(uint64_t start, uint64_t len, char *label); 208struct reserve_info *build_reserve_entry(uint64_t start, uint64_t len);
207struct reserve_info *chain_reserve_entry(struct reserve_info *first, 209struct reserve_info *chain_reserve_entry(struct reserve_info *first,
208 struct reserve_info *list); 210 struct reserve_info *list);
209struct reserve_info *add_reserve_entry(struct reserve_info *list, 211struct reserve_info *add_reserve_entry(struct reserve_info *list,
@@ -218,6 +220,7 @@ struct boot_info {
218 220
219struct boot_info *build_boot_info(struct reserve_info *reservelist, 221struct boot_info *build_boot_info(struct reserve_info *reservelist,
220 struct node *tree, uint32_t boot_cpuid_phys); 222 struct node *tree, uint32_t boot_cpuid_phys);
223void sort_tree(struct boot_info *bi);
221 224
222/* Checks */ 225/* Checks */
223 226
@@ -239,8 +242,4 @@ struct boot_info *dt_from_source(const char *f);
239 242
240struct boot_info *dt_from_fs(const char *dirname); 243struct boot_info *dt_from_fs(const char *dirname);
241 244
242/* misc */
243
244char *join_path(const char *path, const char *name);
245
246#endif /* _DTC_H */ 245#endif /* _DTC_H */