linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: Expand arm64 image header
@ 2013-08-14 23:10 Roy Franz
  2013-08-15  3:58 ` Mark Salter
  2013-08-21 17:30 ` Catalin Marinas
  0 siblings, 2 replies; 6+ messages in thread
From: Roy Franz @ 2013-08-14 23:10 UTC (permalink / raw)
  To: linux-arm-kernel

Expand the arm64 image header to allow for co-existance with
PE/COFF header required by the EFI stub.  The PE/COFF format
requires the "MZ" header to be at offset 0, and the offset
to the PE/COFF header to be at offset 0x3c.  The image
header is expanded to allow 2 instructions at the beginning
to accommodate a benign intruction at offset 0 that includes
the "MZ" header, a magic number, and the offset to the PE/COFF
header.


Signed-off-by: Roy Franz <roy.franz@linaro.org>
---
 Documentation/arm64/booting.txt |   16 +++++++++++++---
 arch/arm64/kernel/head.S        |    8 ++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/Documentation/arm64/booting.txt b/Documentation/arm64/booting.txt
index 9c4d388..5273c4d 100644
--- a/Documentation/arm64/booting.txt
+++ b/Documentation/arm64/booting.txt
@@ -68,13 +68,23 @@ Image target is available instead.
 
 Requirement: MANDATORY
 
-The decompressed kernel image contains a 32-byte header as follows:
+The decompressed kernel image contains a 64-byte header as follows:
 
-  u32 magic	= 0x14000008;	/* branch to stext, little-endian */
-  u32 res0	= 0;		/* reserved */
+  u32 code0;			/* Executable code */
+  u32 code1;			/* Executable code */
   u64 text_offset;		/* Image load offset */
+  u64 res0	= 0;		/* reserved */
   u64 res1	= 0;		/* reserved */
   u64 res2	= 0;		/* reserved */
+  u64 res3	= 0;		/* reserved */
+  u64 res4	= 0;		/* reserved */
+  u32 magic	= 0x644d5241;	/* Magic number, little endian, "ARM\x64" */
+  u32 res5 = 0;      		/* reserved */
+
+
+Header notes:
+
+- code0/code1 are responsible for branching to stext.
 
 The image must be placed at the specified offset (currently 0x80000)
 from the start of the system RAM and called there. The start of the
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 53dcae4..7090c12 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -112,6 +112,14 @@
 	.quad	TEXT_OFFSET			// Image load offset from start of RAM
 	.quad	0				// reserved
 	.quad	0				// reserved
+	.quad	0				// reserved
+	.quad	0				// reserved
+	.quad	0				// reserved
+	.byte	0x41				// Magic number, "ARM\x64"
+	.byte	0x52
+	.byte	0x4d
+	.byte	0x64
+	.word	0				// reserved
 
 ENTRY(stext)
 	mov	x21, x0				// x21=FDT
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] arm64: Expand arm64 image header
  2013-08-14 23:10 [PATCH] arm64: Expand arm64 image header Roy Franz
@ 2013-08-15  3:58 ` Mark Salter
  2013-08-15 15:49   ` Roy Franz
  2013-08-21 17:30 ` Catalin Marinas
  1 sibling, 1 reply; 6+ messages in thread
From: Mark Salter @ 2013-08-15  3:58 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, 2013-08-14 at 16:10 -0700, Roy Franz wrote:
> Expand the arm64 image header to allow for co-existance with
> PE/COFF header required by the EFI stub.  The PE/COFF format
> requires the "MZ" header to be at offset 0, and the offset
> to the PE/COFF header to be at offset 0x3c.  The image
> header is expanded to allow 2 instructions at the beginning
> to accommodate a benign intruction at offset 0 that includes
> the "MZ" header, a magic number, and the offset to the PE/COFF
> header.
> 
> 
> Signed-off-by: Roy Franz <roy.franz@linaro.org>
> ---
>  Documentation/arm64/booting.txt |   16 +++++++++++++---
>  arch/arm64/kernel/head.S        |    8 ++++++++
>  2 files changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/arm64/booting.txt b/Documentation/arm64/booting.txt
> index 9c4d388..5273c4d 100644
> --- a/Documentation/arm64/booting.txt
> +++ b/Documentation/arm64/booting.txt
> @@ -68,13 +68,23 @@ Image target is available instead.
>  
>  Requirement: MANDATORY
>  
> -The decompressed kernel image contains a 32-byte header as follows:
> +The decompressed kernel image contains a 64-byte header as follows:
>  
> -  u32 magic	= 0x14000008;	/* branch to stext, little-endian */
> -  u32 res0	= 0;		/* reserved */
> +  u32 code0;			/* Executable code */
> +  u32 code1;			/* Executable code */
>    u64 text_offset;		/* Image load offset */
> +  u64 res0	= 0;		/* reserved */
>    u64 res1	= 0;		/* reserved */
>    u64 res2	= 0;		/* reserved */
> +  u64 res3	= 0;		/* reserved */
> +  u64 res4	= 0;		/* reserved */
> +  u32 magic	= 0x644d5241;	/* Magic number, little endian, "ARM\x64" */
> +  u32 res5 = 0;      		/* reserved */
> +
> +
> +Header notes:
> +
> +- code0/code1 are responsible for branching to stext.

Do we really want to change the already documented image header? Any
existing bootloaders which check the magic number would stop working.
In my preliminary patches to add an efi stub, I avoid that by making
an Image.efi which is an Image file with pe/coff header prepended. I
could easily switch to using the above header change, but wanted to
point out an alternative that doesn't change the already established
header.

--Mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] arm64: Expand arm64 image header
  2013-08-15  3:58 ` Mark Salter
@ 2013-08-15 15:49   ` Roy Franz
  2013-08-15 17:40     ` Mark Salter
  0 siblings, 1 reply; 6+ messages in thread
From: Roy Franz @ 2013-08-15 15:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Aug 14, 2013 at 8:58 PM, Mark Salter <msalter@redhat.com> wrote:
> On Wed, 2013-08-14 at 16:10 -0700, Roy Franz wrote:
>> Expand the arm64 image header to allow for co-existance with
>> PE/COFF header required by the EFI stub.  The PE/COFF format
>> requires the "MZ" header to be at offset 0, and the offset
>> to the PE/COFF header to be at offset 0x3c.  The image
>> header is expanded to allow 2 instructions at the beginning
>> to accommodate a benign intruction at offset 0 that includes
>> the "MZ" header, a magic number, and the offset to the PE/COFF
>> header.
>>
>>
>> Signed-off-by: Roy Franz <roy.franz@linaro.org>
>> ---
>>  Documentation/arm64/booting.txt |   16 +++++++++++++---
>>  arch/arm64/kernel/head.S        |    8 ++++++++
>>  2 files changed, 21 insertions(+), 3 deletions(-)
>>
>> diff --git a/Documentation/arm64/booting.txt b/Documentation/arm64/booting.txt
>> index 9c4d388..5273c4d 100644
>> --- a/Documentation/arm64/booting.txt
>> +++ b/Documentation/arm64/booting.txt
>> @@ -68,13 +68,23 @@ Image target is available instead.
>>
>>  Requirement: MANDATORY
>>
>> -The decompressed kernel image contains a 32-byte header as follows:
>> +The decompressed kernel image contains a 64-byte header as follows:
>>
>> -  u32 magic  = 0x14000008;   /* branch to stext, little-endian */
>> -  u32 res0   = 0;            /* reserved */
>> +  u32 code0;                 /* Executable code */
>> +  u32 code1;                 /* Executable code */
>>    u64 text_offset;           /* Image load offset */
>> +  u64 res0   = 0;            /* reserved */
>>    u64 res1   = 0;            /* reserved */
>>    u64 res2   = 0;            /* reserved */
>> +  u64 res3   = 0;            /* reserved */
>> +  u64 res4   = 0;            /* reserved */
>> +  u32 magic  = 0x644d5241;   /* Magic number, little endian, "ARM\x64" */
>> +  u32 res5 = 0;                      /* reserved */
>> +
>> +
>> +Header notes:
>> +
>> +- code0/code1 are responsible for branching to stext.
>
> Do we really want to change the already documented image header? Any
> existing bootloaders which check the magic number would stop working.
> In my preliminary patches to add an efi stub, I avoid that by making
> an Image.efi which is an Image file with pe/coff header prepended. I
> could easily switch to using the above header change, but wanted to
> point out an alternative that doesn't change the already established
> header.
>
> --Mark
>

Hi Mark,

   Yes, we do want to make the change, as one the goals is to have a
single binary format, not multiple formats.  This was discussed fairly
extensively at LCE, and I think my patch represents the consensus on
how the EFI stub should be integrated.
Also, since it is early enough in the arm64 development this should be
a relatively easy time to make it.  I don't think that the current
magic number is checked in the current UEFI loader, as the image boots
fine with either header.  If the current ARM64 loaders don't check the
magic number, then they will work with either format, since the entry
point is the same.

Roy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] arm64: Expand arm64 image header
  2013-08-15 15:49   ` Roy Franz
@ 2013-08-15 17:40     ` Mark Salter
  2013-08-20 17:25       ` Roy Franz
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Salter @ 2013-08-15 17:40 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 2013-08-15 at 08:49 -0700, Roy Franz wrote:
> On Wed, Aug 14, 2013 at 8:58 PM, Mark Salter <msalter@redhat.com> wrote:
> > On Wed, 2013-08-14 at 16:10 -0700, Roy Franz wrote:
> >> Expand the arm64 image header to allow for co-existance with
> >> PE/COFF header required by the EFI stub.  The PE/COFF format
> >> requires the "MZ" header to be at offset 0, and the offset
> >> to the PE/COFF header to be at offset 0x3c.  The image
> >> header is expanded to allow 2 instructions at the beginning
> >> to accommodate a benign intruction at offset 0 that includes
> >> the "MZ" header, a magic number, and the offset to the PE/COFF
> >> header.
> >>
> >>
> >> Signed-off-by: Roy Franz <roy.franz@linaro.org>
> >> ---
> >>  Documentation/arm64/booting.txt |   16 +++++++++++++---
> >>  arch/arm64/kernel/head.S        |    8 ++++++++
> >>  2 files changed, 21 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/Documentation/arm64/booting.txt b/Documentation/arm64/booting.txt
> >> index 9c4d388..5273c4d 100644
> >> --- a/Documentation/arm64/booting.txt
> >> +++ b/Documentation/arm64/booting.txt
> >> @@ -68,13 +68,23 @@ Image target is available instead.
> >>
> >>  Requirement: MANDATORY
> >>
> >> -The decompressed kernel image contains a 32-byte header as follows:
> >> +The decompressed kernel image contains a 64-byte header as follows:
> >>
> >> -  u32 magic  = 0x14000008;   /* branch to stext, little-endian */
> >> -  u32 res0   = 0;            /* reserved */
> >> +  u32 code0;                 /* Executable code */
> >> +  u32 code1;                 /* Executable code */
> >>    u64 text_offset;           /* Image load offset */
> >> +  u64 res0   = 0;            /* reserved */
> >>    u64 res1   = 0;            /* reserved */
> >>    u64 res2   = 0;            /* reserved */
> >> +  u64 res3   = 0;            /* reserved */
> >> +  u64 res4   = 0;            /* reserved */
> >> +  u32 magic  = 0x644d5241;   /* Magic number, little endian, "ARM\x64" */
> >> +  u32 res5 = 0;                      /* reserved */
> >> +
> >> +
> >> +Header notes:
> >> +
> >> +- code0/code1 are responsible for branching to stext.
> >
> > Do we really want to change the already documented image header? Any
> > existing bootloaders which check the magic number would stop working.
> > In my preliminary patches to add an efi stub, I avoid that by making
> > an Image.efi which is an Image file with pe/coff header prepended. I
> > could easily switch to using the above header change, but wanted to
> > point out an alternative that doesn't change the already established
> > header.
> >
> > --Mark
> >
> 
> Hi Mark,
> 
>    Yes, we do want to make the change, as one the goals is to have a
> single binary format, not multiple formats.  This was discussed fairly
> extensively at LCE, and I think my patch represents the consensus on
> how the EFI stub should be integrated.
> Also, since it is early enough in the arm64 development this should be
> a relatively easy time to make it.  I don't think that the current
> magic number is checked in the current UEFI loader, as the image boots
> fine with either header.  If the current ARM64 loaders don't check the
> magic number, then they will work with either format, since the entry
> point is the same.
> 
> Roy

That's fine. I wasn't at LCE, so I just wanted to avoid doubt and point
out the alternative. Either way works for the main part of the efi stub
so I'm okay with whatever uncompressed image header is used.

--Mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] arm64: Expand arm64 image header
  2013-08-15 17:40     ` Mark Salter
@ 2013-08-20 17:25       ` Roy Franz
  0 siblings, 0 replies; 6+ messages in thread
From: Roy Franz @ 2013-08-20 17:25 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Aug 15, 2013 at 10:40 AM, Mark Salter <msalter@redhat.com> wrote:
> On Thu, 2013-08-15 at 08:49 -0700, Roy Franz wrote:
>> On Wed, Aug 14, 2013 at 8:58 PM, Mark Salter <msalter@redhat.com> wrote:
>> > On Wed, 2013-08-14 at 16:10 -0700, Roy Franz wrote:
>> >> Expand the arm64 image header to allow for co-existance with
>> >> PE/COFF header required by the EFI stub.  The PE/COFF format
>> >> requires the "MZ" header to be at offset 0, and the offset
>> >> to the PE/COFF header to be at offset 0x3c.  The image
>> >> header is expanded to allow 2 instructions at the beginning
>> >> to accommodate a benign intruction at offset 0 that includes
>> >> the "MZ" header, a magic number, and the offset to the PE/COFF
>> >> header.
>> >>
>> >>
>> >> Signed-off-by: Roy Franz <roy.franz@linaro.org>
>> >> ---
>> >>  Documentation/arm64/booting.txt |   16 +++++++++++++---
>> >>  arch/arm64/kernel/head.S        |    8 ++++++++
>> >>  2 files changed, 21 insertions(+), 3 deletions(-)
>> >>
>> >> diff --git a/Documentation/arm64/booting.txt b/Documentation/arm64/booting.txt
>> >> index 9c4d388..5273c4d 100644
>> >> --- a/Documentation/arm64/booting.txt
>> >> +++ b/Documentation/arm64/booting.txt
>> >> @@ -68,13 +68,23 @@ Image target is available instead.
>> >>
>> >>  Requirement: MANDATORY
>> >>
>> >> -The decompressed kernel image contains a 32-byte header as follows:
>> >> +The decompressed kernel image contains a 64-byte header as follows:
>> >>
>> >> -  u32 magic  = 0x14000008;   /* branch to stext, little-endian */
>> >> -  u32 res0   = 0;            /* reserved */
>> >> +  u32 code0;                 /* Executable code */
>> >> +  u32 code1;                 /* Executable code */
>> >>    u64 text_offset;           /* Image load offset */
>> >> +  u64 res0   = 0;            /* reserved */
>> >>    u64 res1   = 0;            /* reserved */
>> >>    u64 res2   = 0;            /* reserved */
>> >> +  u64 res3   = 0;            /* reserved */
>> >> +  u64 res4   = 0;            /* reserved */
>> >> +  u32 magic  = 0x644d5241;   /* Magic number, little endian, "ARM\x64" */
>> >> +  u32 res5 = 0;                      /* reserved */
>> >> +
>> >> +
>> >> +Header notes:
>> >> +
>> >> +- code0/code1 are responsible for branching to stext.
>> >
>> > Do we really want to change the already documented image header? Any
>> > existing bootloaders which check the magic number would stop working.
>> > In my preliminary patches to add an efi stub, I avoid that by making
>> > an Image.efi which is an Image file with pe/coff header prepended. I
>> > could easily switch to using the above header change, but wanted to
>> > point out an alternative that doesn't change the already established
>> > header.
>> >
>> > --Mark
>> >
>>
>> Hi Mark,
>>
>>    Yes, we do want to make the change, as one the goals is to have a
>> single binary format, not multiple formats.  This was discussed fairly
>> extensively at LCE, and I think my patch represents the consensus on
>> how the EFI stub should be integrated.
>> Also, since it is early enough in the arm64 development this should be
>> a relatively easy time to make it.  I don't think that the current
>> magic number is checked in the current UEFI loader, as the image boots
>> fine with either header.  If the current ARM64 loaders don't check the
>> magic number, then they will work with either format, since the entry
>> point is the same.
>>
>> Roy
>
> That's fine. I wasn't at LCE, so I just wanted to avoid doubt and point
> out the alternative. Either way works for the main part of the efi stub
> so I'm okay with whatever uncompressed image header is used.
>
> --Mark
>
>

Hi Catalin,

   Have you had a chance to look at this?  Please let me know if this
is acceptable or if you would like changes made.

Thanks,
Roy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] arm64: Expand arm64 image header
  2013-08-14 23:10 [PATCH] arm64: Expand arm64 image header Roy Franz
  2013-08-15  3:58 ` Mark Salter
@ 2013-08-21 17:30 ` Catalin Marinas
  1 sibling, 0 replies; 6+ messages in thread
From: Catalin Marinas @ 2013-08-21 17:30 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Aug 15, 2013 at 12:10:00AM +0100, Roy Franz wrote:
> Expand the arm64 image header to allow for co-existance with
> PE/COFF header required by the EFI stub.  The PE/COFF format
> requires the "MZ" header to be at offset 0, and the offset
> to the PE/COFF header to be at offset 0x3c.  The image
> header is expanded to allow 2 instructions at the beginning
> to accommodate a benign intruction at offset 0 that includes
> the "MZ" header, a magic number, and the offset to the PE/COFF
> header.
> 
> 
> Signed-off-by: Roy Franz <roy.franz@linaro.org>

The patch looks fine to me. I couldn't come up with a better magic
number in 4 bytes (something that would suggest Linux kernel). If you
have a better idea let me know before the merging window (LKA64 maybe?)

Thanks.

-- 
Catalin

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-08-21 17:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-14 23:10 [PATCH] arm64: Expand arm64 image header Roy Franz
2013-08-15  3:58 ` Mark Salter
2013-08-15 15:49   ` Roy Franz
2013-08-15 17:40     ` Mark Salter
2013-08-20 17:25       ` Roy Franz
2013-08-21 17:30 ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).