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: 78103 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp970995qge; Tue, 18 Oct 2016 09:33:38 -0700 (PDT) X-Received: by 10.107.55.137 with SMTP id e131mr2062166ioa.76.1476808417467; Tue, 18 Oct 2016 09:33:37 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sn9si30427410pab.296.2016.10.18.09.33.36; Tue, 18 Oct 2016 09:33:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754532AbcJRQdd (ORCPT + 27 others); Tue, 18 Oct 2016 12:33:33 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:33072 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751083AbcJRQdZ (ORCPT ); Tue, 18 Oct 2016 12:33:25 -0400 Received: by mail-wm0-f54.google.com with SMTP id g16so489296wmg.0 for ; Tue, 18 Oct 2016 09:33:24 -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=jb1KjQaEU4ADOT9BGi1PqfoKrfTg6WXRX2eVbmVoCWg1kUDHkvw2ne+KCsxc9cZOgv XG30HR0xCYuhjV+AKomJbjtIsOlR2Rn9O5rLlnT0crWU6+h//V4rdBRWhxnLtuwXGJ18 OHlZ5sw+4zCp3a+UW4pJV63uOOO492jE3c/uzFRRJwanF+SHNd+8S0Wo80jMKCUh3UY8 WWvAs7aniQv7rpBbh9eN8YMXzJEYbDmHtvsfDXOA5hChD4+vlAo9u9s1nrDLuq1w6Z93 iOKFP/KKmuDReeclZq/noiaZ61V9jD43sAAT7tOyiH6JzVg+gcohp2nJrTzkM/e4Mnsd WtzQ== X-Gm-Message-State: AA6/9RmwKtqrC600poCRQdqpUabXKBDe54k8CxLRpVV6mqEp7cJX9kePBP888eXwbKLAp/Vl 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@ksquared.org.uk Cc: peter.griffin@linaro.org, lee.jones@linaro.org, devicetree@vger.kernel.org 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(+) -- 1.9.1 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 = "