aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/gdb/linux/proc.py
diff options
context:
space:
mode:
authorPeter Griffin <peter.griffin@linaro.org>2017-07-12 17:34:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-12 19:26:00 -0400
commit821f74402a4c67de63cb6bab5bae7c7a3b298ac2 (patch)
treefcd6b0920d7de0d5d0e1975083696ae259d2cf40 /scripts/gdb/linux/proc.py
parent59224ac1cf9cacf76a82266854921ca6c9887f20 (diff)
scripts/gdb: add lx-fdtdump command
lx-fdtdump dumps the flattened device tree passed to the kernel from the bootloader to the filename specified as the command argument. If no argument is provided it defaults to fdtdump.dtb. This then allows further post processing on the machine running GDB. The fdt header is also also printed in the GDB console. For example: (gdb) lx-fdtdump fdt_magic: 0xD00DFEED fdt_totalsize: 0xC108 off_dt_struct: 0x38 off_dt_strings: 0x3804 off_mem_rsvmap: 0x28 version: 17 last_comp_version: 16 Dumped fdt to fdtdump.dtb >fdtdump fdtdump.dtb | less This command is useful as the bootloader can often re-write parts of the device tree, and this can sometimes cause the kernel to not boot. Link: http://lkml.kernel.org/r/1481280065-5336-2-git-send-email-kbingham@kernel.org Signed-off-by: Peter Griffin <peter.griffin@linaro.org> Signed-off-by: Kieran Bingham <kbingham@kernel.org> Cc: Jason Wessel <jason.wessel@windriver.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/gdb/linux/proc.py')
-rw-r--r--scripts/gdb/linux/proc.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/scripts/gdb/linux/proc.py b/scripts/gdb/linux/proc.py
index 38b1f09d1cd9..086d27223c0c 100644
--- a/scripts/gdb/linux/proc.py
+++ b/scripts/gdb/linux/proc.py
@@ -16,6 +16,7 @@ from linux import constants
16from linux import utils 16from linux import utils
17from linux import tasks 17from linux import tasks
18from linux import lists 18from linux import lists
19from struct import *
19 20
20 21
21class LxCmdLine(gdb.Command): 22class LxCmdLine(gdb.Command):
@@ -195,3 +196,75 @@ values of that process namespace"""
195 info_opts(MNT_INFO, m_flags))) 196 info_opts(MNT_INFO, m_flags)))
196 197
197LxMounts() 198LxMounts()
199
200
201class LxFdtDump(gdb.Command):
202 """Output Flattened Device Tree header and dump FDT blob to the filename
203 specified as the command argument. Equivalent to
204 'cat /proc/fdt > fdtdump.dtb' on a running target"""
205
206 def __init__(self):
207 super(LxFdtDump, self).__init__("lx-fdtdump", gdb.COMMAND_DATA,
208 gdb.COMPLETE_FILENAME)
209
210 def fdthdr_to_cpu(self, fdt_header):
211
212 fdt_header_be = ">IIIIIII"
213 fdt_header_le = "<IIIIIII"
214
215 if utils.get_target_endianness() == 1:
216 output_fmt = fdt_header_le
217 else:
218 output_fmt = fdt_header_be
219
220 return unpack(output_fmt, pack(fdt_header_be,
221 fdt_header['magic'],
222 fdt_header['totalsize'],
223 fdt_header['off_dt_struct'],
224 fdt_header['off_dt_strings'],
225 fdt_header['off_mem_rsvmap'],
226 fdt_header['version'],
227 fdt_header['last_comp_version']))
228
229 def invoke(self, arg, from_tty):
230
231 if not constants.LX_CONFIG_OF:
232 raise gdb.GdbError("Kernel not compiled with CONFIG_OF\n")
233
234 if len(arg) == 0:
235 filename = "fdtdump.dtb"
236 else:
237 filename = arg
238
239 py_fdt_header_ptr = gdb.parse_and_eval(
240 "(const struct fdt_header *) initial_boot_params")
241 py_fdt_header = py_fdt_header_ptr.dereference()
242
243 fdt_header = self.fdthdr_to_cpu(py_fdt_header)
244
245 if fdt_header[0] != constants.LX_OF_DT_HEADER:
246 raise gdb.GdbError("No flattened device tree magic found\n")
247
248 gdb.write("fdt_magic: 0x{:02X}\n".format(fdt_header[0]))
249 gdb.write("fdt_totalsize: 0x{:02X}\n".format(fdt_header[1]))
250 gdb.write("off_dt_struct: 0x{:02X}\n".format(fdt_header[2]))
251 gdb.write("off_dt_strings: 0x{:02X}\n".format(fdt_header[3]))
252 gdb.write("off_mem_rsvmap: 0x{:02X}\n".format(fdt_header[4]))
253 gdb.write("version: {}\n".format(fdt_header[5]))
254 gdb.write("last_comp_version: {}\n".format(fdt_header[6]))
255
256 inf = gdb.inferiors()[0]
257 fdt_buf = utils.read_memoryview(inf, py_fdt_header_ptr,
258 fdt_header[1]).tobytes()
259
260 try:
261 f = open(filename, 'wb')
262 except:
263 raise gdb.GdbError("Could not open file to dump fdt")
264
265 f.write(fdt_buf)
266 f.close()
267
268 gdb.write("Dumped fdt blob to " + filename + "\n")
269
270LxFdtDump()