aboutsummaryrefslogtreecommitdiff
path: root/lib/libfdt/fdt_rw.c
diff options
context:
space:
mode:
authorSimon Glass2015-06-23 15:38:26 -0600
committerSimon Glass2015-07-21 17:39:20 -0600
commit8f6e2e1ee17bb1ecce03518b8eceda6965617477 (patch)
tree0c227e0e9daf32f4879f8a331e0a1062d80c0c2b /lib/libfdt/fdt_rw.c
parent5b9d44df2307fc882b2ae666fd28fb2c7c2d5b11 (diff)
fdt: Add a function to remove unused strings from a device tree
Property names are stored in a string table. When a node property is removed, the string table is not updated since other nodes may have a property with the same name. Thus it is possible for the string table to build up a number of unused strings. Add a function to remove these. This works by building a new device tree from the old one, adding strings one by one as needed. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/libfdt/fdt_rw.c')
-rw-r--r--lib/libfdt/fdt_rw.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/libfdt/fdt_rw.c b/lib/libfdt/fdt_rw.c
index bec8b8ad891..1a358a8ca0a 100644
--- a/lib/libfdt/fdt_rw.c
+++ b/lib/libfdt/fdt_rw.c
@@ -449,3 +449,35 @@ int fdt_pack(void *fdt)
return 0;
}
+
+int fdt_remove_unused_strings(const void *old, void *new)
+{
+ const struct fdt_property *old_prop;
+ struct fdt_property *new_prop;
+ int size = fdt_totalsize(old);
+ int next_offset, offset;
+ const char *str;
+ int ret;
+ int tag = FDT_PROP;
+
+ /* Make a copy and remove the strings */
+ memcpy(new, old, size);
+ fdt_set_size_dt_strings(new, 0);
+
+ /* Add every property name back into the new string table */
+ for (offset = 0; tag != FDT_END; offset = next_offset) {
+ tag = fdt_next_tag(old, offset, &next_offset);
+ if (tag != FDT_PROP)
+ continue;
+ old_prop = fdt_get_property_by_offset(old, offset, NULL);
+ new_prop = (struct fdt_property *)(unsigned long)
+ fdt_get_property_by_offset(new, offset, NULL);
+ str = fdt_string(old, fdt32_to_cpu(old_prop->nameoff));
+ ret = _fdt_find_add_string(new, str);
+ if (ret < 0)
+ return ret;
+ new_prop->nameoff = cpu_to_fdt32(ret);
+ }
+
+ return 0;
+}