Add qemu 2.4.0
[kvmfornfv.git] / qemu / dtc / tests / dumptrees.c
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 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 };
40
41 #define NUM_TREES       (sizeof(trees) / sizeof(trees[0]))
42
43 int main(int argc, char *argv[])
44 {
45         int i;
46
47         for (i = 0; i < NUM_TREES; i++) {
48                 void *blob = trees[i].blob;
49                 const char *filename = trees[i].filename;
50                 int size;
51                 int fd;
52                 int ret;
53
54                 size = fdt_totalsize(blob);
55
56                 printf("Tree \"%s\", %d bytes\n", filename, size);
57
58                 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
59                 if (fd < 0)
60                         perror("open()");
61
62                 ret = write(fd, blob, size);
63                 if (ret != size)
64                         perror("write()");
65
66                 close(fd);
67         }
68         exit(0);
69 }