1 /* 2 * dumptrees - utility for libfdt testing 3 * 4 * (C) Copyright David Gibson <dwg (at) 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 }; 41 42 #define NUM_TREES (sizeof(trees) / sizeof(trees[0])) 43 44 int main(int argc, char *argv[]) 45 { 46 int i; 47 48 for (i = 0; i < NUM_TREES; i++) { 49 void *blob = trees[i].blob; 50 const char *filename = trees[i].filename; 51 int size; 52 int fd; 53 int ret; 54 55 size = fdt_totalsize(blob); 56 57 printf("Tree \"%s\", %d bytes\n", filename, size); 58 59 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); 60 if (fd < 0) 61 perror("open()"); 62 63 ret = write(fd, blob, size); 64 if (ret != size) 65 perror("write()"); 66 67 close(fd); 68 } 69 exit(0); 70 } 71