xref: /kvm-unit-tests/lib/libfdt/fdt_empty_tree.c (revision a322d4c597bb7a4de7985e7b51b80504f7e4fdda)
1*a322d4c5SAndrew Jones /*
2*a322d4c5SAndrew Jones  * libfdt - Flat Device Tree manipulation
3*a322d4c5SAndrew Jones  * Copyright (C) 2012 David Gibson, IBM Corporation.
4*a322d4c5SAndrew Jones  *
5*a322d4c5SAndrew Jones  * libfdt is dual licensed: you can use it either under the terms of
6*a322d4c5SAndrew Jones  * the GPL, or the BSD license, at your option.
7*a322d4c5SAndrew Jones  *
8*a322d4c5SAndrew Jones  *  a) This library is free software; you can redistribute it and/or
9*a322d4c5SAndrew Jones  *     modify it under the terms of the GNU General Public License as
10*a322d4c5SAndrew Jones  *     published by the Free Software Foundation; either version 2 of the
11*a322d4c5SAndrew Jones  *     License, or (at your option) any later version.
12*a322d4c5SAndrew Jones  *
13*a322d4c5SAndrew Jones  *     This library is distributed in the hope that it will be useful,
14*a322d4c5SAndrew Jones  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
15*a322d4c5SAndrew Jones  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*a322d4c5SAndrew Jones  *     GNU General Public License for more details.
17*a322d4c5SAndrew Jones  *
18*a322d4c5SAndrew Jones  *     You should have received a copy of the GNU General Public
19*a322d4c5SAndrew Jones  *     License along with this library; if not, write to the Free
20*a322d4c5SAndrew Jones  *     Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
21*a322d4c5SAndrew Jones  *     MA 02110-1301 USA
22*a322d4c5SAndrew Jones  *
23*a322d4c5SAndrew Jones  * Alternatively,
24*a322d4c5SAndrew Jones  *
25*a322d4c5SAndrew Jones  *  b) Redistribution and use in source and binary forms, with or
26*a322d4c5SAndrew Jones  *     without modification, are permitted provided that the following
27*a322d4c5SAndrew Jones  *     conditions are met:
28*a322d4c5SAndrew Jones  *
29*a322d4c5SAndrew Jones  *     1. Redistributions of source code must retain the above
30*a322d4c5SAndrew Jones  *        copyright notice, this list of conditions and the following
31*a322d4c5SAndrew Jones  *        disclaimer.
32*a322d4c5SAndrew Jones  *     2. Redistributions in binary form must reproduce the above
33*a322d4c5SAndrew Jones  *        copyright notice, this list of conditions and the following
34*a322d4c5SAndrew Jones  *        disclaimer in the documentation and/or other materials
35*a322d4c5SAndrew Jones  *        provided with the distribution.
36*a322d4c5SAndrew Jones  *
37*a322d4c5SAndrew Jones  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
38*a322d4c5SAndrew Jones  *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
39*a322d4c5SAndrew Jones  *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
40*a322d4c5SAndrew Jones  *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41*a322d4c5SAndrew Jones  *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
42*a322d4c5SAndrew Jones  *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43*a322d4c5SAndrew Jones  *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44*a322d4c5SAndrew Jones  *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45*a322d4c5SAndrew Jones  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46*a322d4c5SAndrew Jones  *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47*a322d4c5SAndrew Jones  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
48*a322d4c5SAndrew Jones  *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
49*a322d4c5SAndrew Jones  *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50*a322d4c5SAndrew Jones  */
51*a322d4c5SAndrew Jones #include "libfdt_env.h"
52*a322d4c5SAndrew Jones 
53*a322d4c5SAndrew Jones #include <fdt.h>
54*a322d4c5SAndrew Jones #include <libfdt.h>
55*a322d4c5SAndrew Jones 
56*a322d4c5SAndrew Jones #include "libfdt_internal.h"
57*a322d4c5SAndrew Jones 
58*a322d4c5SAndrew Jones int fdt_create_empty_tree(void *buf, int bufsize)
59*a322d4c5SAndrew Jones {
60*a322d4c5SAndrew Jones 	int err;
61*a322d4c5SAndrew Jones 
62*a322d4c5SAndrew Jones 	err = fdt_create(buf, bufsize);
63*a322d4c5SAndrew Jones 	if (err)
64*a322d4c5SAndrew Jones 		return err;
65*a322d4c5SAndrew Jones 
66*a322d4c5SAndrew Jones 	err = fdt_finish_reservemap(buf);
67*a322d4c5SAndrew Jones 	if (err)
68*a322d4c5SAndrew Jones 		return err;
69*a322d4c5SAndrew Jones 
70*a322d4c5SAndrew Jones 	err = fdt_begin_node(buf, "");
71*a322d4c5SAndrew Jones 	if (err)
72*a322d4c5SAndrew Jones 		return err;
73*a322d4c5SAndrew Jones 
74*a322d4c5SAndrew Jones 	err =  fdt_end_node(buf);
75*a322d4c5SAndrew Jones 	if (err)
76*a322d4c5SAndrew Jones 		return err;
77*a322d4c5SAndrew Jones 
78*a322d4c5SAndrew Jones 	err = fdt_finish(buf);
79*a322d4c5SAndrew Jones 	if (err)
80*a322d4c5SAndrew Jones 		return err;
81*a322d4c5SAndrew Jones 
82*a322d4c5SAndrew Jones 	return fdt_open_into(buf, buf, bufsize);
83*a322d4c5SAndrew Jones }
84*a322d4c5SAndrew Jones 
85