All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabien DESSENNE <fabien.dessenne@st.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 04/26] remoteproc: elf-loader: Add 64 bit elf loading support
Date: Wed, 4 Sep 2019 15:06:56 +0000	[thread overview]
Message-ID: <16df7b10-ccaa-083d-0bfc-555cf757bc16@st.com> (raw)
In-Reply-To: <20190904103151.20121-5-lokeshvutla@ti.com>

Hi Lokesh

Thank you for the patch.

BR

Fabien


On 04/09/2019 12:31 PM, Lokesh Vutla wrote:
> The current rproc-elf-loader supports loading of only 32 bit elf files.
> Introduce support for loading of 64 bit elf files in rproc-elf-loader.
>
> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Fabien Dessenne <fabien.dessenne@st.com>
> ---
>   drivers/remoteproc/rproc-elf-loader.c | 110 ++++++++++++++++++++++++++
>   include/remoteproc.h                  |  26 ++++++
>   2 files changed, 136 insertions(+)
>
> diff --git a/drivers/remoteproc/rproc-elf-loader.c b/drivers/remoteproc/rproc-elf-loader.c
> index 238f51d3b5..1aece2fc31 100644
> --- a/drivers/remoteproc/rproc-elf-loader.c
> +++ b/drivers/remoteproc/rproc-elf-loader.c
> @@ -64,6 +64,62 @@ int rproc_elf32_sanity_check(ulong addr, ulong size)
>   	return 0;
>   }
>   
> +/* Basic function to verify ELF64 image format */
> +int rproc_elf64_sanity_check(ulong addr, ulong size)
> +{
> +	Elf64_Ehdr *ehdr = (Elf64_Ehdr *)addr;
> +	char class;
> +
> +	if (!addr) {
> +		pr_debug("Invalid fw address?\n");
> +		return -EFAULT;
> +	}
> +
> +	if (size < sizeof(Elf64_Ehdr)) {
> +		pr_debug("Image is too small\n");
> +		return -ENOSPC;
> +	}
> +
> +	class = ehdr->e_ident[EI_CLASS];
> +
> +	if (!IS_ELF(*ehdr) || ehdr->e_type != ET_EXEC || class != ELFCLASS64) {
> +		pr_debug("Not an executable ELF64 image\n");
> +		return -EPROTONOSUPPORT;
> +	}
> +
> +	/* We assume the firmware has the same endianness as the host */
> +# ifdef __LITTLE_ENDIAN
> +	if (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) {
> +# else /* BIG ENDIAN */
> +	if (ehdr->e_ident[EI_DATA] != ELFDATA2MSB) {
> +# endif
> +		pr_debug("Unsupported firmware endianness\n");
> +		return -EILSEQ;
> +	}
> +
> +	if (size < ehdr->e_shoff + sizeof(Elf64_Shdr)) {
> +		pr_debug("Image is too small\n");
> +		return -ENOSPC;
> +	}
> +
> +	if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG)) {
> +		pr_debug("Image is corrupted (bad magic)\n");
> +		return -EBADF;
> +	}
> +
> +	if (ehdr->e_phnum == 0) {
> +		pr_debug("No loadable segments\n");
> +		return -ENOEXEC;
> +	}
> +
> +	if (ehdr->e_phoff > size) {
> +		pr_debug("Firmware size is too small\n");
> +		return -ENOSPC;
> +	}
> +
> +	return 0;
> +}
> +
>   int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
>   {
>   	Elf32_Ehdr *ehdr; /* Elf header structure pointer */
> @@ -110,3 +166,57 @@ int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size)
>   
>   	return 0;
>   }
> +
> +int rproc_elf64_load_image(struct udevice *dev, ulong addr, ulong size)
> +{
> +	const struct dm_rproc_ops *ops = rproc_get_ops(dev);
> +	u64 da, memsz, filesz, offset;
> +	Elf64_Ehdr *ehdr;
> +	Elf64_Phdr *phdr;
> +	int i, ret = 0;
> +	void *ptr;
> +
> +	dev_dbg(dev, "%s: addr = 0x%lx size = 0x%lx\n", __func__, addr, size);
> +
> +	if (rproc_elf64_sanity_check(addr, size))
> +		return -EINVAL;
> +
> +	ehdr = (Elf64_Ehdr *)addr;
> +	phdr = (Elf64_Phdr *)(addr + (ulong)ehdr->e_phoff);
> +
> +	/* go through the available ELF segments */
> +	for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
> +		da = phdr->p_paddr;
> +		memsz = phdr->p_memsz;
> +		filesz = phdr->p_filesz;
> +		offset = phdr->p_offset;
> +
> +		if (phdr->p_type != PT_LOAD)
> +			continue;
> +
> +		dev_dbg(dev, "%s:phdr: type %d da 0x%llx memsz 0x%llx filesz 0x%llx\n",
> +			__func__, phdr->p_type, da, memsz, filesz);
> +
> +		ptr = (void *)(uintptr_t)da;
> +		if (ops->device_to_virt) {
> +			ptr = ops->device_to_virt(dev, da, phdr->p_memsz);
> +			if (!ptr) {
> +				dev_err(dev, "bad da 0x%llx mem 0x%llx\n", da,
> +					memsz);
> +				ret = -EINVAL;
> +				break;
> +			}
> +		}
> +
> +		if (filesz)
> +			memcpy(ptr, (void *)addr + offset, filesz);
> +		if (filesz != memsz)
> +			memset(ptr + filesz, 0x00, memsz - filesz);
> +
> +		flush_cache(rounddown((ulong)ptr, ARCH_DMA_MINALIGN),
> +			    roundup((ulong)ptr + filesz, ARCH_DMA_MINALIGN) -
> +			    rounddown((ulong)ptr, ARCH_DMA_MINALIGN));
> +	}
> +
> +	return ret;
> +}
> diff --git a/include/remoteproc.h b/include/remoteproc.h
> index 1ef88be7f7..56a11db6e3 100644
> --- a/include/remoteproc.h
> +++ b/include/remoteproc.h
> @@ -214,6 +214,18 @@ int rproc_is_running(int id);
>    */
>   int rproc_elf32_sanity_check(ulong addr, ulong size);
>   
> +/**
> + * rproc_elf64_sanity_check() - Verify if an image is a valid ELF32 one
> + *
> + * Check if a valid ELF64 image exists at the given memory location. Verify
> + * basic ELF64 format requirements like magic number and sections size.
> + *
> + * @addr:	address of the image to verify
> + * @size:	size of the image
> + * @return 0 if the image looks good, else appropriate error value.
> + */
> +int rproc_elf64_sanity_check(ulong addr, ulong size);
> +
>   /**
>    * rproc_elf32_load_image() - load an ELF32 image
>    * @dev:	device loading the ELF32 image
> @@ -222,6 +234,15 @@ int rproc_elf32_sanity_check(ulong addr, ulong size);
>    * @return 0 if the image is successfully loaded, else appropriate error value.
>    */
>   int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size);
> +
> +/**
> + * rproc_elf64_load_image() - load an ELF64 image
> + * @dev:	device loading the ELF64 image
> + * @addr:	valid ELF64 image address
> + * @size:	size of the image
> + * @return 0 if the image is successfully loaded, else appropriate error value.
> + */
> +int rproc_elf64_load_image(struct udevice *dev, ulong addr, ulong size);
>   #else
>   static inline int rproc_init(void) { return -ENOSYS; }
>   static inline int rproc_dev_init(int id) { return -ENOSYS; }
> @@ -234,9 +255,14 @@ static inline int rproc_ping(int id) { return -ENOSYS; }
>   static inline int rproc_is_running(int id) { return -ENOSYS; }
>   static inline int rproc_elf32_sanity_check(ulong addr,
>   					   ulong size) { return -ENOSYS; }
> +static inline int rproc_elf64_sanity_check(ulong addr,
> +					   ulong size) { return -ENOSYS; }
>   static inline int rproc_elf32_load_image(struct udevice *dev,
>   					 unsigned long addr, ulong size)
>   { return -ENOSYS; }
> +static inline int rproc_elf64_load_image(struct udevice *dev, ulong addr,
> +					 ulong size)
> +{ return -ENOSYS; }
>   #endif
>   
>   #endif	/* _RPROC_H_ */

  reply	other threads:[~2019-09-04 15:06 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-04 10:31 [U-Boot] [PATCH v2 00/26] remoteproc: Add support for R5F and DSP processors Lokesh Vutla
2019-09-04 10:31 ` [U-Boot] [PATCH v2 01/26] dm: core: Add a function to count the children of a device Lokesh Vutla
2019-10-12 20:24   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 02/26] remoteproc: ops: Add elf section size as input parameter to device_to_virt api Lokesh Vutla
2019-09-04 15:04   ` Fabien DESSENNE
2019-10-12 20:24   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 03/26] remoteproc: elf_loader: Always check the validity of the image before loading Lokesh Vutla
2019-09-04 15:05   ` Fabien DESSENNE
2019-10-12 20:24   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 04/26] remoteproc: elf-loader: Add 64 bit elf loading support Lokesh Vutla
2019-09-04 15:06   ` Fabien DESSENNE [this message]
2019-10-12 20:24   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 05/26] remoteproc: elf_loader: Introduce a common elf loader and checker functions Lokesh Vutla
2019-09-04 15:05   ` Fabien DESSENNE
2019-10-12 20:24   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 06/26] remoteproc: elf_loader: Introduce rproc_elf_get_boot_addr() api Lokesh Vutla
2019-10-12 20:24   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 07/26] remoteproc: tisci_proc: Add helper api for controlling core power domain Lokesh Vutla
2019-10-12 20:24   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 08/26] dt-bindings: remoteproc: Add bindings for R5F subsystem on TI K3 SoCs Lokesh Vutla
2019-10-12 20:24   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 09/26] remoteproc: Introduce K3 remoteproc driver for R5F subsystem Lokesh Vutla
2019-10-12 20:24   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 10/26] dt-bindings: remoteproc: Add bindings for DSP C66x clusters on TI K3 SoCs Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 11/26] remoteproc: Introduce K3 C66 and C71 remoteproc driver Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 12/26] arm: dts: k3-j721e-mcu: Add MCU domain R5F cluster node Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 13/26] arm: dts: k3-j721e-main: Add MAIN domain R5F cluster nodes Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 14/26] arm: dts: k3-j721e-main: Add C66x DSP nodes Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 15/26] arm: dts: k3-j721e-main: Add C71x DSP node Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 16/26] arm: dts: k3-am65-mcu: Add MCU domain R5F DT nodes Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 17/26] env: ti: k3_rproc: Add common rproc environment variables Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 18/26] env: ti: j721e-evm: Add support to boot rprocs including R5Fs and DSPs Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 19/26] env: ti: am65x_evm: Add env support to boot the MCU R5F rprocs Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 20/26] configs: j721e_evm_a72: Enable R5F and DSP remoteproc driver Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 21/26] configs: j721e_evm_a72: Enhance bootcmd to start remoteprocs Lokesh Vutla
2019-10-12 20:25   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 22/26] configs: am65x_evm_a53: Enable R5F remoteproc driver Lokesh Vutla
2019-10-12 20:26   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 23/26] configs: am65x_evm_a53: Enhance bootcmd to start remoteprocs Lokesh Vutla
2019-10-12 20:26   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 24/26] armv8: K3: am65x: Update DDR address regions in MMU table Lokesh Vutla
2019-10-12 20:26   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 25/26] armv8: K3: j721e: Updated ddr " Lokesh Vutla
2019-10-12 20:26   ` Tom Rini
2019-09-04 10:31 ` [U-Boot] [PATCH v2 26/26] board: j721e: Add README Lokesh Vutla
2019-10-12 20:26   ` Tom Rini

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=16df7b10-ccaa-083d-0bfc-555cf757bc16@st.com \
    --to=fabien.dessenne@st.com \
    --cc=u-boot@lists.denx.de \
    /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.