From patchwork Tue Oct 18 16:33:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Griffin X-Patchwork-Id: 9382703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E606600CA for ; Tue, 18 Oct 2016 16:35:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DD65296A3 for ; Tue, 18 Oct 2016 16:35:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 010E6296AB; Tue, 18 Oct 2016 16:35:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C4DF296A3 for ; Tue, 18 Oct 2016 16:35:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwXKs-0002b9-3R; Tue, 18 Oct 2016 16:33:54 +0000 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwXKk-0002Rm-09 for linux-arm-kernel@lists.infradead.org; Tue, 18 Oct 2016 16:33:48 +0000 Received: by mail-wm0-x232.google.com with SMTP id c78so3299825wme.0 for ; Tue, 18 Oct 2016 09:33:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=W/B1cQFPbZAzJ7OEapx3VXCbHUFgVroM3crTA0Jj02c=; b=dV+6Dw1SSaLWwXVI3lKTUu24KW00B340dH/J5+rUkiG0K2Vw9RKWaaNqqVXBFVw4cS xukwCs2eORU3jKuTSdsFacjqJqSM4Y9ICiegapeOOMBUWVJjsTl2HGJo8yPer+RoVTaB T7hxTUWBmLfI9Aqp3R7Rtzy7eigKcSHGMCbYs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=W/B1cQFPbZAzJ7OEapx3VXCbHUFgVroM3crTA0Jj02c=; b=mWf5KSIPm/UBWnCbPSsWffQck9gMuDKCGzGUcLtgaIyWDzoUd7CftRNipIUQCVJtBx kZLx+6tJylTQeQtt5qSUxzS7wyxcvbHTgklteiu4VjAuyBr+rjSe+YQVeLINqkrkxFuA ODqzRgIPszlK1t/W+WfVn/5EyUEOULUx7Jolnob/7MCFDqGDibA5CZKJrNFGKOOFwIcp wtCJbrYhKitshWvvCxr5/74bI2HnIn7uBAqRIuWwR0P1IgY85dq6uBCSxZecShDy87Gi ICjCGK0FUjxroyBBflcojz3tb+uxNPyncAgaPbLMO1MReDc9Dk65dEM+jx2m8nooVA4d 1IdA== X-Gm-Message-State: AA6/9RnJbw3Cy83ZZdPk7GW0lwQKj4AS57fQbzGLSa8/k7BtZBQENFrty6F7IEDOyuXBgJFx X-Received: by 10.28.138.209 with SMTP id m200mr11896870wmd.89.1476808403942; Tue, 18 Oct 2016 09:33:23 -0700 (PDT) Received: from localhost.localdomain (cpc89244-aztw30-2-0-cust4998.18-1.cable.virginm.net. [86.31.179.135]) by smtp.gmail.com with ESMTPSA id a1sm64050324wjl.28.2016.10.18.09.33.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Oct 2016 09:33:23 -0700 (PDT) From: Peter Griffin To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@stlinux.com, jan.kiszka@siemens.com, kieran@bingham.xyz Subject: [PATCH v2] scripts/gdb: add lx-fdtdump command Date: Tue, 18 Oct 2016 17:33:20 +0100 Message-Id: <1476808400-28407-1-git-send-email-peter.griffin@linaro.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161018_093346_442082_01ACA24F X-CRM114-Status: GOOD ( 15.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.griffin@linaro.org, devicetree@vger.kernel.org, lee.jones@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Peter Griffin --- Changes since v1 - s/flatenned/flattened/ (Kieran) - Add filename as argument to command (Jan / Kieran) - Check LX_CONFIG_OF early to reduce indendation (Kieran) - Add gdb.COMPLETE_FILENAME to get auto completion (Jan) - Squash pep8 fixup patch (Kieran) --- scripts/gdb/linux/constants.py.in | 8 +++++ scripts/gdb/linux/proc.py | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in index 7986f4e..43c6241 100644 --- a/scripts/gdb/linux/constants.py.in +++ b/scripts/gdb/linux/constants.py.in @@ -14,6 +14,7 @@ #include #include +#include /* We need to stringify expanded macros so that they can be parsed */ @@ -50,3 +51,10 @@ LX_VALUE(MNT_NOEXEC) LX_VALUE(MNT_NOATIME) LX_VALUE(MNT_NODIRATIME) LX_VALUE(MNT_RELATIME) + +/* linux/of_fdt.h> */ +LX_VALUE(OF_DT_HEADER) + +/* Kernel Configs */ +LX_CONFIG(CONFIG_OF) + diff --git a/scripts/gdb/linux/proc.py b/scripts/gdb/linux/proc.py index 38b1f09..086d272 100644 --- a/scripts/gdb/linux/proc.py +++ b/scripts/gdb/linux/proc.py @@ -16,6 +16,7 @@ from linux import constants from linux import utils from linux import tasks from linux import lists +from struct import * class LxCmdLine(gdb.Command): @@ -195,3 +196,75 @@ values of that process namespace""" info_opts(MNT_INFO, m_flags))) LxMounts() + + +class LxFdtDump(gdb.Command): + """Output Flattened Device Tree header and dump FDT blob to the filename + specified as the command argument. Equivalent to + 'cat /proc/fdt > fdtdump.dtb' on a running target""" + + def __init__(self): + super(LxFdtDump, self).__init__("lx-fdtdump", gdb.COMMAND_DATA, + gdb.COMPLETE_FILENAME) + + def fdthdr_to_cpu(self, fdt_header): + + fdt_header_be = ">IIIIIII" + fdt_header_le = "