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