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