2 * libfdt - Flat Device Tree manipulation
3 * Testcase for fdt_nop_node()
4 * Copyright (C) 2006 David Gibson, IBM Corporation.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
40 static void realloc_fdt(void **fdt, size_t *size, bool created)
47 FAIL("Ran out of space");
53 } else if (*size < SPACE) {
55 fdt_resize(*fdt, *fdt, *size);
57 FAIL("Ran out of space");
63 *fdt = xrealloc(*fdt, *size);
65 fdt_resize(*fdt, *fdt, *size);
69 CONFIG("Bad allocation mode");
76 if (err == -FDT_ERR_NOSPACE) \
77 realloc_fdt(&fdt, &size, created); \
79 FAIL(#code ": %s", fdt_strerror(err)); \
82 int main(int argc, char *argv[])
89 test_init(argc, argv);
94 } else if (argc == 2) {
95 if (streq(argv[1], "resize")) {
98 } else if (streq(argv[1], "realloc")) {
104 size = strtoul(argv[1], &endp, 0);
108 CONFIG("Bad allocation mode \"%s\" specified",
114 CHECK(fdt_create(fdt, size));
118 CHECK(fdt_add_reservemap_entry(fdt, TEST_ADDR_1, TEST_SIZE_1));
120 CHECK(fdt_add_reservemap_entry(fdt, TEST_ADDR_2, TEST_SIZE_2));
121 CHECK(fdt_finish_reservemap(fdt));
123 CHECK(fdt_begin_node(fdt, ""));
124 CHECK(fdt_property_string(fdt, "compatible", "test_tree1"));
125 CHECK(fdt_property_u32(fdt, "prop-int", TEST_VALUE_1));
126 CHECK(fdt_property_u64(fdt, "prop-int64", TEST_VALUE64_1));
127 CHECK(fdt_property_string(fdt, "prop-str", TEST_STRING_1));
128 CHECK(fdt_property_u32(fdt, "#address-cells", 1));
129 CHECK(fdt_property_u32(fdt, "#size-cells", 0));
131 CHECK(fdt_begin_node(fdt, "subnode@1"));
132 CHECK(fdt_property_string(fdt, "compatible", "subnode1"));
133 CHECK(fdt_property_u32(fdt, "reg", 1));
134 CHECK(fdt_property_cell(fdt, "prop-int", TEST_VALUE_1));
135 CHECK(fdt_begin_node(fdt, "subsubnode"));
136 CHECK(fdt_property(fdt, "compatible", "subsubnode1\0subsubnode",
138 CHECK(fdt_property_cell(fdt, "prop-int", TEST_VALUE_1));
139 CHECK(fdt_end_node(fdt));
140 CHECK(fdt_begin_node(fdt, "ss1"));
141 CHECK(fdt_end_node(fdt));
142 CHECK(fdt_end_node(fdt));
144 CHECK(fdt_begin_node(fdt, "subnode@2"));
145 CHECK(fdt_property_u32(fdt, "reg", 2));
146 CHECK(fdt_property_cell(fdt, "linux,phandle", PHANDLE_1));
147 CHECK(fdt_property_cell(fdt, "prop-int", TEST_VALUE_2));
148 CHECK(fdt_property_u32(fdt, "#address-cells", 1));
149 CHECK(fdt_property_u32(fdt, "#size-cells", 0));
150 CHECK(fdt_begin_node(fdt, "subsubnode@0"));
151 CHECK(fdt_property_u32(fdt, "reg", 0));
152 CHECK(fdt_property_cell(fdt, "phandle", PHANDLE_2));
153 CHECK(fdt_property(fdt, "compatible", "subsubnode2\0subsubnode",
155 CHECK(fdt_property_cell(fdt, "prop-int", TEST_VALUE_2));
156 CHECK(fdt_end_node(fdt));
157 CHECK(fdt_begin_node(fdt, "ss2"));
158 CHECK(fdt_end_node(fdt));
160 CHECK(fdt_end_node(fdt));
162 CHECK(fdt_end_node(fdt));
164 save_blob("unfinished_tree1.test.dtb", fdt);
166 CHECK(fdt_finish(fdt));
168 verbose_printf("Completed tree, totalsize = %d\n",
171 save_blob("sw_tree1.test.dtb", fdt);