ofnode.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <common.h>
  3. #include <dm.h>
  4. #include <dm/of_extra.h>
  5. #include <dm/test.h>
  6. #include <test/ut.h>
  7. static int dm_test_ofnode_compatible(struct unit_test_state *uts)
  8. {
  9. ofnode root_node = ofnode_path("/");
  10. ut_assert(ofnode_valid(root_node));
  11. ut_assert(ofnode_device_is_compatible(root_node, "sandbox"));
  12. return 0;
  13. }
  14. DM_TEST(dm_test_ofnode_compatible, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  15. static int dm_test_ofnode_by_prop_value(struct unit_test_state *uts)
  16. {
  17. const char propname[] = "compatible";
  18. const char propval[] = "denx,u-boot-fdt-test";
  19. const char *str;
  20. ofnode node = ofnode_null();
  21. /* Find first matching node, there should be at least one */
  22. node = ofnode_by_prop_value(node, propname, propval, sizeof(propval));
  23. ut_assert(ofnode_valid(node));
  24. str = ofnode_read_string(node, propname);
  25. ut_assert(str && !strcmp(str, propval));
  26. /* Find the rest of the matching nodes */
  27. while (true) {
  28. node = ofnode_by_prop_value(node, propname, propval,
  29. sizeof(propval));
  30. if (!ofnode_valid(node))
  31. break;
  32. str = ofnode_read_string(node, propname);
  33. ut_assert(str && !strcmp(str, propval));
  34. }
  35. return 0;
  36. }
  37. DM_TEST(dm_test_ofnode_by_prop_value, DM_TESTF_SCAN_FDT);
  38. static int dm_test_ofnode_fmap(struct unit_test_state *uts)
  39. {
  40. struct fmap_entry entry;
  41. ofnode node;
  42. node = ofnode_path("/cros-ec/flash");
  43. ut_assert(ofnode_valid(node));
  44. ut_assertok(ofnode_read_fmap_entry(node, &entry));
  45. ut_asserteq(0x08000000, entry.offset);
  46. ut_asserteq(0x20000, entry.length);
  47. return 0;
  48. }
  49. DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);