summaryrefslogtreecommitdiffstats
path: root/src/fdtdump.c
blob: 1b609da0719a3fd9869f33b217bfb8c79bde84ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <errno.h>
#include <stdio.h>
#include <unistd.h>

#include <common.h>
#include <dt/dt.h>

int main(int argc, char *argv[])
{
	void *fdt;
	struct device_node *root;
	const char *dtbfile = NULL;

	if (argc > 1)
		dtbfile = argv[1];

	if (dtbfile) {
		fdt = read_file(dtbfile, NULL);
		if (!fdt) {
			fprintf(stderr, "Could not read %s: %s\n", dtbfile, strerror(errno));
			exit(1);
		}

		root = of_unflatten_dtb(fdt);
	} else {
		root = of_read_proc_devicetree();
	}

	if (IS_ERR(root)) {
		fprintf(stderr, "Could not unflatten dtb: %s\n", strerror(-PTR_ERR(root)));
		exit(1);
	}

	printf("/dts-v1/;\n/");

	of_print_nodes(root, 0);

	exit(0);
}