fdt_rw.c 1.0 KB

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