1/* 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 int allocated; 15 16 /* Make a copy and remove the strings */ 17 memcpy(new, old, size); 18 fdt_set_size_dt_strings(new, 0); 19 20 /* Add every property name back into the new string table */ 21 for (offset = 0; tag != FDT_END; offset = next_offset) { 22 tag = fdt_next_tag(old, offset, &next_offset); 23 if (tag != FDT_PROP) 24 continue; 25 old_prop = fdt_get_property_by_offset(old, offset, NULL); 26 new_prop = (struct fdt_property *)(unsigned long) 27 fdt_get_property_by_offset(new, offset, NULL); 28 str = fdt_string(old, fdt32_to_cpu(old_prop->nameoff)); 29 ret = fdt_find_add_string_(new, str, &allocated); 30 if (ret < 0) 31 return ret; 32 new_prop->nameoff = cpu_to_fdt32(ret); 33 } 34 35 return 0; 36} 37