xref: /netbsd-src/external/gpl2/dtc/dist/tests/asm_tree_dump.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: asm_tree_dump.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $	*/
2 
3 /*
4  * libfdt - Flat Device Tree manipulation
5  *	Tests if an asm tree built into a shared object matches a given dtb
6  * Copyright (C) 2008 David Gibson, IBM Corporation.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdint.h>
27 #include <errno.h>
28 
29 #include <dlfcn.h>
30 
31 #include <libfdt.h>
32 
33 #include "tests.h"
34 #include "testdata.h"
35 
36 int main(int argc, char *argv[])
37 {
38 	void *sohandle;
39 	void *fdt;
40 	int err;
41 
42 	test_init(argc, argv);
43 	if (argc != 3)
44 		CONFIG("Usage: %s <so file> <dtb file>", argv[0]);
45 
46 	sohandle = dlopen(argv[1], RTLD_NOW);
47 	if (!sohandle)
48 		FAIL("Couldn't dlopen() %s", argv[1]);
49 
50 	fdt = dlsym(sohandle, "dt_blob_start");
51 	if (!fdt)
52 		FAIL("Couldn't locate \"dt_blob_start\" symbol in %s",
53 		     argv[1]);
54 
55 	err = fdt_check_header(fdt);
56 	if (err != 0)
57 		FAIL("%s contains invalid tree: %s", argv[1],
58 		     fdt_strerror(err));
59 
60 	save_blob(argv[2], fdt);
61 
62 	PASS();
63 }
64