diff mbox

[3/4] kvm tools: arm: make .dtb dumping a command-line option

Message ID 1357582501-6024-4-git-send-email-will.deacon@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Will Deacon Jan. 7, 2013, 6:15 p.m. UTC
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 <will.deacon@arm.com>
---
 tools/kvm/arm/fdt.c                         | 18 ++++++------------
 tools/kvm/arm/include/kvm/kvm-config-arch.h |  8 ++++++++
 2 files changed, 14 insertions(+), 12 deletions(-)
diff mbox

Patch

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 <linux/kernel.h>
 #include <linux/sizes.h>
 
-#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 */