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