1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3  * libfdt - Flat Device Tree manipulation
4  *	Tests if an asm tree built into a shared object matches a given dtb
5  * Copyright (C) 2008 David Gibson, IBM Corporation.
6  */
7 
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdint.h>
12 #include <errno.h>
13 
14 #include <dlfcn.h>
15 
16 #include <libfdt.h>
17 
18 #include "tests.h"
19 #include "testdata.h"
20 
main(int argc,char * argv[])21 int main(int argc, char *argv[])
22 {
23 	void *sohandle;
24 	void *fdt;
25 	int err;
26 
27 	test_init(argc, argv);
28 	if (argc != 3)
29 		CONFIG("Usage: %s <so file> <dtb file>", argv[0]);
30 
31 	sohandle = dlopen(argv[1], RTLD_NOW);
32 	if (!sohandle)
33 		FAIL("Couldn't dlopen() %s", argv[1]);
34 
35 	fdt = dlsym(sohandle, "dt_blob_start");
36 	if (!fdt)
37 		FAIL("Couldn't locate \"dt_blob_start\" symbol in %s",
38 		     argv[1]);
39 
40 	err = fdt_check_header(fdt);
41 	if (err != 0)
42 		FAIL("%s contains invalid tree: %s", argv[1],
43 		     fdt_strerror(err));
44 
45 	save_blob(argv[2], fdt);
46 
47 	PASS();
48 }
49