diff options
Diffstat (limited to 'scripts/gdb/linux/proc.py')
-rw-r--r-- | scripts/gdb/linux/proc.py | 73 |
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 | |||
16 | from linux import utils | 16 | from linux import utils |
17 | from linux import tasks | 17 | from linux import tasks |
18 | from linux import lists | 18 | from linux import lists |
19 | from struct import * | ||
19 | 20 | ||
20 | 21 | ||
21 | class LxCmdLine(gdb.Command): | 22 | class 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 | ||
197 | LxMounts() | 198 | LxMounts() |
199 | |||
200 | |||
201 | class 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 | |||
270 | LxFdtDump() | ||