1 /* $NetBSD: dumptrees.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
2
3 // SPDX-License-Identifier: GPL-2.0-or-later
4 /*
5 * dumptrees - utility for libfdt testing
6 *
7 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2006.
8 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <fcntl.h>
13 #include <stdint.h>
14
15 #include <libfdt.h>
16
17 #include "testdata.h"
18
19 static struct {
20 void *blob;
21 const char *filename;
22 } trees[] = {
23 #define TREE(name) { &name, #name ".dtb" }
24 TREE(test_tree1),
25 TREE(bad_node_char), TREE(bad_node_format), TREE(bad_prop_char),
26 TREE(ovf_size_strings),
27 TREE(truncated_property), TREE(truncated_string),
28 TREE(truncated_memrsv),
29 };
30
31 #define NUM_TREES (sizeof(trees) / sizeof(trees[0]))
32
main(int argc,char * argv[])33 int main(int argc, char *argv[])
34 {
35 int i;
36
37 for (i = 0; i < NUM_TREES; i++) {
38 void *blob = trees[i].blob;
39 const char *filename = trees[i].filename;
40 int size;
41 int fd;
42 int ret;
43
44 size = fdt_totalsize(blob);
45
46 printf("Tree \"%s\", %d bytes\n", filename, size);
47
48 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
49 if (fd < 0)
50 perror("open()");
51
52 ret = write(fd, blob, size);
53 if (ret != size)
54 perror("write()");
55
56 close(fd);
57 }
58 exit(0);
59 }
60