2
* libfdt - Flat Device Tree manipulation
3
* Testcase for phandle references in dtc
4
* Copyright (C) 2006 David Gibson, IBM Corporation.
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public License
8
* as published by the Free Software Foundation; either version 2.1 of
9
* the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31
void check_ref(const void *fdt, int node, uint32_t checkref)
37
p = fdt_getprop(fdt, node, "ref", &len);
39
FAIL("fdt_getprop(%d, \"ref\"): %s", node, fdt_strerror(len));
40
if (len != sizeof(*p))
41
FAIL("'ref' in node at %d has wrong size (%d instead of %zd)",
42
node, len, sizeof(*p));
43
ref = fdt32_to_cpu(*p);
45
FAIL("'ref' in node at %d has value 0x%x instead of 0x%x",
48
p = fdt_getprop(fdt, node, "lref", &len);
50
FAIL("fdt_getprop(%d, \"lref\"): %s", node, fdt_strerror(len));
51
if (len != sizeof(*p))
52
FAIL("'lref' in node at %d has wrong size (%d instead of %zd)",
53
node, len, sizeof(*p));
54
ref = fdt32_to_cpu(*p);
56
FAIL("'lref' in node at %d has value 0x%x instead of 0x%x",
60
int main(int argc, char *argv[])
66
test_init(argc, argv);
67
fdt = load_blob_arg(argc, argv);
69
n1 = fdt_path_offset(fdt, "/node1");
71
FAIL("fdt_path_offset(/node1): %s", fdt_strerror(n1));
72
n2 = fdt_path_offset(fdt, "/node2");
74
FAIL("fdt_path_offset(/node2): %s", fdt_strerror(n2));
75
n3 = fdt_path_offset(fdt, "/node3");
77
FAIL("fdt_path_offset(/node3): %s", fdt_strerror(n3));
78
n4 = fdt_path_offset(fdt, "/node4");
80
FAIL("fdt_path_offset(/node4): %s", fdt_strerror(n4));
82
h1 = fdt_get_phandle(fdt, n1);
83
h2 = fdt_get_phandle(fdt, n2);
84
h4 = fdt_get_phandle(fdt, n4);
87
FAIL("/node1 has wrong phandle, 0x%x instead of 0x%x",
90
FAIL("/node2 has wrong phandle, 0x%x instead of 0x%x",
92
if ((h4 == 0x2000) || (h4 == 0x1) || (h4 == 0))
93
FAIL("/node4 has bad phandle, 0x%x", h4);
95
check_ref(fdt, n1, h2);
96
check_ref(fdt, n2, h1);
97
check_ref(fdt, n3, h4);