2 * libfdt - Flat Device Tree manipulation
3 * Testcase for phandle format options
4 * Copyright (C) 2009 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 #define PHANDLE_LEGACY 0x1
31 #define PHANDLE_EPAPR 0x2
32 #define PHANDLE_BOTH 0x3
34 int main(int argc, char *argv[])
42 CONFIG("Usage: %s <dtb file> <legacy|epapr|both>\n", argv[0]);
44 test_init(argc, argv);
45 fdt = load_blob(argv[1]);
47 if (streq(argv[2], "legacy"))
48 phandle_format = PHANDLE_LEGACY;
49 else if (streq(argv[2], "epapr"))
50 phandle_format = PHANDLE_EPAPR;
51 else if (streq(argv[2], "both"))
52 phandle_format = PHANDLE_BOTH;
54 CONFIG("Usage: %s <dtb file> <legacy|epapr|both>\n", argv[0]);
56 n4 = fdt_path_offset(fdt, "/node4");
58 FAIL("fdt_path_offset(/node4): %s", fdt_strerror(n4));
60 h4 = fdt_get_phandle(fdt, n4);
61 if ((h4 == 0) || (h4 == -1))
62 FAIL("/node4 has bad phandle 0x%x\n", h4);
64 if (phandle_format & PHANDLE_LEGACY)
65 check_getprop_cell(fdt, n4, "linux,phandle", h4);
67 if (fdt_getprop(fdt, n4, "linux,phandle", NULL))
68 FAIL("linux,phandle property present in non-legacy mode");
70 if (phandle_format & PHANDLE_EPAPR)
71 check_getprop_cell(fdt, n4, "phandle", h4);
73 if (fdt_getprop(fdt, n4, "phandle", NULL))
74 FAIL("phandle property present in legacy-only mode");