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
30 static void check_ref(const void *fdt, int node, uint32_t checkref)
36 p = fdt_getprop(fdt, node, "ref", &len);
38 FAIL("fdt_getprop(%d, \"ref\"): %s", node, fdt_strerror(len));
39 if (len != sizeof(*p))
40 FAIL("'ref' in node at %d has wrong size (%d instead of %zd)",
41 node, len, sizeof(*p));
42 ref = fdt32_to_cpu(*p);
44 FAIL("'ref' in node at %d has value 0x%x instead of 0x%x",
47 p = fdt_getprop(fdt, node, "lref", &len);
49 FAIL("fdt_getprop(%d, \"lref\"): %s", node, fdt_strerror(len));
50 if (len != sizeof(*p))
51 FAIL("'lref' in node at %d has wrong size (%d instead of %zd)",
52 node, len, sizeof(*p));
53 ref = fdt32_to_cpu(*p);
55 FAIL("'lref' in node at %d has value 0x%x instead of 0x%x",
59 int main(int argc, char *argv[])
62 int n1, n2, n3, n4, n5;
63 uint32_t h1, h2, h4, h5;
65 test_init(argc, argv);
66 fdt = load_blob_arg(argc, argv);
68 n1 = fdt_path_offset(fdt, "/node1");
70 FAIL("fdt_path_offset(/node1): %s", fdt_strerror(n1));
71 n2 = fdt_path_offset(fdt, "/node2");
73 FAIL("fdt_path_offset(/node2): %s", fdt_strerror(n2));
74 n3 = fdt_path_offset(fdt, "/node3");
76 FAIL("fdt_path_offset(/node3): %s", fdt_strerror(n3));
77 n4 = fdt_path_offset(fdt, "/node4");
79 FAIL("fdt_path_offset(/node4): %s", fdt_strerror(n4));
80 n5 = fdt_path_offset(fdt, "/node5");
82 FAIL("fdt_path_offset(/node5): %s", fdt_strerror(n5));
84 h1 = fdt_get_phandle(fdt, n1);
85 h2 = fdt_get_phandle(fdt, n2);
86 h4 = fdt_get_phandle(fdt, n4);
87 h5 = fdt_get_phandle(fdt, n5);
90 FAIL("/node1 has wrong phandle, 0x%x instead of 0x%x",
93 FAIL("/node2 has wrong phandle, 0x%x instead of 0x%x",
95 if ((h4 == 0x2000) || (h4 == 0x1) || (h4 == 0))
96 FAIL("/node4 has bad phandle, 0x%x", h4);
98 if ((h5 == 0) || (h5 == -1))
99 FAIL("/node5 has bad phandle, 0x%x", h5);
100 if ((h5 == h4) || (h5 == h2) || (h5 == h1))
101 FAIL("/node5 has duplicate phandle, 0x%x", h5);
103 check_ref(fdt, n1, h2);
104 check_ref(fdt, n2, h1);
105 check_ref(fdt, n3, h4);