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