From patchwork Mon Jan 7 18:15:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 1941751 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id F0FC5DF215 for ; Mon, 7 Jan 2013 18:15:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753751Ab3AGSP3 (ORCPT ); Mon, 7 Jan 2013 13:15:29 -0500 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:47489 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753702Ab3AGSP2 (ORCPT ); Mon, 7 Jan 2013 13:15:28 -0500 Received: from mudshark.cambridge.arm.com (mudshark.cambridge.arm.com [10.1.79.58]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id r07IF7ki005580; Mon, 7 Jan 2013 18:15:07 GMT Received: by mudshark.cambridge.arm.com (Postfix, from userid 1000) id 813E9C2B12; Mon, 7 Jan 2013 18:15:02 +0000 (GMT) From: Will Deacon To: kvm@vger.kernel.org Cc: penberg@kernel.org, marc.zyngier@arm.com, c.dall@virtualopensystems.com, kvmarm@lists.cs.columbia.edu, Will Deacon Subject: [PATCH 3/4] kvm tools: arm: make .dtb dumping a command-line option Date: Mon, 7 Jan 2013 18:15:00 +0000 Message-Id: <1357582501-6024-4-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1357582501-6024-1-git-send-email-will.deacon@arm.com> References: <1357582501-6024-1-git-send-email-will.deacon@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org It can sometimes be useful to dump the .dtb file generated by kvmtool when debugging a guest. Currently, this is achieved by rebuilding the tool and changing some #defines, which is fairly clumsy to use. This patch adds a new command-line option for ARM, allowing the dtb to be dumped to a named file at runtime. Signed-off-by: Will Deacon --- tools/kvm/arm/fdt.c | 18 ++++++------------ tools/kvm/arm/include/kvm/kvm-config-arch.h | 8 ++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/kvm/arm/fdt.c b/tools/kvm/arm/fdt.c index c7f4b52..e52c10c 100644 --- a/tools/kvm/arm/fdt.c +++ b/tools/kvm/arm/fdt.c @@ -13,9 +13,6 @@ #include #include -#define DEBUG 0 -#define DEBUG_FDT_DUMP_FILE "/tmp/kvmtool.dtb" - static char kern_cmdline[COMMAND_LINE_SIZE]; bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename) @@ -28,25 +25,21 @@ int kvm__arch_setup_firmware(struct kvm *kvm) return 0; } -#if DEBUG -static void dump_fdt(void *fdt) +static void dump_fdt(const char *dtb_file, void *fdt) { int count, fd; - fd = open(DEBUG_FDT_DUMP_FILE, O_CREAT | O_TRUNC | O_RDWR, 0666); + fd = open(dtb_file, O_CREAT | O_TRUNC | O_RDWR, 0666); if (fd < 0) - die("Failed to write dtb to %s", DEBUG_FDT_DUMP_FILE); + die("Failed to write dtb to %s", dtb_file); count = write(fd, fdt, FDT_MAX_SIZE); if (count < 0) die_perror("Failed to dump dtb"); - pr_info("Wrote %d bytes to dtb %s\n", count, DEBUG_FDT_DUMP_FILE); + pr_info("Wrote %d bytes to dtb %s\n", count, dtb_file); close(fd); } -#else -static void dump_fdt(void *fdt) { } -#endif #define DEVICE_NAME_MAX_LEN 32 static void generate_virtio_mmio_node(void *fdt, struct virtio_mmio *vmmio) @@ -143,7 +136,8 @@ static int setup_fdt(struct kvm *kvm) _FDT(fdt_open_into(fdt, fdt_dest, FDT_MAX_SIZE)); _FDT(fdt_pack(fdt_dest)); - dump_fdt(fdt_dest); + if (kvm->cfg.arch.dump_dtb_filename) + dump_fdt(kvm->cfg.arch.dump_dtb_filename, fdt_dest); return 0; } late_init(setup_fdt); diff --git a/tools/kvm/arm/include/kvm/kvm-config-arch.h b/tools/kvm/arm/include/kvm/kvm-config-arch.h index 60f61de..f63f302 100644 --- a/tools/kvm/arm/include/kvm/kvm-config-arch.h +++ b/tools/kvm/arm/include/kvm/kvm-config-arch.h @@ -1,7 +1,15 @@ #ifndef KVM__KVM_CONFIG_ARCH_H #define KVM__KVM_CONFIG_ARCH_H +#include "kvm/parse-options.h" + struct kvm_config_arch { + const char *dump_dtb_filename; }; +#define OPT_ARCH_RUN(pfx, cfg) \ + pfx, \ + OPT_STRING('\0', "dump-dtb", &(cfg)->dump_dtb_filename, \ + ".dtb file", "Dump generated .dtb to specified file"), + #endif /* KVM__KVM_CONFIG_ARCH_H */