1 /* $NetBSD: sized_cells.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 variable sized cells in dtc
7 * Copyright (C) 2006 David Gibson, IBM Corporation.
8 * Copyright (C) 2011 The Chromium Authors. All rights reserved.
9 */
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdint.h>
14
15 #include <libfdt.h>
16
17 #include "tests.h"
18 #include "testdata.h"
19
check_compare_properties(void * fdt,char const * name_one,char const * name_two)20 static void check_compare_properties(void *fdt,
21 char const *name_one,
22 char const *name_two)
23 {
24 const void *propval;
25 int proplen;
26
27 propval = fdt_getprop(fdt, 0, name_one, &proplen);
28
29 if (!propval)
30 FAIL("fdt_getprop(\"%s\"): %s",
31 name_one,
32 fdt_strerror(proplen));
33
34 check_getprop(fdt, 0, name_two, proplen, propval);
35 }
36
main(int argc,char * argv[])37 int main(int argc, char *argv[])
38 {
39 void *fdt;
40 uint8_t expected_8[6] = {TEST_CHAR1,
41 TEST_CHAR2,
42 TEST_CHAR3,
43 TEST_CHAR4,
44 TEST_CHAR5,
45 TEST_VALUE_1 >> 24};
46 fdt16_t expected_16[6];
47 fdt32_t expected_32[6];
48 fdt64_t expected_64[6];
49 int i;
50
51 for (i = 0; i < 5; ++i) {
52 expected_16[i] = cpu_to_fdt16(expected_8[i]);
53 expected_32[i] = cpu_to_fdt32(expected_8[i]);
54 expected_64[i] = cpu_to_fdt64(expected_8[i]);
55 }
56
57 expected_16[5] = cpu_to_fdt16(TEST_VALUE_1 >> 16);
58 expected_32[5] = cpu_to_fdt32(TEST_VALUE_1);
59 expected_64[5] = cpu_to_fdt64(TEST_ADDR_1);
60
61 test_init(argc, argv);
62 fdt = load_blob_arg(argc, argv);
63
64 check_getprop(fdt, 0, "cells-8b", sizeof(expected_8), expected_8);
65 check_getprop(fdt, 0, "cells-16b", sizeof(expected_16), expected_16);
66 check_getprop(fdt, 0, "cells-32b", sizeof(expected_32), expected_32);
67 check_getprop(fdt, 0, "cells-64b", sizeof(expected_64), expected_64);
68
69 check_compare_properties(fdt, "cells-one-16b", "cells-one-32b");
70
71 PASS();
72 }
73