flatdevtree_misc.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * This file does the necessary interface mapping between the bootwrapper
  3. * device tree operations and the interface provided by shared source
  4. * files flatdevicetree.[ch].
  5. *
  6. * Author: Mark A. Greer <mgreer@mvista.com>
  7. *
  8. * 2006 (c) MontaVista Software, Inc. This file is licensed under
  9. * the terms of the GNU General Public License version 2. This program
  10. * is licensed "as is" without any warranty of any kind, whether express
  11. * or implied.
  12. */
  13. #include <stddef.h>
  14. #include "flatdevtree.h"
  15. #include "ops.h"
  16. static struct ft_cxt cxt;
  17. static void *fdtm_finddevice(const char *name)
  18. {
  19. return ft_find_device(&cxt, NULL, name);
  20. }
  21. static int fdtm_getprop(const void *phandle, const char *propname,
  22. void *buf, const int buflen)
  23. {
  24. return ft_get_prop(&cxt, phandle, propname, buf, buflen);
  25. }
  26. static int fdtm_setprop(const void *phandle, const char *propname,
  27. const void *buf, const int buflen)
  28. {
  29. return ft_set_prop(&cxt, phandle, propname, buf, buflen);
  30. }
  31. static void *fdtm_get_parent(const void *phandle)
  32. {
  33. return ft_get_parent(&cxt, phandle);
  34. }
  35. static void *fdtm_create_node(const void *phandle, const char *name)
  36. {
  37. return ft_create_node(&cxt, phandle, name);
  38. }
  39. static void *fdtm_find_node_by_prop_value(const void *prev,
  40. const char *propname,
  41. const char *propval,
  42. int proplen)
  43. {
  44. return ft_find_node_by_prop_value(&cxt, prev, propname,
  45. propval, proplen);
  46. }
  47. static unsigned long fdtm_finalize(void)
  48. {
  49. ft_end_tree(&cxt);
  50. return (unsigned long)cxt.bph;
  51. }
  52. static char *fdtm_get_path(const void *phandle, char *buf, int len)
  53. {
  54. return ft_get_path(&cxt, phandle, buf, len);
  55. }
  56. int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device)
  57. {
  58. dt_ops.finddevice = fdtm_finddevice;
  59. dt_ops.getprop = fdtm_getprop;
  60. dt_ops.setprop = fdtm_setprop;
  61. dt_ops.get_parent = fdtm_get_parent;
  62. dt_ops.create_node = fdtm_create_node;
  63. dt_ops.find_node_by_prop_value = fdtm_find_node_by_prop_value;
  64. dt_ops.finalize = fdtm_finalize;
  65. dt_ops.get_path = fdtm_get_path;
  66. return ft_open(&cxt, dt_blob, max_size, max_find_device,
  67. platform_ops.realloc);
  68. }