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