* [PATCH] riscv: Fix efi header for RV32
@ 2020-10-13 19:23 Atish Patra
2020-10-14 1:03 ` Bin Meng
2020-11-11 8:25 ` Leo Liang
0 siblings, 2 replies; 7+ messages in thread
From: Atish Patra @ 2020-10-13 19:23 UTC (permalink / raw)
To: u-boot
RV32 should use PE32 format instead of PE32+ as the efi header format.
This requires following changes
1. A different header magic value
2. An additional parameter known as BaseOfData. Currently, it is set to
zero in absence of any usage.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
---
arch/riscv/lib/crt0_riscv_efi.S | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
index 87fe1e56f906..4aaa49ad0777 100644
--- a/arch/riscv/lib/crt0_riscv_efi.S
+++ b/arch/riscv/lib/crt0_riscv_efi.S
@@ -15,11 +15,13 @@
#define SAVE_LONG(reg, idx) sd reg, (idx*SIZE_LONG)(sp)
#define LOAD_LONG(reg, idx) ld reg, (idx*SIZE_LONG)(sp)
#define PE_MACHINE IMAGE_FILE_MACHINE_RISCV64
+#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
#else
#define SIZE_LONG 4
#define SAVE_LONG(reg, idx) sw reg, (idx*SIZE_LONG)(sp)
#define LOAD_LONG(reg, idx) lw reg, (idx*SIZE_LONG)(sp)
#define PE_MACHINE IMAGE_FILE_MACHINE_RISCV32
+#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
#endif
@@ -48,7 +50,7 @@ coff_header:
IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
IMAGE_FILE_DEBUG_STRIPPED)
optional_header:
- .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
+ .short PE_MAGIC /* PE32+ format */
.byte 0x02 /* MajorLinkerVersion */
.byte 0x14 /* MinorLinkerVersion */
.long _edata - _start /* SizeOfCode */
@@ -56,6 +58,9 @@ optional_header:
.long 0 /* SizeOfUninitializedData */
.long _start - ImageBase /* AddressOfEntryPoint */
.long _start - ImageBase /* BaseOfCode */
+#if __riscv_xlen == 32
+ .long 0 /* BaseOfData */
+#endif
extra_header_fields:
.quad 0 /* ImageBase */
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH] riscv: Fix efi header for RV32
2020-10-13 19:23 [PATCH] riscv: Fix efi header for RV32 Atish Patra
@ 2020-10-14 1:03 ` Bin Meng
2020-10-14 1:16 ` Heinrich Schuchardt
2020-11-11 8:25 ` Leo Liang
1 sibling, 1 reply; 7+ messages in thread
From: Bin Meng @ 2020-10-14 1:03 UTC (permalink / raw)
To: u-boot
On Wed, Oct 14, 2020 at 3:23 AM Atish Patra <atish.patra@wdc.com> wrote:
>
> RV32 should use PE32 format instead of PE32+ as the efi header format.
> This requires following changes
> 1. A different header magic value
> 2. An additional parameter known as BaseOfData. Currently, it is set to
> zero in absence of any usage.
>
> Signed-off-by: Atish Patra <atish.patra@wdc.com>
> ---
> arch/riscv/lib/crt0_riscv_efi.S | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
> index 87fe1e56f906..4aaa49ad0777 100644
> --- a/arch/riscv/lib/crt0_riscv_efi.S
> +++ b/arch/riscv/lib/crt0_riscv_efi.S
> @@ -15,11 +15,13 @@
> #define SAVE_LONG(reg, idx) sd reg, (idx*SIZE_LONG)(sp)
> #define LOAD_LONG(reg, idx) ld reg, (idx*SIZE_LONG)(sp)
> #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV64
> +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
nits: the indentation seems to be incorrect
> #else
> #define SIZE_LONG 4
> #define SAVE_LONG(reg, idx) sw reg, (idx*SIZE_LONG)(sp)
> #define LOAD_LONG(reg, idx) lw reg, (idx*SIZE_LONG)(sp)
> #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV32
> +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
> #endif
>
>
> @@ -48,7 +50,7 @@ coff_header:
> IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
> IMAGE_FILE_DEBUG_STRIPPED)
> optional_header:
> - .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
nits: PE32(+) ?
> + .short PE_MAGIC /* PE32+ format */
> .byte 0x02 /* MajorLinkerVersion */
> .byte 0x14 /* MinorLinkerVersion */
> .long _edata - _start /* SizeOfCode */
> @@ -56,6 +58,9 @@ optional_header:
> .long 0 /* SizeOfUninitializedData */
> .long _start - ImageBase /* AddressOfEntryPoint */
> .long _start - ImageBase /* BaseOfCode */
> +#if __riscv_xlen == 32
> + .long 0 /* BaseOfData */
> +#endif
>
> extra_header_fields:
> .quad 0 /* ImageBase */
Looks good otherwise
Reviewed-by: Bin Meng <bin.meng@windriver.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] riscv: Fix efi header for RV32
2020-10-14 1:03 ` Bin Meng
@ 2020-10-14 1:16 ` Heinrich Schuchardt
[not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FB22ACFD8@ATCPCS12.andestech.com>
0 siblings, 1 reply; 7+ messages in thread
From: Heinrich Schuchardt @ 2020-10-14 1:16 UTC (permalink / raw)
To: u-boot
Am 14. Oktober 2020 03:03:28 MESZ schrieb Bin Meng <bmeng.cn@gmail.com>:
>On Wed, Oct 14, 2020 at 3:23 AM Atish Patra <atish.patra@wdc.com>
>wrote:
>>
>> RV32 should use PE32 format instead of PE32+ as the efi header
>format.
>> This requires following changes
>> 1. A different header magic value
>> 2. An additional parameter known as BaseOfData. Currently, it is set
>to
>> zero in absence of any usage.
>>
>> Signed-off-by: Atish Patra <atish.patra@wdc.com>
>> ---
>> arch/riscv/lib/crt0_riscv_efi.S | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/riscv/lib/crt0_riscv_efi.S
>b/arch/riscv/lib/crt0_riscv_efi.S
>> index 87fe1e56f906..4aaa49ad0777 100644
>> --- a/arch/riscv/lib/crt0_riscv_efi.S
>> +++ b/arch/riscv/lib/crt0_riscv_efi.S
>> @@ -15,11 +15,13 @@
>> #define SAVE_LONG(reg, idx) sd reg, (idx*SIZE_LONG)(sp)
>> #define LOAD_LONG(reg, idx) ld reg, (idx*SIZE_LONG)(sp)
>> #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV64
>> +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
>
>nits: the indentation seems to be incorrect
>
>> #else
>> #define SIZE_LONG 4
>> #define SAVE_LONG(reg, idx) sw reg, (idx*SIZE_LONG)(sp)
>> #define LOAD_LONG(reg, idx) lw reg, (idx*SIZE_LONG)(sp)
>> #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV32
>> +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
>> #endif
>>
>>
>> @@ -48,7 +50,7 @@ coff_header:
>> IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
>> IMAGE_FILE_DEBUG_STRIPPED)
>> optional_header:
>> - .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
>
>nits: PE32(+) ?
>
>> + .short PE_MAGIC /* PE32+ format */
>> .byte 0x02 /* MajorLinkerVersion
>*/
>> .byte 0x14 /* MinorLinkerVersion
>*/
>> .long _edata - _start /* SizeOfCode */
>> @@ -56,6 +58,9 @@ optional_header:
>> .long 0 /*
>SizeOfUninitializedData */
>> .long _start - ImageBase /*
>AddressOfEntryPoint */
>> .long _start - ImageBase /* BaseOfCode */
>> +#if __riscv_xlen == 32
>> + .long 0 /* BaseOfData */
>> +#endif
>>
The PE32 header has to be 96 bytes long, the PE32+ header 112 bytes long.
See https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
Best regards
Heinrich
>> extra_header_fields:
>> .quad 0 /* ImageBase */
>
>Looks good otherwise
>Reviewed-by: Bin Meng <bin.meng@windriver.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] riscv: Fix efi header for RV32
[not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FB22ACFD8@ATCPCS12.andestech.com>
@ 2020-11-04 1:49 ` Rick Chen
0 siblings, 0 replies; 7+ messages in thread
From: Rick Chen @ 2020-11-04 1:49 UTC (permalink / raw)
To: u-boot
Hi Atish
> From: U-Boot [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Heinrich Schuchardt
> Sent: Wednesday, October 14, 2020 9:16 AM
> To: Bin Meng; Atish Patra
> Cc: U-Boot Mailing List; Anup Patel; Jagan Teki; Marek Vasut; Simon Goldschmidt; David Abdurachmanov; Tom Rini
> Subject: Re: [PATCH] riscv: Fix efi header for RV32
>
> Am 14. Oktober 2020 03:03:28 MESZ schrieb Bin Meng <bmeng.cn@gmail.com>:
> >On Wed, Oct 14, 2020 at 3:23 AM Atish Patra <atish.patra@wdc.com>
> >wrote:
> >>
> >> RV32 should use PE32 format instead of PE32+ as the efi header
> >format.
> >> This requires following changes
> >> 1. A different header magic value
> >> 2. An additional parameter known as BaseOfData. Currently, it is set
> >to
> >> zero in absence of any usage.
> >>
> >> Signed-off-by: Atish Patra <atish.patra@wdc.com>
> >> ---
> >> arch/riscv/lib/crt0_riscv_efi.S | 7 ++++++-
> >> 1 file changed, 6 insertions(+), 1 deletion(-)
> >>
Reviewed-by: Rick Chen <rick@andestech.com>
> >> diff --git a/arch/riscv/lib/crt0_riscv_efi.S
> >b/arch/riscv/lib/crt0_riscv_efi.S
> >> index 87fe1e56f906..4aaa49ad0777 100644
> >> --- a/arch/riscv/lib/crt0_riscv_efi.S
> >> +++ b/arch/riscv/lib/crt0_riscv_efi.S
> >> @@ -15,11 +15,13 @@
> >> #define SAVE_LONG(reg, idx) sd reg, (idx*SIZE_LONG)(sp)
> >> #define LOAD_LONG(reg, idx) ld reg, (idx*SIZE_LONG)(sp)
> >> #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV64
> >> +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
> >
> >nits: the indentation seems to be incorrect
> >
> >> #else
> >> #define SIZE_LONG 4
> >> #define SAVE_LONG(reg, idx) sw reg, (idx*SIZE_LONG)(sp)
> >> #define LOAD_LONG(reg, idx) lw reg, (idx*SIZE_LONG)(sp)
> >> #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV32
> >> +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
> >> #endif
> >>
> >>
> >> @@ -48,7 +50,7 @@ coff_header:
> >> IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
> >> IMAGE_FILE_DEBUG_STRIPPED)
> >> optional_header:
> >> - .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
> >
> >nits: PE32(+) ?
> >
> >> + .short PE_MAGIC /* PE32+ format */
> >> .byte 0x02 /* MajorLinkerVersion
> >*/
> >> .byte 0x14 /* MinorLinkerVersion
> >*/
> >> .long _edata - _start /* SizeOfCode */
> >> @@ -56,6 +58,9 @@ optional_header:
> >> .long 0 /*
> >SizeOfUninitializedData */
> >> .long _start - ImageBase /*
> >AddressOfEntryPoint */
> >> .long _start - ImageBase /* BaseOfCode */
> >> +#if __riscv_xlen == 32
> >> + .long 0 /* BaseOfData */
> >> +#endif
> >>
>
> The PE32 header has to be 96 bytes long, the PE32+ header 112 bytes long.
>
> See https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
>
Do you have any comments ?
The other headers seem for Windows-Specific Fields. If no other
comments furthermore.
I will pull it into riscv tree later.
Thanks,
Rick
> Best regards
>
> Heinrich
>
>
> >> extra_header_fields:
> >> .quad 0 /* ImageBase */
> >
> >Looks good otherwise
> >Reviewed-by: Bin Meng <bin.meng@windriver.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] riscv: Fix efi header for RV32
2020-10-13 19:23 [PATCH] riscv: Fix efi header for RV32 Atish Patra
2020-10-14 1:03 ` Bin Meng
@ 2020-11-11 8:25 ` Leo Liang
2020-11-12 2:46 ` Leo Liang
2020-11-12 8:09 ` Atish Patra
1 sibling, 2 replies; 7+ messages in thread
From: Leo Liang @ 2020-11-11 8:25 UTC (permalink / raw)
To: u-boot
Hi Atish and Heinrich,
On Tue, Oct 13, 2020 at 12:23:31PM -0700, Atish Patra wrote:
> RV32 should use PE32 format instead of PE32+ as the efi header format.
> This requires following changes
> 1. A different header magic value
> 2. An additional parameter known as BaseOfData. Currently, it is set to
> zero in absence of any usage.
>
> Signed-off-by: Atish Patra <atish.patra@wdc.com>
> Reviewed-by: Bin Meng <bin.meng@windriver.com>
> Reviewed-by: Rick Chen <rick@andestech.com>
> ---
> arch/riscv/lib/crt0_riscv_efi.S | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
> index 87fe1e56f906..4aaa49ad0777 100644
> --- a/arch/riscv/lib/crt0_riscv_efi.S
> +++ b/arch/riscv/lib/crt0_riscv_efi.S
> @@ -15,11 +15,13 @@
> #define SAVE_LONG(reg, idx) sd reg, (idx*SIZE_LONG)(sp)
> #define LOAD_LONG(reg, idx) ld reg, (idx*SIZE_LONG)(sp)
> #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV64
> +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
> #else
> #define SIZE_LONG 4
> #define SAVE_LONG(reg, idx) sw reg, (idx*SIZE_LONG)(sp)
> #define LOAD_LONG(reg, idx) lw reg, (idx*SIZE_LONG)(sp)
> #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV32
> +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
> #endif
>
>
> @@ -48,7 +50,7 @@ coff_header:
> IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
> IMAGE_FILE_DEBUG_STRIPPED)
> optional_header:
> - .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
> + .short PE_MAGIC /* PE32+ format */
> .byte 0x02 /* MajorLinkerVersion */
> .byte 0x14 /* MinorLinkerVersion */
> .long _edata - _start /* SizeOfCode */
> @@ -56,6 +58,9 @@ optional_header:
> .long 0 /* SizeOfUninitializedData */
> .long _start - ImageBase /* AddressOfEntryPoint */
> .long _start - ImageBase /* BaseOfCode */
> +#if __riscv_xlen == 32
> + .long 0 /* BaseOfData */
> +#endif
>
> extra_header_fields:
> .quad 0 /* ImageBase */
diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
index 4aaa49ad07..f47c4a6d82 100644
--- a/arch/riscv/lib/crt0_riscv_efi.S
+++ b/arch/riscv/lib/crt0_riscv_efi.S
@@ -63,7 +63,11 @@ optional_header:
#endif
extra_header_fields:
+#if __riscv_xlen == 32
+ .long 0 /* ImageBase */
+#else if
.quad 0 /* ImageBase */
+#endif
.long 0x20 /* SectionAlignment */
.long 0x8 /* FileAlignment */
.short 0 /* MajorOperatingSystemVersion */
@@ -83,10 +87,17 @@ extra_header_fields:
.long 0 /* CheckSum */
.short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
.short 0 /* DllCharacteristics */
+#if __riscv_xlen == 32
+ .long 0 /* SizeOfStackReserve */
+ .long 0 /* SizeOfStackCommit */
+ .long 0 /* SizeOfHeapReserve */
+ .long 0 /* SizeOfHeapCommit */
+#else if
.quad 0 /* SizeOfStackReserve */
.quad 0 /* SizeOfStackCommit */
.quad 0 /* SizeOfHeapReserve */
.quad 0 /* SizeOfHeapCommit */
+#endif
.long 0 /* LoaderFlags */
.long 0x6 /* NumberOfRvaAndSizes */
Based on Atish's patch,
would the above modification fit more closely to the specification that Heinrich provided ?
Best regards,
Leo
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH] riscv: Fix efi header for RV32
2020-11-11 8:25 ` Leo Liang
@ 2020-11-12 2:46 ` Leo Liang
2020-11-12 8:09 ` Atish Patra
1 sibling, 0 replies; 7+ messages in thread
From: Leo Liang @ 2020-11-12 2:46 UTC (permalink / raw)
To: u-boot
On Wed, Nov 11, 2020 at 04:25:53PM +0800, Leo Liang wrote:
> Hi Atish and Heinrich,
>
> On Tue, Oct 13, 2020 at 12:23:31PM -0700, Atish Patra wrote:
> > RV32 should use PE32 format instead of PE32+ as the efi header format.
> > This requires following changes
> > 1. A different header magic value
> > 2. An additional parameter known as BaseOfData. Currently, it is set to
> > zero in absence of any usage.
> >
> > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > Reviewed-by: Bin Meng <bin.meng@windriver.com>
> > Reviewed-by: Rick Chen <rick@andestech.com>
> > ---
> > arch/riscv/lib/crt0_riscv_efi.S | 7 ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
> > index 87fe1e56f906..4aaa49ad0777 100644
> > --- a/arch/riscv/lib/crt0_riscv_efi.S
> > +++ b/arch/riscv/lib/crt0_riscv_efi.S
> > @@ -15,11 +15,13 @@
> > #define SAVE_LONG(reg, idx) sd reg, (idx*SIZE_LONG)(sp)
> > #define LOAD_LONG(reg, idx) ld reg, (idx*SIZE_LONG)(sp)
> > #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV64
> > +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
> > #else
> > #define SIZE_LONG 4
> > #define SAVE_LONG(reg, idx) sw reg, (idx*SIZE_LONG)(sp)
> > #define LOAD_LONG(reg, idx) lw reg, (idx*SIZE_LONG)(sp)
> > #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV32
> > +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
> > #endif
> >
> >
> > @@ -48,7 +50,7 @@ coff_header:
> > IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
> > IMAGE_FILE_DEBUG_STRIPPED)
> > optional_header:
> > - .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
> > + .short PE_MAGIC /* PE32+ format */
> > .byte 0x02 /* MajorLinkerVersion */
> > .byte 0x14 /* MinorLinkerVersion */
> > .long _edata - _start /* SizeOfCode */
> > @@ -56,6 +58,9 @@ optional_header:
> > .long 0 /* SizeOfUninitializedData */
> > .long _start - ImageBase /* AddressOfEntryPoint */
> > .long _start - ImageBase /* BaseOfCode */
> > +#if __riscv_xlen == 32
> > + .long 0 /* BaseOfData */
> > +#endif
> >
> > extra_header_fields:
> > .quad 0 /* ImageBase */
>
> diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
> index 4aaa49ad07..f47c4a6d82 100644
> --- a/arch/riscv/lib/crt0_riscv_efi.S
> +++ b/arch/riscv/lib/crt0_riscv_efi.S
> @@ -63,7 +63,11 @@ optional_header:
> #endif
>
> extra_header_fields:
> +#if __riscv_xlen == 32
> + .long 0 /* ImageBase */
> +#else if
> .quad 0 /* ImageBase */
> +#endif
> .long 0x20 /* SectionAlignment */
> .long 0x8 /* FileAlignment */
> .short 0 /* MajorOperatingSystemVersion */
> @@ -83,10 +87,17 @@ extra_header_fields:
> .long 0 /* CheckSum */
> .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
> .short 0 /* DllCharacteristics */
> +#if __riscv_xlen == 32
> + .long 0 /* SizeOfStackReserve */
> + .long 0 /* SizeOfStackCommit */
> + .long 0 /* SizeOfHeapReserve */
> + .long 0 /* SizeOfHeapCommit */
> +#else if
> .quad 0 /* SizeOfStackReserve */
> .quad 0 /* SizeOfStackCommit */
> .quad 0 /* SizeOfHeapReserve */
> .quad 0 /* SizeOfHeapCommit */
> +#endif
> .long 0 /* LoaderFlags */
> .long 0x6 /* NumberOfRvaAndSizes */
>
> Based on Atish's patch,
> would the above modification fit more closely to the specification that Heinrich provided ?
>
> Best regards,
> Leo
Sending a new patch seems more reasonable.
I will send a new patch later based on this patch.
Best regards,
Leo
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] riscv: Fix efi header for RV32
2020-11-11 8:25 ` Leo Liang
2020-11-12 2:46 ` Leo Liang
@ 2020-11-12 8:09 ` Atish Patra
1 sibling, 0 replies; 7+ messages in thread
From: Atish Patra @ 2020-11-12 8:09 UTC (permalink / raw)
To: u-boot
On Wed, Nov 11, 2020 at 12:26 AM Leo Liang <ycliang@andestech.com> wrote:
>
> Hi Atish and Heinrich,
>
> On Tue, Oct 13, 2020 at 12:23:31PM -0700, Atish Patra wrote:
> > RV32 should use PE32 format instead of PE32+ as the efi header format.
> > This requires following changes
> > 1. A different header magic value
> > 2. An additional parameter known as BaseOfData. Currently, it is set to
> > zero in absence of any usage.
> >
> > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > Reviewed-by: Bin Meng <bin.meng@windriver.com>
> > Reviewed-by: Rick Chen <rick@andestech.com>
> > ---
> > arch/riscv/lib/crt0_riscv_efi.S | 7 ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
> > index 87fe1e56f906..4aaa49ad0777 100644
> > --- a/arch/riscv/lib/crt0_riscv_efi.S
> > +++ b/arch/riscv/lib/crt0_riscv_efi.S
> > @@ -15,11 +15,13 @@
> > #define SAVE_LONG(reg, idx) sd reg, (idx*SIZE_LONG)(sp)
> > #define LOAD_LONG(reg, idx) ld reg, (idx*SIZE_LONG)(sp)
> > #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV64
> > +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
> > #else
> > #define SIZE_LONG 4
> > #define SAVE_LONG(reg, idx) sw reg, (idx*SIZE_LONG)(sp)
> > #define LOAD_LONG(reg, idx) lw reg, (idx*SIZE_LONG)(sp)
> > #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV32
> > +#define PE_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
> > #endif
> >
> >
> > @@ -48,7 +50,7 @@ coff_header:
> > IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
> > IMAGE_FILE_DEBUG_STRIPPED)
> > optional_header:
> > - .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
> > + .short PE_MAGIC /* PE32+ format */
> > .byte 0x02 /* MajorLinkerVersion */
> > .byte 0x14 /* MinorLinkerVersion */
> > .long _edata - _start /* SizeOfCode */
> > @@ -56,6 +58,9 @@ optional_header:
> > .long 0 /* SizeOfUninitializedData */
> > .long _start - ImageBase /* AddressOfEntryPoint */
> > .long _start - ImageBase /* BaseOfCode */
> > +#if __riscv_xlen == 32
> > + .long 0 /* BaseOfData */
> > +#endif
> >
> > extra_header_fields:
> > .quad 0 /* ImageBase */
>
> diff --git a/arch/riscv/lib/crt0_riscv_efi.S b/arch/riscv/lib/crt0_riscv_efi.S
> index 4aaa49ad07..f47c4a6d82 100644
> --- a/arch/riscv/lib/crt0_riscv_efi.S
> +++ b/arch/riscv/lib/crt0_riscv_efi.S
> @@ -63,7 +63,11 @@ optional_header:
> #endif
>
> extra_header_fields:
> +#if __riscv_xlen == 32
> + .long 0 /* ImageBase */
> +#else if
> .quad 0 /* ImageBase */
> +#endif
> .long 0x20 /* SectionAlignment */
> .long 0x8 /* FileAlignment */
> .short 0 /* MajorOperatingSystemVersion */
> @@ -83,10 +87,17 @@ extra_header_fields:
> .long 0 /* CheckSum */
> .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
> .short 0 /* DllCharacteristics */
> +#if __riscv_xlen == 32
> + .long 0 /* SizeOfStackReserve */
> + .long 0 /* SizeOfStackCommit */
> + .long 0 /* SizeOfHeapReserve */
> + .long 0 /* SizeOfHeapCommit */
> +#else if
> .quad 0 /* SizeOfStackReserve */
> .quad 0 /* SizeOfStackCommit */
> .quad 0 /* SizeOfHeapReserve */
> .quad 0 /* SizeOfHeapCommit */
> +#endif
> .long 0 /* LoaderFlags */
> .long 0x6 /* NumberOfRvaAndSizes */
>
Sorry for not responding to this thread earlier. It went to a
different filter due to a filtering mistake.
> Based on Atish's patch,
> would the above modification fit more closely to the specification that Heinrich provided ?
>
The above changes look good to me and matches the PE32 spec. Thanks for the fix.
> Best regards,
> Leo
--
Regards,
Atish
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-11-12 8:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-13 19:23 [PATCH] riscv: Fix efi header for RV32 Atish Patra
2020-10-14 1:03 ` Bin Meng
2020-10-14 1:16 ` Heinrich Schuchardt
[not found] ` <752D002CFF5D0F4FA35C0100F1D73F3FB22ACFD8@ATCPCS12.andestech.com>
2020-11-04 1:49 ` Rick Chen
2020-11-11 8:25 ` Leo Liang
2020-11-12 2:46 ` Leo Liang
2020-11-12 8:09 ` Atish Patra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox