From patchwork Tue Oct 18 15:07:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Griffin X-Patchwork-Id: 9382325 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 8C2AE600CA for ; Tue, 18 Oct 2016 15:09:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AC1828F7C for ; Tue, 18 Oct 2016 15:09:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F4912963E; Tue, 18 Oct 2016 15:09:44 +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 0560D28F7C for ; Tue, 18 Oct 2016 15:09:40 +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 1bwW07-0001oX-7d; Tue, 18 Oct 2016 15:08:23 +0000 Received: from mail-lf0-x232.google.com ([2a00:1450:4010:c07::232]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwVzk-0001bP-7g for linux-arm-kernel@lists.infradead.org; Tue, 18 Oct 2016 15:08:02 +0000 Received: by mail-lf0-x232.google.com with SMTP id l131so29013834lfl.2 for ; Tue, 18 Oct 2016 08:07:37 -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=mO+ygbHkqP6VBLzeTFfbdv1YEy4ci55cWCbIPm02wcE=; b=FlSBA/NETZMLvZfhOp4V81i6I4oI84cxFFr/XOaTHjre/tAS+kJrjTnRzWM+d7icD9 rrRadA85otXnC1IGvqJvAzzycTB88B8Xao09tQ9etrALi/fe2Nl9YDmH7d6rdKDG6V3F MkuvfFjym28nhbOPdF/krKJ4p2+JXdfteHbFA= 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=mO+ygbHkqP6VBLzeTFfbdv1YEy4ci55cWCbIPm02wcE=; b=WHKNchdVclKRvVtTCj5zqUItlUArCvcah73ND4WHl2EYtMZYbSAwNrXncvYlBjs9gN Wud9gtBrUNFCs2wsmK/9Tb3c5JuRzbbTzxHOSVphDkmPpPVImG9KE5ab45vuUcpEy/vZ AJxG4wbpfWIisuQPTJ21+8alQeeBruvGY+rz6oR00diMt+ZKJl02d1VPJ2fgGHpXBg2y uuQoJaHKHNo9JGYFCSpqmUdJ71Hk9kSHCJuqek8THn/pSEzbQE3xP2fD6xfRNCdmYBYl Kzf9HiGX46uQMlv3LUzeqEWrinFfAnURQGkOm+ynTbGjKEANrkxYgupuLqtbdgp39Qzs Y+yg== X-Gm-Message-State: AA6/9RlUQCpwiL0NxSrj4QdmG12I3Ee8u4ZotnTa1aw3XzBsCqXPCtv2Xg1L65hNmHmgtnhw X-Received: by 10.194.216.37 with SMTP id on5mr514617wjc.162.1476803254572; Tue, 18 Oct 2016 08:07:34 -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 ce6sm63427784wjc.27.2016.10.18.08.07.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Oct 2016 08:07:33 -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 1/2] scripts/gdb: add lx-fdtdump command Date: Tue, 18 Oct 2016 16:07:28 +0100 Message-Id: <1476803249-23328-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_080800_541017_40803AB0 X-CRM114-Status: GOOD ( 16.42 ) 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 flatenned device tree passed to the kernel from the bootloader to a file called fdtdump.dtb to allow 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 --- scripts/gdb/linux/constants.py.in | 8 +++++ scripts/gdb/linux/proc.py | 70 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) 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..f20fcfa 100644 --- a/scripts/gdb/linux/proc.py +++ b/scripts/gdb/linux/proc.py @@ -16,7 +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): """ Report the Linux Commandline used in the current kernel. @@ -195,3 +195,71 @@ 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 a file + Equivalent to 'cat /proc/fdt > fdtdump.dtb' on a running target""" + + def __init__(self): + super(LxFdtDump, self).__init__("lx-fdtdump", gdb.COMMAND_DATA) + + def fdthdr_to_cpu(self, fdt_header): + + fdt_header_be = ">IIIIIII" + fdt_header_le = "