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