diff mbox

[v8,1/5] loader: Allow ELF loader to auto-detect the ELF arch

Message ID 8be6c03a245859be421fb38ffa6dfa3d29945ecf.1467417982.git.alistair.francis@xilinx.com
State New
Headers show

Commit Message

Alistair Francis July 2, 2016, 1:07 a.m. UTC
If the caller didn't specify an architecture for the ELF machine
the load_elf() function will auto detect it based on the ELF file.

Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---
V8:
 - Move into load_elf64/load_elf32
V7:
 - Fix typo

 include/hw/elf_ops.h | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Peter Maydell July 12, 2016, 4:40 p.m. UTC | #1
On 2 July 2016 at 02:07, Alistair Francis <alistair.francis@xilinx.com> wrote:
> If the caller didn't specify an architecture for the ELF machine
> the load_elf() function will auto detect it based on the ELF file.
>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
> V8:
>  - Move into load_elf64/load_elf32
> V7:
>  - Fix typo
>
>  include/hw/elf_ops.h | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
> index f510e7e..db70c11 100644
> --- a/include/hw/elf_ops.h
> +++ b/include/hw/elf_ops.h
> @@ -280,6 +280,11 @@ static int glue(load_elf, SZ)(const char *name, int fd,
>          glue(bswap_ehdr, SZ)(&ehdr);
>      }
>
> +    if (elf_machine < 1) {
> +        /* The caller didn't specify an ARCH, we can figure it out */
> +        elf_machine = ehdr.e_machine;
> +    }
> +
>      switch (elf_machine) {
>          case EM_PPC64:
>              if (ehdr.e_machine != EM_PPC64) {

Is there also a doc comment that should be updated with this change?

thanks
-- PMM
Alistair Francis July 13, 2016, 12:44 a.m. UTC | #2
On Tue, Jul 12, 2016 at 9:40 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 2 July 2016 at 02:07, Alistair Francis <alistair.francis@xilinx.com> wrote:
>> If the caller didn't specify an architecture for the ELF machine
>> the load_elf() function will auto detect it based on the ELF file.
>>
>> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
>> ---
>> V8:
>>  - Move into load_elf64/load_elf32
>> V7:
>>  - Fix typo
>>
>>  include/hw/elf_ops.h | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
>> index f510e7e..db70c11 100644
>> --- a/include/hw/elf_ops.h
>> +++ b/include/hw/elf_ops.h
>> @@ -280,6 +280,11 @@ static int glue(load_elf, SZ)(const char *name, int fd,
>>          glue(bswap_ehdr, SZ)(&ehdr);
>>      }
>>
>> +    if (elf_machine < 1) {
>> +        /* The caller didn't specify an ARCH, we can figure it out */
>> +        elf_machine = ehdr.e_machine;
>> +    }
>> +
>>      switch (elf_machine) {
>>          case EM_PPC64:
>>              if (ehdr.e_machine != EM_PPC64) {
>
> Is there also a doc comment that should be updated with this change?

Yep, updated.

Thanks,

Alistair

>
> thanks
> -- PMM
>
diff mbox

Patch

diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index f510e7e..db70c11 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -280,6 +280,11 @@  static int glue(load_elf, SZ)(const char *name, int fd,
         glue(bswap_ehdr, SZ)(&ehdr);
     }
 
+    if (elf_machine < 1) {
+        /* The caller didn't specify an ARCH, we can figure it out */
+        elf_machine = ehdr.e_machine;
+    }
+
     switch (elf_machine) {
         case EM_PPC64:
             if (ehdr.e_machine != EM_PPC64) {