From patchwork Tue Dec 6 03:41:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Evans X-Patchwork-Id: 129511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 495841007D4 for ; Tue, 6 Dec 2011 14:40:28 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932933Ab1LFDkV (ORCPT ); Mon, 5 Dec 2011 22:40:21 -0500 Received: from ozlabs.org ([203.10.76.45]:48698 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932871Ab1LFDkU (ORCPT ); Mon, 5 Dec 2011 22:40:20 -0500 Received: from [10.61.2.183] (ibmaus65.lnk.telstra.net [165.228.126.9]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPSA id 39E941007D5; Tue, 6 Dec 2011 14:40:17 +1100 (EST) Message-ID: <4EDD8ED3.8010608@ozlabs.org> Date: Tue, 06 Dec 2011 14:41:07 +1100 From: Matt Evans User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110921 Thunderbird/3.1.15 MIME-Version: 1.0 To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Subject: [PATCH 16/28] kvm tools: Allow load_flat_binary() to load an initrd alongside References: In-Reply-To: Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org This patch passes the initrd fd and commandline to load_flat_binary(), which may be used to load both the kernel & an initrd (stashing or inserting the commandline as appropriate) in the same way that load_bzimage() does. This is especially useful when load_bzimage() is unused for a particular architecture. :-) Signed-off-by: Matt Evans --- tools/kvm/include/kvm/kvm.h | 2 +- tools/kvm/kvm.c | 10 ++++++---- tools/kvm/x86/kvm.c | 12 +++++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index fae2ba9..5fe6e75 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -59,7 +59,7 @@ void kvm__arch_setup_firmware(struct kvm *kvm); bool kvm__arch_cpu_supports_vm(void); void kvm__arch_periodic_poll(struct kvm *kvm); -int load_flat_binary(struct kvm *kvm, int fd); +int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline); bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline, u16 vidmode); /* diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 457de1a..6f33e1a 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -354,23 +354,25 @@ bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename, ret = load_bzimage(kvm, fd_kernel, fd_initrd, kernel_cmdline, vidmode); - if (initrd_filename) - close(fd_initrd); - if (ret) goto found_kernel; pr_warning("%s is not a bzImage. Trying to load it as a flat binary...", kernel_filename); - ret = load_flat_binary(kvm, fd_kernel); + ret = load_flat_binary(kvm, fd_kernel, fd_initrd, kernel_cmdline); + if (ret) goto found_kernel; + if (initrd_filename) + close(fd_initrd); close(fd_kernel); die("%s is not a valid bzImage or flat binary", kernel_filename); found_kernel: + if (initrd_filename) + close(fd_initrd); close(fd_kernel); return ret; diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c index 7071dc6..4ac21c0 100644 --- a/tools/kvm/x86/kvm.c +++ b/tools/kvm/x86/kvm.c @@ -227,17 +227,23 @@ void kvm__irq_trigger(struct kvm *kvm, int irq) #define BOOT_PROTOCOL_REQUIRED 0x206 #define LOAD_HIGH 0x01 -int load_flat_binary(struct kvm *kvm, int fd) +int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline) { void *p; int nr; - if (lseek(fd, 0, SEEK_SET) < 0) + /* Some architectures may support loading an initrd alongside the flat kernel, + * but we do not. + */ + if (fd_initrd != -1) + pr_warning("Loading initrd with flat binary not supported."); + + if (lseek(fd_kernel, 0, SEEK_SET) < 0) die_perror("lseek"); p = guest_real_to_host(kvm, BOOT_LOADER_SELECTOR, BOOT_LOADER_IP); - while ((nr = read(fd, p, 65536)) > 0) + while ((nr = read(fd_kernel, p, 65536)) > 0) p += nr; kvm->boot_selector = BOOT_LOADER_SELECTOR;