summaryrefslogtreecommitdiff
path: root/tests/dumptrees.c
diff options
context:
space:
mode:
authorDavid Gibson <dgibson@mulberryst.seuss>2007-06-14 15:05:55 +1000
committerDavid Gibson <dgibson@mulberryst.seuss>2007-06-14 15:05:55 +1000
commit12578976fe9cef82f0c08db3f9a4f550f5085ba4 (patch)
treecba2b4ddb05edb66e92e171076d0ea476e153e61 /tests/dumptrees.c
parent400bd98a3a4177c8c399fd1270bf58cba43d1f35 (diff)
downloaddevice-tree-compiler-12578976fe9cef82f0c08db3f9a4f550f5085ba4.tar.gz
Merge libfdt into dtc.
Having pulled the libfdt repository into dtc, merge the makefiles and testsuites so that they build together usefully.
Diffstat (limited to 'tests/dumptrees.c')
-rw-r--r--tests/dumptrees.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/dumptrees.c b/tests/dumptrees.c
new file mode 100644
index 0000000..3db0e2b
--- /dev/null
+++ b/tests/dumptrees.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdint.h>
+
+#include <fdt.h>
+#include <libfdt.h>
+#include <libfdt_env.h>
+
+#include "testdata.h"
+
+struct {
+ void *blob;
+ const char *filename;
+} trees[] = {
+#define TREE(name) { &_##name, #name ".dtb" }
+ TREE(test_tree1),
+};
+
+#define NUM_TREES (sizeof(trees) / sizeof(trees[0]))
+
+int main(int argc, char *argv[])
+{
+ int i;
+
+ for (i = 0; i < NUM_TREES; i++) {
+ void *blob = trees[i].blob;
+ const char *filename = trees[i].filename;
+ int size;
+ int fd;
+ int ret;
+
+ size = fdt_totalsize(blob);
+
+ printf("Tree \"%s\", %d bytes\n", filename, size);
+
+ fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (fd < 0)
+ perror("open()");
+
+ ret = write(fd, blob, size);
+ if (ret != size)
+ perror("write()");
+
+ close(fd);
+ }
+ exit(0);
+}