diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-01-21 19:19:13 +0900 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2018-01-28 12:27:30 -0500 |
commit | ae9ace7089d2167cbf8a69a29705049ae11c8eea (patch) | |
tree | 0b7e60a539711c42a9d46ae9ae02b70c2af714ef /tools/libfdt | |
parent | 94b13bbae90bfb94204b8fe9c531bc163e746a9f (diff) |
libfdt: migrate fdt_rw.c to a wrapper of scripts/dtc/libfdt/fdt_rw.c
The only difference between scripts/dtc/libfdt/fdt_rw.c and
lib/libfdt/fdt_rw.c is fdt_remove_unused_strings().
It is only used by fdtgrep, so we do not need to compile it for U-Boot
image. Move it to tools/libfdt/fdw_rw.c so that lib/libfdt/fdt_rw.c
can be a wrapper of scripts/dtc/libfdt/fdt_rw.c.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/libfdt')
-rw-r--r-- | tools/libfdt/fdt_rw.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/libfdt/fdt_rw.c b/tools/libfdt/fdt_rw.c new file mode 100644 index 0000000000..e475084fae --- /dev/null +++ b/tools/libfdt/fdt_rw.c @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause */ +#include "fdt_host.h" +#include "../../scripts/dtc/libfdt/fdt_rw.c" + +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; +} |