All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roy Franz <roy.franz@linaro.org>
To: Dave Martin <Dave.Martin@arm.com>
Cc: linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	matt.fleming@intel.com,
	Russell King - ARM Linux <linux@arm.linux.org.uk>,
	Leif Lindholm <leif.lindholm@linaro.org>
Subject: Re: [PATCH 16/17] Add EFI stub for ARM
Date: Thu, 8 Aug 2013 17:53:16 -0700	[thread overview]
Message-ID: <CAFECyb9Qh1TzGcjK2AMkKWZTsvTh2MgF1yeDzxYpLE7skMLg7g@mail.gmail.com> (raw)
In-Reply-To: <CAFECyb-aAHk0RzBGPmGOhRkm8=chwyAM=DdwE=6Z4VLR9sqFRA@mail.gmail.com>

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 <linux/linkage.h>
 #include <asm/assembler.h>
+#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

WARNING: multiple messages have this Message-ID (diff)
From: roy.franz@linaro.org (Roy Franz)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 16/17] Add EFI stub for ARM
Date: Thu, 8 Aug 2013 17:53:16 -0700	[thread overview]
Message-ID: <CAFECyb9Qh1TzGcjK2AMkKWZTsvTh2MgF1yeDzxYpLE7skMLg7g@mail.gmail.com> (raw)
In-Reply-To: <CAFECyb-aAHk0RzBGPmGOhRkm8=chwyAM=DdwE=6Z4VLR9sqFRA@mail.gmail.com>

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 <linux/linkage.h>
 #include <asm/assembler.h>
+#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

  reply	other threads:[~2013-08-09  0:53 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-07  3:44 [PATCH V2 00/17] EFI stub for ARM Roy Franz
2013-08-07  3:44 ` Roy Franz
2013-08-07  3:44 ` [PATCH 01/17] EFI stub documentation updates Roy Franz
2013-08-07  3:44   ` Roy Franz
2013-08-07  3:44   ` Roy Franz
2013-08-07  3:44 ` [PATCH 02/17] Move common EFI stub code from x86 arch code to common location Roy Franz
2013-08-07  3:44   ` Roy Franz
2013-08-07  3:44 ` [PATCH 03/17] Add system pointer argument to shared EFI stub related functions so they no longer use global system table pointer as they did when part of eboot.c Roy Franz
2013-08-07  3:44   ` Roy Franz
2013-08-07  3:44   ` Roy Franz
2013-08-07 13:08   ` Matt Fleming
2013-08-07 13:08     ` Matt Fleming
2013-08-07 13:08     ` Matt Fleming
2013-08-07 17:10     ` Roy Franz
2013-08-07 17:10       ` Roy Franz
2013-08-07 17:10       ` Roy Franz
2013-08-07 21:55       ` Matt Fleming
2013-08-07 21:55         ` Matt Fleming
2013-08-07  3:45 ` [PATCH 04/17] Rename memory allocation/free functions Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07 13:09   ` Matt Fleming
2013-08-07 13:09     ` Matt Fleming
2013-08-07 17:12     ` Roy Franz
2013-08-07 17:12       ` Roy Franz
2013-08-07 17:12       ` Roy Franz
2013-08-07  3:45 ` [PATCH 05/17] Add minimum address parameter to efi_low_alloc() Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45 ` [PATCH 06/17] rename __get_map() to efi_get_memory_map(), add parameter to optionally return mmap key. The mmap key is required to exit EFI boot services, and allows efi_get_memory_map() to be used for getting final memory map Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45 ` [PATCH 07/17] Enforce minimum alignment of 1 page on allocations. The efi_high_alloc() and efi_low_alloc() functions use the EFI_ALLOCATE_ADDRESS option to the EFI function allocate_pages(), which requires a minimum of page alignment, and rejects all other requests Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45 ` [PATCH 08/17] Allow efi_free() to be called with size of 0, and do nothing in that case Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45 ` [PATCH 09/17] Generalize handle_ramdisks() and rename to handle_cmdline_files() Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45 ` [PATCH 10/17] Renames in handle_cmdline_files() to complete generalization Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07 13:09   ` Matt Fleming
2013-08-07 13:09     ` Matt Fleming
2013-08-07  3:45 ` [PATCH 11/17] Move EFI_READ_CHUNK_SIZE define to shared location Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45 ` [PATCH 12/17] Add proper definitions for some EFI function pointers Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07 13:09   ` Matt Fleming
2013-08-07 13:09     ` Matt Fleming
2013-08-07 13:09     ` Matt Fleming
2013-08-07 17:20     ` Roy Franz
2013-08-07 17:20       ` Roy Franz
2013-08-07 17:20       ` Roy Franz
2013-08-09 14:10   ` Mark Salter
2013-08-09 14:10     ` Mark Salter
2013-08-09 14:10     ` Mark Salter
2013-08-09 14:13     ` Roy Franz
2013-08-09 14:13       ` Roy Franz
2013-08-09 14:13       ` Roy Franz
2013-08-07  3:45 ` [PATCH 13/17] Fix types in EFI calls to match EFI function definitions Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45 ` [PATCH 14/17] resolve warnings found on ARM compile Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45 ` [PATCH 15/17] Add strstr to compressed string.c for ARM Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45 ` [PATCH 16/17] Add EFI stub " Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07 18:05   ` Dave Martin
2013-08-07 18:05     ` Dave Martin
2013-08-07 18:05     ` Dave Martin
2013-08-07 18:33     ` Leif Lindholm
2013-08-07 18:33       ` Leif Lindholm
2013-08-08 21:57     ` Roy Franz
2013-08-08 21:57       ` Roy Franz
2013-08-08 21:57       ` Roy Franz
2013-08-09  0:53       ` Roy Franz [this message]
2013-08-09  0:53         ` Roy Franz
2013-08-09  0:53         ` Roy Franz
2013-08-13 14:21       ` Dave P Martin
2013-08-13 14:21         ` Dave P Martin
2013-08-13 14:21         ` Dave P Martin
2013-08-07  3:45 ` [PATCH 17/17] Add config EFI_STUB for ARM to Kconfig Roy Franz
2013-08-07  3:45   ` Roy Franz
2013-08-07  7:44 ` [PATCH V2 00/17] EFI stub for ARM Matt Fleming
2013-08-07  7:44   ` Matt Fleming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFECyb9Qh1TzGcjK2AMkKWZTsvTh2MgF1yeDzxYpLE7skMLg7g@mail.gmail.com \
    --to=roy.franz@linaro.org \
    --cc=Dave.Martin@arm.com \
    --cc=leif.lindholm@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=matt.fleming@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.