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