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