1 /*
2 * dumptrees - utility for libfdt testing
3 *
4 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2006.
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <stdint.h>
27
28 #include <libfdt.h>
29
30 #include "testdata.h"
31
32 static struct {
33 void *blob;
34 const char *filename;
35 } trees[] = {
36 #define TREE(name) { &name, #name ".dtb" }
37 TREE(test_tree1),
38 TREE(bad_node_char), TREE(bad_node_format), TREE(bad_prop_char),
39 TREE(ovf_size_strings),
40 TREE(truncated_property), TREE(truncated_string),
41 TREE(truncated_memrsv),
42 };
43
44 #define NUM_TREES (sizeof(trees) / sizeof(trees[0]))
45
main(int argc,char * argv[])46 int main(int argc, char *argv[])
47 {
48 int i;
49
50 for (i = 0; i < NUM_TREES; i++) {
51 void *blob = trees[i].blob;
52 const char *filename = trees[i].filename;
53 int size;
54 int fd;
55 int ret;
56
57 size = fdt_totalsize(blob);
58
59 printf("Tree \"%s\", %d bytes\n", filename, size);
60
61 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
62 if (fd < 0)
63 perror("open()");
64
65 ret = write(fd, blob, size);
66 if (ret != size)
67 perror("write()");
68
69 close(fd);
70 }
71 exit(0);
72 }
73