2019-06-20 23:19:41 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-12-19 01:04:33 +01:00
|
|
|
/*
|
|
|
|
* dumptrees - utility for libfdt testing
|
|
|
|
*
|
|
|
|
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2006.
|
|
|
|
*/
|
2006-11-28 07:20:01 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2007-03-23 05:16:54 +01:00
|
|
|
#include <stdint.h>
|
2006-11-28 07:20:01 +01:00
|
|
|
|
2006-12-15 05:12:47 +01:00
|
|
|
#include <libfdt.h>
|
2006-11-28 07:20:01 +01:00
|
|
|
|
|
|
|
#include "testdata.h"
|
|
|
|
|
2017-03-06 02:08:53 +01:00
|
|
|
static struct {
|
2006-12-15 05:12:47 +01:00
|
|
|
void *blob;
|
2006-11-28 07:20:01 +01:00
|
|
|
const char *filename;
|
|
|
|
} trees[] = {
|
2017-10-18 07:59:43 +02:00
|
|
|
#define TREE(name) { &name, #name ".dtb" }
|
2006-11-28 07:20:01 +01:00
|
|
|
TREE(test_tree1),
|
2008-02-27 03:45:13 +01:00
|
|
|
TREE(bad_node_char), TREE(bad_node_format), TREE(bad_prop_char),
|
2016-01-02 22:43:35 +01:00
|
|
|
TREE(ovf_size_strings),
|
2018-03-17 14:12:12 +01:00
|
|
|
TREE(truncated_property), TREE(truncated_string),
|
|
|
|
TREE(truncated_memrsv),
|
2021-03-23 02:04:10 +01:00
|
|
|
TREE(two_roots),
|
|
|
|
TREE(named_root)
|
2006-11-28 07:20:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NUM_TREES (sizeof(trees) / sizeof(trees[0]))
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-06-18 19:20:26 +02:00
|
|
|
unsigned int i;
|
2006-11-28 07:20:01 +01:00
|
|
|
|
2019-10-09 12:20:18 +02:00
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr, "Missing output directory argument\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chdir(argv[1]) != 0) {
|
|
|
|
perror("chdir()");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-11-28 07:20:01 +01:00
|
|
|
for (i = 0; i < NUM_TREES; i++) {
|
2006-12-15 05:12:47 +01:00
|
|
|
void *blob = trees[i].blob;
|
2006-11-28 07:20:01 +01:00
|
|
|
const char *filename = trees[i].filename;
|
|
|
|
int size;
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
2006-12-15 05:12:47 +01:00
|
|
|
size = fdt_totalsize(blob);
|
2006-11-28 07:20:01 +01:00
|
|
|
|
|
|
|
printf("Tree \"%s\", %d bytes\n", filename, size);
|
|
|
|
|
|
|
|
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
|
|
|
if (fd < 0)
|
|
|
|
perror("open()");
|
|
|
|
|
2006-12-15 05:12:47 +01:00
|
|
|
ret = write(fd, blob, size);
|
2006-11-28 07:20:01 +01:00
|
|
|
if (ret != size)
|
|
|
|
perror("write()");
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|