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