1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3 * libfdt - Flat Device Tree manipulation
4 * Testcase for phandle format options
5 * Copyright (C) 2009 David Gibson, IBM Corporation.
6 */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdint.h>
11
12 #include <libfdt.h>
13
14 #include "tests.h"
15 #include "testdata.h"
16
17 #define PHANDLE_LEGACY 0x1
18 #define PHANDLE_EPAPR 0x2
19 #define PHANDLE_BOTH 0x3
20
main(int argc,char * argv[])21 int main(int argc, char *argv[])
22 {
23 void *fdt;
24 int phandle_format;
25 int n4;
26 uint32_t h4;
27
28 if (argc != 3)
29 CONFIG("Usage: %s <dtb file> <legacy|epapr|both>\n", argv[0]);
30
31 test_init(argc, argv);
32 fdt = load_blob(argv[1]);
33
34 if (streq(argv[2], "legacy"))
35 phandle_format = PHANDLE_LEGACY;
36 else if (streq(argv[2], "epapr"))
37 phandle_format = PHANDLE_EPAPR;
38 else if (streq(argv[2], "both"))
39 phandle_format = PHANDLE_BOTH;
40 else
41 CONFIG("Usage: %s <dtb file> <legacy|epapr|both>\n", argv[0]);
42
43 n4 = fdt_path_offset(fdt, "/node4");
44 if (n4 < 0)
45 FAIL("fdt_path_offset(/node4): %s", fdt_strerror(n4));
46
47 h4 = fdt_get_phandle(fdt, n4);
48 if ((h4 == 0) || (h4 == -1))
49 FAIL("/node4 has bad phandle 0x%x\n", h4);
50
51 if (phandle_format & PHANDLE_LEGACY)
52 check_getprop_cell(fdt, n4, "linux,phandle", h4);
53 else
54 if (fdt_getprop(fdt, n4, "linux,phandle", NULL))
55 FAIL("linux,phandle property present in non-legacy mode");
56
57 if (phandle_format & PHANDLE_EPAPR)
58 check_getprop_cell(fdt, n4, "phandle", h4);
59 else
60 if (fdt_getprop(fdt, n4, "phandle", NULL))
61 FAIL("phandle property present in legacy-only mode");
62
63 PASS();
64 }
65