|
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 <fdt.h> |
|
29 #include <libfdt.h> |
|
30 #include <libfdt_env.h> |
|
31 |
|
32 #include "testdata.h" |
|
33 |
|
34 struct { |
|
35 void *blob; |
|
36 const char *filename; |
|
37 } trees[] = { |
|
38 #define TREE(name) { &_##name, #name ".dtb" } |
|
39 TREE(test_tree1), |
|
40 TREE(bad_node_char), TREE(bad_node_format), TREE(bad_prop_char), |
|
41 }; |
|
42 |
|
43 #define NUM_TREES (sizeof(trees) / sizeof(trees[0])) |
|
44 |
|
45 int main(int argc, char *argv[]) |
|
46 { |
|
47 int i; |
|
48 |
|
49 for (i = 0; i < NUM_TREES; i++) { |
|
50 void *blob = trees[i].blob; |
|
51 const char *filename = trees[i].filename; |
|
52 int size; |
|
53 int fd; |
|
54 int ret; |
|
55 |
|
56 size = fdt_totalsize(blob); |
|
57 |
|
58 printf("Tree \"%s\", %d bytes\n", filename, size); |
|
59 |
|
60 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
|
61 if (fd < 0) |
|
62 perror("open()"); |
|
63 |
|
64 ret = write(fd, blob, size); |
|
65 if (ret != size) |
|
66 perror("write()"); |
|
67 |
|
68 close(fd); |
|
69 } |
|
70 exit(0); |
|
71 } |