of_extra.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2021 Google LLC
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <dm/of_extra.h>
  9. #include <dm/test.h>
  10. #include <test/ut.h>
  11. #include <u-boot/sha256.h>
  12. static int dm_test_ofnode_read_fmap_entry(struct unit_test_state *uts)
  13. {
  14. const char hash_expect[] = {
  15. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  16. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  17. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  18. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  19. };
  20. struct fmap_entry entry;
  21. ofnode node;
  22. node = ofnode_path("/cros-ec/flash/wp-ro");
  23. ut_assertok(ofnode_read_fmap_entry(node, &entry));
  24. ut_asserteq(0xf000, entry.offset);
  25. ut_asserteq(0x1000, entry.length);
  26. ut_asserteq(0x884, entry.used);
  27. ut_asserteq(FMAP_COMPRESS_LZ4, entry.compress_algo);
  28. ut_asserteq(0xcf8, entry.unc_length);
  29. ut_asserteq(FMAP_HASH_SHA256, entry.hash_algo);
  30. ut_asserteq(SHA256_SUM_LEN, entry.hash_size);
  31. ut_asserteq_mem(hash_expect, entry.hash, SHA256_SUM_LEN);
  32. return 0;
  33. }
  34. DM_TEST(dm_test_ofnode_read_fmap_entry, 0);
  35. static int dm_test_ofnode_phy_is_fixed_link(struct unit_test_state *uts)
  36. {
  37. ofnode eth_node, phy_node, node;
  38. eth_node = ofnode_path("/dsa-test/ports/port@0");
  39. ut_assert(ofnode_phy_is_fixed_link(eth_node, &phy_node));
  40. node = ofnode_path("/dsa-test/ports/port@0/fixed-link");
  41. ut_asserteq_mem(&phy_node, &node, sizeof(ofnode));
  42. eth_node = ofnode_path("/dsa-test/ports/port@1");
  43. ut_assert(ofnode_phy_is_fixed_link(eth_node, &phy_node));
  44. node = eth_node;
  45. ut_asserteq_mem(&phy_node, &node, sizeof(ofnode));
  46. return 0;
  47. }
  48. DM_TEST(dm_test_ofnode_phy_is_fixed_link, 0);