• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * libfdt - Flat Device Tree manipulation
3  *	Testcase for DT overlays()
4  * Copyright (C) 2016 Free Electrons
5  * Copyright (C) 2016 NextThing Co.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <stdio.h>
23 
24 #include <libfdt.h>
25 
26 #include "tests.h"
27 
28 #define CHECK(code, expected)					\
29 	{							\
30 		err = (code);					\
31 		if (err != expected)				\
32 			FAIL(#code ": %s", fdt_strerror(err));	\
33 	}
34 
35 /* 4k ought to be enough for anybody */
36 #define FDT_COPY_SIZE	(4 * 1024)
37 
open_dt(char * path)38 static void *open_dt(char *path)
39 {
40 	void *dt, *copy;
41 	int err;
42 
43 	dt = load_blob(path);
44 	copy = xmalloc(FDT_COPY_SIZE);
45 
46 	/*
47 	 * Resize our DTs to 4k so that we have room to operate on
48 	 */
49 	CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE), 0);
50 
51 	return copy;
52 }
53 
main(int argc,char * argv[])54 int main(int argc, char *argv[])
55 {
56 	void *fdt_base, *fdt_overlay;
57 	int err;
58 
59 	test_init(argc, argv);
60 	if (argc != 3)
61 		CONFIG("Usage: %s <base dtb> <overlay dtb>", argv[0]);
62 
63 	fdt_base = open_dt(argv[1]);
64 	fdt_overlay = open_dt(argv[2]);
65 
66 	/* Apply the overlay */
67 	CHECK(fdt_overlay_apply(fdt_base, fdt_overlay), -FDT_ERR_BADOVERLAY);
68 
69 	PASS();
70 }
71