From patchwork Fri Aug 9 00:53:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roy Franz X-Patchwork-Id: 2841487 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 35A68BF546 for ; Fri, 9 Aug 2013 00:53:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D41B2039D for ; Fri, 9 Aug 2013 00:53:48 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 372B72039C for ; Fri, 9 Aug 2013 00:53:47 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7axc-0005vH-JZ; Fri, 09 Aug 2013 00:53:44 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7axa-0007OV-9o; Fri, 09 Aug 2013 00:53:42 +0000 Received: from mail-vb0-f45.google.com ([209.85.212.45]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7axX-0007Nt-Eb for linux-arm-kernel@lists.infradead.org; Fri, 09 Aug 2013 00:53:40 +0000 Received: by mail-vb0-f45.google.com with SMTP id e15so3692736vbg.18 for ; Thu, 08 Aug 2013 17:53:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=E06MKgsvXYpD7VVd3nyC09Pdo4AuJJiUBMdQhuj3AmE=; b=I1VDruXpAwE+7skWvTgyHT6nwaABwUWYGPnk99oFo3+WjX/5vvvNz5u5qh/YGU7uuf JXFjPL8OsO8i4B05JQgQXWhu+oT5cpIJw+6jGnai1uj0bhVbIFKtqur7AXksvXi4ETKl Zjk76YdmV5qHUOUV76NiHxn4iwTMdxMeBT06y5BXpXCmG6grutLcvcp4dGq3E/bAPzxv sjO0ILodRwe5F0zc2NhhPC8bLI6NzQh/WLRMCtGlLM4zbgFkNjXyEaMVBuO6ANTH+7ao 3hc97hiViSst6wJhrDMlQ+RcfYj8NprG2gfBeQzrzTsxtniNmZr54bDcHb8ALfYOZEcu 1aYg== X-Gm-Message-State: ALoCoQnG3YL0eKFUZXbYG6ro+7N7lRbqJw46+l5I5zBhg+Ummrq6mnFswx0BZwSQ9o6eui+mqycC MIME-Version: 1.0 X-Received: by 10.220.45.132 with SMTP id e4mr5571615vcf.56.1376009596766; Thu, 08 Aug 2013 17:53:16 -0700 (PDT) Received: by 10.221.6.74 with HTTP; Thu, 8 Aug 2013 17:53:16 -0700 (PDT) In-Reply-To: References: <1375847113-24884-1-git-send-email-roy.franz@linaro.org> <1375847113-24884-17-git-send-email-roy.franz@linaro.org> <20130807180548.GA12592@localhost.localdomain> Date: Thu, 8 Aug 2013 17:53:16 -0700 Message-ID: Subject: Re: [PATCH 16/17] Add EFI stub for ARM From: Roy Franz To: Dave Martin X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130808_205339_582597_FD2BDE74 X-CRM114-Status: GOOD ( 15.31 ) X-Spam-Score: -2.6 (--) Cc: linux-efi@vger.kernel.org, Russell King - ARM Linux , linux-kernel@vger.kernel.org, Leif Lindholm , matt.fleming@intel.com, "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Dave - here is an updated patch for head.S, I'm still working on the rest. I will make the EFI stub depend on !CPU_ENDIAN_BE32 to make the stub LE only for now. I think I have addressed the rest of your comments in head.S in the patch below. I will send a complete new series once I have the other changes, mostly in efi-stub.c, complete. Thanks, Roy diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index 75189f1..5401a3a 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -10,6 +10,7 @@ */ #include #include +#include "efi-stub.h" .arch armv7-a /* @@ -120,21 +121,99 @@ */ .align .arm @ Always enter in ARM state + .text start: .type start,#function - .rept 7 +#ifdef CONFIG_EFI_STUB + @ Magic MSDOS signature for PE/COFF + ADD opcode + .word 0x62805a4d +#else + mov r0, r0 +#endif + .rept 5 mov r0, r0 .endr - ARM( mov r0, r0 ) - ARM( b 1f ) - THUMB( adr r12, BSYM(1f) ) - THUMB( bx r12 ) + + adrl r12, BSYM(zimage_continue) + ARM( mov pc, r12 ) + THUMB( bx r12 ) + @ zimage_continue will be in ARM or thumb mode as configured .word 0x016f2818 @ Magic numbers to help the loader .word start @ absolute load/run zImage address .word _edata @ zImage end address + +#ifdef CONFIG_EFI_STUB + @ Portions of the MSDOS file header must be at offset + @ 0x3c from the start of the file. All PE/COFF headers + @ are kept contiguous for simplicity. +#include "efi-header.S" + +efi_stub_entry: + @ The EFI stub entry point is not at a fixed address, however + @ this address must be set in the PE/COFF header. + @ EFI entry point is in A32 mode, switch to T32 if configured. + THUMB( adr r12, BSYM(1f) ) + THUMB( bx r12 ) THUMB( .thumb ) 1: + @ Save lr on stack for possible return to EFI firmware. + @ Don't care about fp, but need 64 bit alignment.... + stmfd sp!, {fp, lr} + + @ allocate space on stack for return of new entry point of + @ zImage, as EFI stub may copy the kernel. Pass address + @ of space in r2 - EFI stub will fill in the pointer. + + sub sp, sp, #8 @ we only need 4 bytes, + @ but keep stack 8 byte aligned. + mov r2, sp + @ Pass our actual runtime start address in pointer data + adr r11, LC0 @ address of LC0 at run time + ldr r12, [r11, #0] @ address of LC0 at link time + + sub r3, r11, r12 @ calculate the delta offset + str r3, [r2, #0] + bl efi_entry + + @ get new zImage entry address from stack, put into r3 + ldr r3, [sp, #0] + add sp, sp, #8 @ restore stack + + @ Check for error return from EFI stub + mov r1, #EFI_STUB_ERROR + cmp r0, r1 + beq efi_load_fail + + + @ Save return values of efi_entry + stmfd sp!, {r0, r3} + bl cache_clean_flush + bl cache_off + ldmfd sp!, {r0, r3} + + @ Set parameters for booting zImage according to boot protocol + @ put FDT address in r2, it was returned by efi_entry() + @ r1 is FDT machine type, and r0 needs to be 0 + mov r2, r0 + mov r1, #0xFFFFFFFF + mov r0, #0 + + @ Branch to (possibly) relocated zImage that is in r3 + @ Make sure we are in A32 mode, as zImage requires + THUMB( bx r3 ) + ARM( mov pc, r3 ) + +efi_load_fail: + @ Return EFI_LOAD_ERROR to EFI firmware on error. + @ Switch back to ARM mode for EFI is done based on + @ return address on stack + ldr r0, =0x80000001 + ldmfd sp!, {fp, pc} +#endif + + THUMB( .thumb ) +zimage_continue: mrs r9, cpsr #ifdef CONFIG_ARM_VIRT_EXT bl __hyp_stub_install @ get into SVC mode, reversibly @@ -167,7 +246,6 @@ not_angel: * by the linker here, but it should preserve r7, r8, and r9. */ - .text #ifdef CONFIG_AUTO_ZRELADDR @ determine final kernel image address