fdt_wip.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
  2. /*
  3. * libfdt - Flat Device Tree manipulation
  4. * Copyright (C) 2006 David Gibson, IBM Corporation.
  5. */
  6. #include "libfdt_env.h"
  7. #include <fdt.h>
  8. #include <libfdt.h>
  9. #include "libfdt_internal.h"
  10. int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
  11. const char *name, int namelen,
  12. uint32_t idx, const void *val,
  13. int len)
  14. {
  15. void *propval;
  16. int proplen;
  17. propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen,
  18. &proplen);
  19. if (!propval)
  20. return proplen;
  21. if (proplen < (len + idx))
  22. return -FDT_ERR_NOSPACE;
  23. memcpy((char *)propval + idx, val, len);
  24. return 0;
  25. }
  26. int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
  27. const void *val, int len)
  28. {
  29. const void *propval;
  30. int proplen;
  31. propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
  32. if (!propval)
  33. return proplen;
  34. if (proplen != len)
  35. return -FDT_ERR_NOSPACE;
  36. return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
  37. strlen(name), 0,
  38. val, len);
  39. }
  40. static void fdt_nop_region_(void *start, int len)
  41. {
  42. fdt32_t *p;
  43. for (p = start; (char *)p < ((char *)start + len); p++)
  44. *p = cpu_to_fdt32(FDT_NOP);
  45. }
  46. int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
  47. {
  48. struct fdt_property *prop;
  49. int len;
  50. prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
  51. if (!prop)
  52. return len;
  53. fdt_nop_region_(prop, len + sizeof(*prop));
  54. return 0;
  55. }
  56. int fdt_node_end_offset_(void *fdt, int offset)
  57. {
  58. int depth = 0;
  59. while ((offset >= 0) && (depth >= 0))
  60. offset = fdt_next_node(fdt, offset, &depth);
  61. return offset;
  62. }
  63. int fdt_nop_node(void *fdt, int nodeoffset)
  64. {
  65. int endoffset;
  66. endoffset = fdt_node_end_offset_(fdt, nodeoffset);
  67. if (endoffset < 0)
  68. return endoffset;
  69. fdt_nop_region_(fdt_offset_ptr_w(fdt, nodeoffset, 0),
  70. endoffset - nodeoffset);
  71. return 0;
  72. }