Hi Lokesh,

Then a common rproc_elf_sanity_check() 32/64-bit common API would be 
great :)


BR

Fabien


On 28/08/2019 2:55 PM, Lokesh Vutla wrote:
> Introduce a common remoteproc elf loader function that automatically
> detects the 64 bit elf file or 32 bit elf file and loads the sections
> accordingly.
>
> Signed-off-by: Lokesh Vutla <lokeshvu...@ti.com>
> ---
>   drivers/remoteproc/rproc-elf-loader.c | 15 +++++++++++++++
>   include/remoteproc.h                  | 14 ++++++++++++++
>   2 files changed, 29 insertions(+)
>
> diff --git a/drivers/remoteproc/rproc-elf-loader.c 
> b/drivers/remoteproc/rproc-elf-loader.c
> index dff1873a51..276164bae7 100644
> --- a/drivers/remoteproc/rproc-elf-loader.c
> +++ b/drivers/remoteproc/rproc-elf-loader.c
> @@ -219,3 +219,18 @@ int rproc_elf64_load_image(struct udevice *dev, ulong 
> addr, ulong size)
>   
>       return ret;
>   }
> +
> +int rproc_elf_load_image(struct udevice *dev, ulong addr, ulong size)
> +{
> +     Elf32_Ehdr *ehdr = (Elf32_Ehdr *)addr;
> +
> +     if (!addr) {
> +             dev_err(dev, "Invalid firmware address\n");
> +             return -EFAULT;
> +     }
> +
> +     if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
> +             return rproc_elf64_load_image(dev, addr, size);
> +     else
> +             return rproc_elf32_load_image(dev, addr, size);
> +}
> diff --git a/include/remoteproc.h b/include/remoteproc.h
> index f5d77c8c81..e0493aae2c 100644
> --- a/include/remoteproc.h
> +++ b/include/remoteproc.h
> @@ -219,6 +219,17 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned 
> long addr, ulong size);
>    * @return 0 if the image is successfully loaded, else appropriate error 
> value.
>    */
>   int rproc_elf64_load_image(struct udevice *dev, ulong addr, ulong size);
> +
> +/**
> + * rproc_elf_load_image() - load an ELF image
> + * @dev:     device loading the ELF image
> + * @addr:    valid ELF image address
> + * @size:    size of the image
> + *
> + * Auto detects if the image is ELF32 or ELF64 image and load accordingly.
> + * @return 0 if the image is successfully loaded, else appropriate error 
> value.
> + */
> +int rproc_elf_load_image(struct udevice *dev, unsigned long addr, ulong 
> size);
>   #else
>   static inline int rproc_init(void) { return -ENOSYS; }
>   static inline int rproc_dev_init(int id) { return -ENOSYS; }
> @@ -235,6 +246,9 @@ static inline int rproc_elf32_load_image(struct udevice 
> *dev,
>   static inline int rproc_elf64_load_image(struct udevice *dev, ulong addr,
>                                        ulong size)
>   { return -ENOSYS; }
> +static inline int rproc_elf_load_image(struct udevice *dev, ulong addr,
> +                                    ulong size)
> +{ return -ENOSYS; }
>   #endif
>   
>   #endif      /* _RPROC_H_ */
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to