blob: e475084faecab2c5e31544f0c74b2dc50c95c00c [file] [log] [blame]
Masahiro Yamadaae9ace72018-01-21 19:19:13 +09001/* SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause */
2#include "fdt_host.h"
3#include "../../scripts/dtc/libfdt/fdt_rw.c"
4
5int fdt_remove_unused_strings(const void *old, void *new)
6{
7 const struct fdt_property *old_prop;
8 struct fdt_property *new_prop;
9 int size = fdt_totalsize(old);
10 int next_offset, offset;
11 const char *str;
12 int ret;
13 int tag = FDT_PROP;
14
15 /* Make a copy and remove the strings */
16 memcpy(new, old, size);
17 fdt_set_size_dt_strings(new, 0);
18
19 /* Add every property name back into the new string table */
20 for (offset = 0; tag != FDT_END; offset = next_offset) {
21 tag = fdt_next_tag(old, offset, &next_offset);
22 if (tag != FDT_PROP)
23 continue;
24 old_prop = fdt_get_property_by_offset(old, offset, NULL);
25 new_prop = (struct fdt_property *)(unsigned long)
26 fdt_get_property_by_offset(new, offset, NULL);
27 str = fdt_string(old, fdt32_to_cpu(old_prop->nameoff));
28 ret = _fdt_find_add_string(new, str);
29 if (ret < 0)
30 return ret;
31 new_prop->nameoff = cpu_to_fdt32(ret);
32 }
33
34 return 0;
35}