hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/scripts/dtc/livetree.c
....@@ -1,24 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
3
- *
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as
7
- * published by the Free Software Foundation; either version 2 of the
8
- * License, or (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18
- * USA
194 */
205
216 #include "dtc.h"
7
+#include "srcpos.h"
228
239 /*
2410 * Tree building functions
....@@ -50,7 +36,8 @@
5036 label->deleted = 1;
5137 }
5238
53
-struct property *build_property(char *name, struct data val)
39
+struct property *build_property(char *name, struct data val,
40
+ struct srcpos *srcpos)
5441 {
5542 struct property *new = xmalloc(sizeof(*new));
5643
....@@ -58,6 +45,7 @@
5845
5946 new->name = name;
6047 new->val = val;
48
+ new->srcpos = srcpos_copy(srcpos);
6149
6250 return new;
6351 }
....@@ -97,7 +85,8 @@
9785 return head;
9886 }
9987
100
-struct node *build_node(struct property *proplist, struct node *children)
88
+struct node *build_node(struct property *proplist, struct node *children,
89
+ struct srcpos *srcpos)
10190 {
10291 struct node *new = xmalloc(sizeof(*new));
10392 struct node *child;
....@@ -106,6 +95,7 @@
10695
10796 new->proplist = reverse_properties(proplist);
10897 new->children = children;
98
+ new->srcpos = srcpos_copy(srcpos);
10999
110100 for_each_child(new, child) {
111101 child->parent = new;
....@@ -114,13 +104,14 @@
114104 return new;
115105 }
116106
117
-struct node *build_node_delete(void)
107
+struct node *build_node_delete(struct srcpos *srcpos)
118108 {
119109 struct node *new = xmalloc(sizeof(*new));
120110
121111 memset(new, 0, sizeof(*new));
122112
123113 new->deleted = 1;
114
+ new->srcpos = srcpos_copy(srcpos);
124115
125116 return new;
126117 }
....@@ -183,6 +174,8 @@
183174
184175 old_prop->val = new_prop->val;
185176 old_prop->deleted = 0;
177
+ free(old_prop->srcpos);
178
+ old_prop->srcpos = new_prop->srcpos;
186179 free(new_prop);
187180 new_prop = NULL;
188181 break;
....@@ -223,6 +216,8 @@
223216 add_child(old_node, new_child);
224217 }
225218
219
+ old_node->srcpos = srcpos_extend(old_node->srcpos, new_node->srcpos);
220
+
226221 /* The new node contents are now merged into the old node. Free
227222 * the new node. */
228223 free(new_node);
....@@ -239,20 +234,21 @@
239234 char *name;
240235
241236 if (ref[0] == '/') {
237
+ d = data_add_marker(d, TYPE_STRING, ref);
242238 d = data_append_data(d, ref, strlen(ref) + 1);
243239
244
- p = build_property("target-path", d);
240
+ p = build_property("target-path", d, NULL);
245241 } else {
246242 d = data_add_marker(d, REF_PHANDLE, ref);
247243 d = data_append_integer(d, 0xffffffff, 32);
248244
249
- p = build_property("target", d);
245
+ p = build_property("target", d, NULL);
250246 }
251247
252248 xasprintf(&name, "fragment@%u",
253249 next_orphan_fragment++);
254250 name_node(new_node, "__overlay__");
255
- node = build_node(p, new_node);
251
+ node = build_node(p, new_node, NULL);
256252 name_node(node, name);
257253
258254 add_child(dt, node);
....@@ -340,18 +336,21 @@
340336 }
341337
342338 void append_to_property(struct node *node,
343
- char *name, const void *data, int len)
339
+ char *name, const void *data, int len,
340
+ enum markertype type)
344341 {
345342 struct data d;
346343 struct property *p;
347344
348345 p = get_property(node, name);
349346 if (p) {
350
- d = data_append_data(p->val, data, len);
347
+ d = data_add_marker(p->val, type, name);
348
+ d = data_append_data(d, data, len);
351349 p->val = d;
352350 } else {
353
- d = data_append_data(empty_data, data, len);
354
- p = build_property(name, d);
351
+ d = data_add_marker(empty_data, type, name);
352
+ d = data_append_data(d, data, len);
353
+ p = build_property(name, d, NULL);
355354 add_property(node, p);
356355 }
357356 }
....@@ -527,8 +526,7 @@
527526 p = strchr(path, '/');
528527
529528 for_each_child(tree, child) {
530
- if (p && (strlen(child->name) == p-path) &&
531
- strprefixeq(path, p - path, child->name))
529
+ if (p && strprefixeq(path, p - path, child->name))
532530 return get_node_by_path(child, p+1);
533531 else if (!p && streq(path, child->name))
534532 return child;
....@@ -594,6 +592,7 @@
594592 cell_t get_node_phandle(struct node *root, struct node *node)
595593 {
596594 static cell_t phandle = 1; /* FIXME: ick, static local */
595
+ struct data d = empty_data;
597596
598597 if ((node->phandle != 0) && (node->phandle != -1))
599598 return node->phandle;
....@@ -603,17 +602,16 @@
603602
604603 node->phandle = phandle;
605604
605
+ d = data_add_marker(d, TYPE_UINT32, NULL);
606
+ d = data_append_cell(d, phandle);
607
+
606608 if (!get_property(node, "linux,phandle")
607609 && (phandle_format & PHANDLE_LEGACY))
608
- add_property(node,
609
- build_property("linux,phandle",
610
- data_append_cell(empty_data, phandle)));
610
+ add_property(node, build_property("linux,phandle", d, NULL));
611611
612612 if (!get_property(node, "phandle")
613613 && (phandle_format & PHANDLE_EPAPR))
614
- add_property(node,
615
- build_property("phandle",
616
- data_append_cell(empty_data, phandle)));
614
+ add_property(node, build_property("phandle", d, NULL));
617615
618616 /* If the node *does* have a phandle property, we must
619617 * be dealing with a self-referencing phandle, which will be
....@@ -787,7 +785,7 @@
787785 {
788786 struct node *node;
789787
790
- node = build_node(NULL, NULL);
788
+ node = build_node(NULL, NULL, NULL);
791789 name_node(node, xstrdup(name));
792790 add_child(parent, node);
793791
....@@ -848,8 +846,9 @@
848846
849847 /* insert it */
850848 p = build_property(l->label,
851
- data_copy_mem(node->fullpath,
852
- strlen(node->fullpath) + 1));
849
+ data_copy_escape_string(node->fullpath,
850
+ strlen(node->fullpath)),
851
+ NULL);
853852 add_property(an, p);
854853 }
855854
....@@ -899,7 +898,7 @@
899898
900899 xasprintf(&entry, "%s:%s:%u",
901900 node->fullpath, prop->name, m->offset);
902
- append_to_property(fn, m->ref, entry, strlen(entry) + 1);
901
+ append_to_property(fn, m->ref, entry, strlen(entry) + 1, TYPE_STRING);
903902
904903 free(entry);
905904 }
....@@ -959,7 +958,7 @@
959958 char **compp;
960959 int i, depth;
961960
962
- /* walk back retreiving depth */
961
+ /* walk back retrieving depth */
963962 depth = 0;
964963 for (wn = node; wn; wn = wn->parent)
965964 depth++;
....@@ -982,7 +981,7 @@
982981 free(compp);
983982
984983 value_32 = cpu_to_fdt32(m->offset);
985
- append_to_property(wn, prop->name, &value_32, sizeof(value_32));
984
+ append_to_property(wn, prop->name, &value_32, sizeof(value_32), TYPE_UINT32);
986985 }
987986
988987 static void generate_local_fixups_tree_internal(struct dt_info *dti,