From patchwork Thu Sep 1 21:51:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 9309815 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 36F1E60756 for ; Thu, 1 Sep 2016 21:53:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6731528425 for ; Thu, 1 Sep 2016 21:53:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C0972955B; Thu, 1 Sep 2016 21:53:45 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham 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 1577F28425 for ; Thu, 1 Sep 2016 21:53:45 +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 1bfZuD-0000sE-UA; Thu, 01 Sep 2016 21:52:17 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bfZtC-0000T2-Ic; Thu, 01 Sep 2016 21:51:14 +0000 Received: from geoff by merlin.infradead.org with local (Exim 4.85_2 #1 (Red Hat Linux)) id 1bfZt8-0007JP-L5; Thu, 01 Sep 2016 21:51:10 +0000 Message-Id: <26a67f5fa8ecf7d76c908a5e0d8ee8bf4f9cb578.1472766405.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 1 Sep 2016 14:33:49 -0700 Subject: [PATCH v5 3/3] arm64: Add support for binary image files To: Simon Horman Date: Thu, 01 Sep 2016 21:51:10 +0000 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: Pratyush Anand , AKASHI Takahiro , Mark Rutland , kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.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 From: Pratyush Anand Signed-off-by: Pratyush Anand [Reworked and cleaned up] Signed-off-by: Geoff Levand --- kexec/arch/arm64/kexec-image-arm64.c | 49 ++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/kexec/arch/arm64/kexec-image-arm64.c b/kexec/arch/arm64/kexec-image-arm64.c index 42d2ea7..960ed96 100644 --- a/kexec/arch/arm64/kexec-image-arm64.c +++ b/kexec/arch/arm64/kexec-image-arm64.c @@ -3,7 +3,9 @@ */ #define _GNU_SOURCE + #include "kexec-arm64.h" +#include int image_arm64_probe(const char *kernel_buf, off_t kernel_size) { @@ -21,14 +23,53 @@ int image_arm64_probe(const char *kernel_buf, off_t kernel_size) return -1; } - fprintf(stderr, "kexec: ARM64 binary image files are currently NOT SUPPORTED.\n"); - return -1; + return 0; } int image_arm64_load(int argc, char **argv, const char *kernel_buf, off_t kernel_size, struct kexec_info *info) { - return -1; + const struct arm64_image_header *header; + unsigned long kernel_segment; + int result; + + header = (const struct arm64_image_header *)(kernel_buf); + + if (arm64_process_image_header(header)) + return -1; + + kernel_segment = arm64_locate_kernel_segment(info); + + if (kernel_segment == ULONG_MAX) { + dbgprintf("%s: Kernel segment is not allocated\n", __func__); + result = -EFAILED; + goto exit; + } + + dbgprintf("%s: kernel_segment: %016lx\n", __func__, kernel_segment); + dbgprintf("%s: text_offset: %016lx\n", __func__, + arm64_mem.text_offset); + dbgprintf("%s: image_size: %016lx\n", __func__, + arm64_mem.image_size); + dbgprintf("%s: phys_offset: %016lx\n", __func__, + arm64_mem.phys_offset); + dbgprintf("%s: vp_offset: %016lx\n", __func__, + arm64_mem.vp_offset); + dbgprintf("%s: PE format: %s\n", __func__, + (arm64_header_check_pe_sig(header) ? "yes" : "no")); + + /* load the kernel */ + add_segment_phys_virt(info, kernel_buf, kernel_size, + kernel_segment + arm64_mem.text_offset, + arm64_mem.image_size, 0); + + result = arm64_load_other_segments(info, kernel_segment + + arm64_mem.text_offset); + +exit: + if (result) + fprintf(stderr, "kexec: load failed.\n"); + return result; } void image_arm64_usage(void) @@ -36,6 +77,4 @@ void image_arm64_usage(void) printf( " An ARM64 binary image, compressed or not, big or little endian.\n" " Typically an Image, Image.gz or Image.lzma file.\n\n"); - printf( -" ARM64 binary image files are currently NOT SUPPORTED.\n\n"); }