summaryrefslogtreecommitdiffstats
path: root/meta-ti-extras/recipes/dtc/dtc/0001-fdtdump-Add-live-tree-dump-capability.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-ti-extras/recipes/dtc/dtc/0001-fdtdump-Add-live-tree-dump-capability.patch')
-rw-r--r--meta-ti-extras/recipes/dtc/dtc/0001-fdtdump-Add-live-tree-dump-capability.patch212
1 files changed, 0 insertions, 212 deletions
diff --git a/meta-ti-extras/recipes/dtc/dtc/0001-fdtdump-Add-live-tree-dump-capability.patch b/meta-ti-extras/recipes/dtc/dtc/0001-fdtdump-Add-live-tree-dump-capability.patch
deleted file mode 100644
index 372a430..0000000
--- a/meta-ti-extras/recipes/dtc/dtc/0001-fdtdump-Add-live-tree-dump-capability.patch
+++ /dev/null
@@ -1,212 +0,0 @@
1From da5c33dd94949fa27243faf15cd87e98c53ccb29 Mon Sep 17 00:00:00 2001
2From: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
3Date: Tue, 5 Nov 2013 10:16:14 +0200
4Subject: [PATCH] fdtdump: Add live tree dump capability
5
6Adds the capability to dump any point of the kernel's live tree
7which resides usually in /proc/device-tree.
8
9For example you can do this:
10
11 # fdtdump /proc/device-tree/ocp/ethernet\@4a100000/
12 /* dump of live tree at /proc/device-tree/ocp/ethernet@4a100000 */
13 / {
14 name = "ethernet";
15 pinctrl-1 = <0x0000000b>;
16 pinctrl-0 = <0x0000000a>;
17 pinctrl-names = "default", "sleep";
18 ranges;
19 interrupts = <0x00000028 0x00000000 0x00000000 0x00000000>;
20 interrupt-parent = <0x00000001>;
21 #size-cells = <0x00000001>;
22 #address-cells = <0x00000001>;
23 reg = <0x4a100000 0x00000000 0x00000000 0x00000000>;
24 cpts_clock_shift = <0x0000001d>;
25 cpts_clock_mult = <0x80000000>;
26 active_slave = <0x00000000>;
27 slaves = <0x00000002>;
28 mac_control = <0x00000020>;
29 rx_descs = <0x00000040>;
30 no_bd_ram = <0x00000000>;
31 bd_ram_size = <0x00002000>;
32 ale_entries = <0x00000400>;
33 cpdma_channels = <0x00000008>;
34 ti,hwmods = "cpgmac0";
35 compatible = "ti,cpsw";
36 slave@4a100300 {
37 name = "slave";
38 phy-mode = "mii";
39 phy_id = <0x0000000e 0x00000000>;
40 mac-address = [00 00 00 00 00 00];
41 };
42 slave@4a100200 {
43 name = "slave";
44 phy-mode = "mii";
45 phy_id = <0x0000000e 0x00000000>;
46 mac-address = [00 00 00 00 00 00];
47 };
48 mdio@4a101000 {
49 name = "mdio";
50 phandle = <0x0000000e>;
51 linux,phandle = <0x0000000e>;
52 pinctrl-1 = <0x0000000d>;
53 pinctrl-0 = <0x0000000c>;
54 pinctrl-names = "default", "sleep";
55 reg = <0x4a101000 0x00000000>;
56 bus_freq = <0x000f4240>;
57 ti,hwmods = "davinci_mdio";
58 #size-cells = <0x00000000>;
59 #address-cells = <0x00000001>;
60 compatible = "ti,davinci_mdio";
61 };
62 };
63
64This makes it much easier to see the state of the kernel's live tree.
65
66Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
67---
68 fdtdump.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
69 1 file changed, 107 insertions(+)
70
71diff --git a/fdtdump.c b/fdtdump.c
72index 95a6a20..9183555 100644
73--- a/fdtdump.c
74+++ b/fdtdump.c
75@@ -8,6 +8,14 @@
76 #include <stdlib.h>
77 #include <string.h>
78 #include <ctype.h>
79+#include <sys/types.h>
80+#include <sys/stat.h>
81+#include <alloca.h>
82+#include <dirent.h>
83+#include <limits.h>
84+#include <unistd.h>
85+#include <fcntl.h>
86+#include <errno.h>
87
88 #include <libfdt.h>
89 #include <libfdt_env.h>
90@@ -143,6 +151,95 @@ static void dump_blob(void *blob, bool debug)
91 }
92 }
93
94+static void dump_live_internal(const char *path, bool debug, int depth)
95+{
96+ int maxsz = strlen(path) + 1 + PATH_MAX;
97+ char *new_path = alloca(maxsz + 1);
98+ struct stat sb;
99+ struct dirent *de;
100+ char *buf, *p;
101+ int buf_alloc, shift, chunk, left, fd, ret;
102+ DIR *d;
103+
104+ shift = 4;
105+ buf_alloc = 4 * 1024; /* 4K (maximum chunk) */
106+ buf = alloca(buf_alloc + sizeof(uint32_t));
107+ buf[buf_alloc] = '\0'; /* always terminate (just in case) */
108+
109+ d = opendir(path);
110+ if (d == NULL)
111+ die("Could not open %s directory\n", path);
112+
113+ /* first dump the properties (files) */
114+ while ((de = readdir(d)) != NULL) {
115+ /* properties are files */
116+ if (de->d_type != DT_REG)
117+ continue;
118+ snprintf(new_path, maxsz, "%s/%s", path, de->d_name);
119+ new_path[maxsz] = '\0';
120+ printf("%*s%s", depth * shift, "", de->d_name);
121+
122+ if (stat(new_path, &sb) != 0)
123+ die("could not open: %s\n", new_path);
124+
125+ fd = open(new_path, O_RDONLY);
126+ if (fd == -1)
127+ die("Could not open: %s\n", new_path);
128+
129+ chunk = sb.st_size > buf_alloc ? buf_alloc : sb.st_size;
130+ p = buf;
131+ left = chunk;
132+ while (left > 0) {
133+ do {
134+ ret = read(fd, p, left);
135+ } while (ret == -1 && (errno == EAGAIN || errno == EINTR));
136+ if (ret == -1)
137+ die("Read failed on: %s\n", new_path);
138+ left -= ret;
139+ p += ret;
140+ }
141+ close(fd);
142+
143+ if (chunk < sb.st_size)
144+ printf(" (trunc)");
145+ utilfdt_print_data(buf, chunk);
146+ printf(";\n");
147+ }
148+
149+ /* now recurse to the directories */
150+ rewinddir(d);
151+ while ((de = readdir(d)) != NULL) {
152+ /* properties are files */
153+ if (de->d_type != DT_DIR)
154+ continue;
155+ /* skip current and parent directories */
156+ if (strcmp(de->d_name, ".") == 0 ||
157+ strcmp(de->d_name, "..") == 0)
158+ continue;
159+ snprintf(new_path, maxsz, "%s/%s", path, de->d_name);
160+ new_path[maxsz] = '\0';
161+ printf("%*s%s {\n", depth * shift, "", de->d_name);
162+ dump_live_internal(new_path, debug, depth + 1);
163+ printf("%*s};\n", depth * shift, "");
164+ }
165+}
166+
167+static void dump_live(const char *path, bool debug)
168+{
169+ char *fixed_path = alloca(strlen(path) + 1);
170+ char *p;
171+
172+ /* strip trailing / */
173+ strcpy(fixed_path, path);
174+ p = fixed_path + strlen(fixed_path) - 1;
175+ while (*p == '/' && p > fixed_path)
176+ *p-- = '\0';
177+ printf("/* dump of live tree at %s */\n", fixed_path);
178+ printf("/ {\n");
179+ dump_live_internal(fixed_path, debug, 1);
180+ printf("};\n");
181+}
182+
183 /* Usage related data. */
184 static const char usage_synopsis[] = "fdtdump [options] <file>";
185 static const char usage_short_opts[] = "ds" USAGE_COMMON_SHORT_OPTS;
186@@ -165,6 +262,7 @@ int main(int argc, char *argv[])
187 bool debug = false;
188 bool scan = false;
189 off_t len;
190+ struct stat sb;
191
192 while ((opt = util_getopt_long()) != EOF) {
193 switch (opt) {
194@@ -182,6 +280,15 @@ int main(int argc, char *argv[])
195 usage("missing input filename");
196 file = argv[optind];
197
198+ if (stat(file, &sb) != 0)
199+ die("could not open: %s\n", file);
200+
201+ /* dump live tree if it's a directory */
202+ if (S_ISDIR(sb.st_mode)) {
203+ dump_live(file, debug);
204+ return 0;
205+ }
206+
207 buf = utilfdt_read_len(file, &len);
208 if (!buf)
209 die("could not read: %s\n", file);
210--
2111.9.1
212