Add STM32 Cortex-M4 remoteproc driver
Subsystems (2)
cover Add STM32 Cortex-M4 remoteproc driver
This patchset adds an STM32 remoteproc driver.
The two first patches add the xxx_translate_dma_address() API which is the equivalent of the xxx_translate_address() relying on the "dma-ranges" property instead of the "ranges" property.
The patches 3 & 4 add the support of the ELF image loading (the current implementation supports only binary image loading).
The 5th patch is about the driver, and the two last patches are about MAINTAINERS and configs update.
Fabien Dessenne (7):
fdt: Introduce fdt_translate_dma_address()
dm: core: Introduce xxx_translate_dma_address()
remoteproc: add da_to_pa ops
remoteproc: add elf file load support
remoteproc: Introduce STM32 Cortex-M4 remoteproc driver
MAINTAINERS: Add stm32 remoteproc driver
configs: stm32mp15: enable stm32 remoteproc
MAINTAINERS | 1 + common/fdt_support.c | 6 + configs/stm32mp15_basic_defconfig | 2 + configs/stm32mp15_trusted_defconfig | 2 + drivers/core/of_addr.c | 4 + drivers/core/ofnode.c | 8 ++ drivers/core/read.c | 5 + drivers/remoteproc/Kconfig | 10 ++ drivers/remoteproc/Makefile | 1 + drivers/remoteproc/rproc-uclass.c | 128 ++++++++++++++++++ drivers/remoteproc/stm32_copro.c | 257 ++++++++++++++++++++++++++++++++++++ include/dm/of_addr.h | 18 +++ include/dm/ofnode.h | 16 ++- include/dm/read.h | 20 ++- include/fdt_support.h | 2 + include/remoteproc.h | 32 ++++- 16 files changed, 509 insertions(+), 3 deletions(-) create mode 100644 drivers/remoteproc/stm32_copro.c
Signature · 1 line
2.7.4
PATCH 1/7 fdt: Introduce fdt_translate_dma_address()
Add the fdt_translate_dma_address() function to translate DMA address to CPU address.
This function works the same way as fdt_translate_address(), with the difference that the translation relies on the "dma-ranges" property instead of the "ranges" property.
--- common/fdt_support.c | 6 ++++++ include/fdt_support.h | 2 ++ 2 files changed, 8 insertions(+)
common/fdt_support.c +6 -0
@@ -1279,6 +1279,12 @@ u64 fdt_translate_address(const void *blob, int node_offset,return __of_translate_address (blob, node_offset, in_addr,"ranges" ); } +u64 fdt_translate_dma_address (const void *blob,int node_offset, +const fdt32_t *in_addr) +{ +return __of_translate_address (blob, node_offset, in_addr,"dma-ranges" ); +} +/** * fdt_node_offset_by_compat_reg: Find a node that matches compatiable and * who's reg property matches a physical cpu address
include/fdt_support.h +2 -0
@@ -220,6 +220,8 @@ static inline void fdt_fixup_mtdparts(void *fdt,void fdt_del_node_and_alias (void *blob,const char *alias);u64 fdt_translate_address (const void *blob,int node_offset,const __be32 *in_addr); +u64 fdt_translate_dma_address (const void *blob,int node_offset, +const __be32 *in_addr);int fdt_node_offset_by_compat_reg (void *blob,const char *compat,phys_addr_t compat_off);int fdt_alloc_phandle (void *blob);
Signature · 1 line
2.7.4
PATCH 1/7 fdt: Introduce fdt_translate_dma_address()
Hi Fabien,
Quoted 7 lines · Fabien Dessenne
Add the
fdt_translate_dma_address()function to translate DMA address to CPU address.
This function works the same way asfdt_translate_address(), with the difference that the translation relies on the "dma-ranges" property instead of the "ranges" property.
Quoted 5 lines
Signed-off-by Fabien Dessenne <[email protected]>--- common/fdt_support.c | 6 ++++++ include/fdt_support.h | 2 ++ 2 files changed, 8 insertions(+)
Please can you add a simple test for this, and also a function comment in the header file?
Regards,
Simon
PATCH 2/7 dm: core: Introduce xxx_translate_dma_address()
In reply to Fabien DessenneAdd the following functions to translate DMA address to CPU address:
- dev_translate_dma_address()
- ofnode_translate_dma_address()
- of_translate_dma_address()
These functions work the same way as xxx_translate_address(), with the difference that the translation relies on the "dma-ranges" property instead of the "ranges" property.
--- drivers/core/of_addr.c | 4 ++++ drivers/core/ofnode.c | 8 ++++++++ drivers/core/read.c | 5 +++++ include/dm/of_addr.h | 18 ++++++++++++++++++ include/dm/ofnode.h | 16 +++++++++++++++- include/dm/read.h | 20 +++++++++++++++++++- 6 files changed, 69 insertions(+), 2 deletions(-)
drivers/core/of_addr.c +4 -0
@@ -318,6 +318,10 @@ u64 of_translate_address(const struct device_node *dev, const __be32 *in_addr)return __of_translate_address (dev, in_addr,"ranges" ); } +u64 of_translate_dma_address (const struct device_node *dev,const __be32 *in_addr) +{ +return __of_translate_address (dev, in_addr,"dma-ranges" ); +} static int __of_address_to_resource(const struct device_node *dev, const __be32 *addrp, u64 size, unsigned int flags,
drivers/core/ofnode.c +8 -0
@@ -763,6 +763,14 @@ u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr)return fdt_translate_address (gd->fdt_blob,ofnode_to_offset (node), in_addr); } +u64 ofnode_translate_dma_address (ofnode node,const fdt32_t *in_addr) +{ +if (ofnode_is_np (node)) +return of_translate_dma_address (ofnode_to_np (node), in_addr); +else +return fdt_translate_dma_address (gd->fdt_blob,ofnode_to_offset (node), in_addr); +} +int ofnode_device_is_compatible (ofnode node,const char *compat) {if (ofnode_is_np (node))
drivers/core/read.c +5 -0
@@ -265,6 +265,11 @@ u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)return ofnode_translate_address (dev_ofnode (dev), in_addr); } +u64 dev_translate_dma_address (struct udevice *dev,const fdt32_t *in_addr) +{ +return ofnode_translate_dma_address (dev_ofnode (dev), in_addr); +} +int dev_read_alias_highest_id (const char *stem) {if (of_live_active ())
include/dm/of_addr.h +18 -0
@@ -27,6 +27,24 @@u64 of_translate_address (const struct device_node *no,const __be32 *in_addr);/** +* of_translate_dma_address() - translate a device-tree DMA address to a CPU +* address +* +* Translate a DMA address from the device-tree into a CPU physical address, +* this walks up the tree and applies the various bus mappings on the way. +* +* Note: We consider that crossing any level with #size-cells == 0 to mean +* that translation is impossible (that is we are not dealing with a value +* that can be mapped to a cpu physical address). This is not really specified +* that way, but this is traditionally the way IBM at least do things +* +* @np: node to check +* @in_addr: pointer to input DMA address +* @return translated DMA address or OF_BAD_ADDR on error +*/ +u64 of_translate_dma_address (const struct device_node *no,const __be32 *in_addr); + +/** * of_get_address() - obtain an address from a node * * Extract an address from a node, returns the region size and the address
include/dm/ofnode.h +15 -1
@@ -751,7 +751,7 @@ ofnode ofnode_by_prop_value(ofnode from, const char *propname, node = ofnode_next_subnode(node))/** -* ofnode_translate_address() - Tranlate a device-tree address +* ofnode_translate_address() - Translate a device-tree address * * Translate an address from the device-tree into a CPU physical address. This * function walks up the tree and applies the various bus mappings along the
@@ -765,6 +765,20 @@ ofnode ofnode_by_prop_value(ofnode from, const char *propname,u64 ofnode_translate_address (ofnode node,const fdt32_t *in_addr);/** +* ofnode_translate_dma_address() - Translate a device-tree DMA address +* +* Translate a DMA address from the device-tree into a CPU physical address. +* This function walks up the tree and applies the various bus mappings along +* the way. +* +* @ofnode: Device tree node giving the context in which to translate the +* DMA address +* @in_addr: pointer to the DMA address to translate +* @return the translated DMA address; OF_BAD_ADDR on error +*/ +u64 ofnode_translate_dma_address (ofnode node,const fdt32_t *in_addr); + +/** * ofnode_device_is_compatible() - check if the node is compatible with compat * * This allows to check whether the node is comaptible with the compat.
include/dm/read.h +19 -1
@@ -499,7 +499,7 @@ int dev_read_resource_byname(struct udevice *dev, const char *name, struct resource *res);/** -* dev_translate_address() - Tranlate a device-tree address +* dev_translate_address() - Translate a device-tree address * * Translate an address from the device-tree into a CPU physical address. This * function walks up the tree and applies the various bus mappings along the
@@ -512,6 +512,19 @@ int dev_read_resource_byname(struct udevice *dev, const char *name,u64 dev_translate_address (struct udevice *dev,const fdt32_t *in_addr);/** +* dev_translate_dma_address() - Translate a device-tree DMA address +* +* Translate a DMA address from the device-tree into a CPU physical address. +* This function walks up the tree and applies the various bus mappings along +* the way. +* +* @dev: device giving the context in which to translate the DMA address +* @in_addr: pointer to the DMA address to translate +* @return the translated DMA address; OF_BAD_ADDR on error +*/ +u64 dev_translate_dma_address (struct udevice *dev,const fdt32_t *in_addr); + +/** * dev_read_alias_highest_id - Get highest alias id for the given stem * @stem: Alias stem to be examined *
@@ -751,6 +764,11 @@ static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_areturn ofnode_translate_address (dev_ofnode (dev), in_addr); } +static inline u64 dev_translate_dma_address (struct udevice *dev,const fdt32_t *in_addr) +{ +return ofnode_translate_dma_address (dev_ofnode (dev), in_addr); +} +static inline int dev_read_alias_highest_id (const char *stem) {return fdtdec_get_alias_highest_id (gd->fdt_blob, stem);
Signature · 1 line
2.7.4
PATCH 2/7 dm: core: Introduce xxx_translate_dma_address()
Hi Fabien,
Quoted 9 lines · Fabien Dessenne
Add the following functions to translate DMA address to CPU address:
-dev_translate_dma_address()
-ofnode_translate_dma_address()
-of_translate_dma_address()
These functions work the same way asxxx_translate_address(), with the difference that the translation relies on the "dma-ranges" property instead of the "ranges" property.
Looks good, but again, needs a test.
Quoted 10 lines
Signed-off-by Fabien Dessenne <[email protected]>--- drivers/core/of_addr.c | 4 ++++ drivers/core/ofnode.c | 8 ++++++++ drivers/core/read.c | 5 +++++ include/dm/of_addr.h | 18 ++++++++++++++++++ include/dm/ofnode.h | 16 +++++++++++++++- include/dm/read.h | 20 +++++++++++++++++++- 6 files changed, 69 insertions(+), 2 deletions(-)
Regards,
Simon
PATCH 3/7 remoteproc: add da_to_pa ops
In reply to Fabien DessenneThis patch introduces da_to_pa function to allow translation between device address (remote processor view) and physical address (main processor view).
--- include/remoteproc.h | 3 +++ 1 file changed, 3 insertions(+)
include/remoteproc.h +3 -0
@@ -63,6 +63,8 @@ struct dm_rproc_uclass_pdata {* Return 0 on success, 1 if not running, -ve on others errors * @ping: Ping the remote device for basic communication check(optional) * Return 0 on success, 1 if not responding, -ve on other errors +* @da_to_pa: Return translated physical address (device address different +* from physical address) */ struct dm_rproc_ops {int (*init)(struct udevice *dev);
@@ -72,6 +74,7 @@ struct dm_rproc_ops {int (*reset)(struct udevice *dev);int (*is_running)(struct udevice *dev);int (*ping)(struct udevice *dev); +ulong (*da_to_pa)(struct udevice *dev,ulong da); };/* Accessor */
Signature · 1 line
2.7.4
PATCH 3/7 remoteproc: add da_to_pa ops
Hi Fabien,
Quoted 16 lines · Fabien Dessenne
This patch introduces
da_to_pafunction to allow translation between device address (remote processor view) and physical address (main processor view).Signed-off-by Loic Pallardy <[email protected]>Signed-off-by Fabien Dessenne <[email protected]>--- include/remoteproc.h | 3 +++ 1 file changed, 3 insertions(+)include/remoteproc.h +0
-0
include/remoteproc.h struct dm_rproc_uclass_pdata { · line 67
Quoted 5 lines
include/remoteproc.h +2
-0@@ -63,6 +63,8 @@ struct dm_rproc_uclass_pdata {* Return 0 on success, 1 if not running, -ve on others errors * @ping: Ping the remote device for basic communication check(optional) * Return 0 on success, 1 if not responding, -ve on other errors +* @da_to_pa: Return translated physical address (device address different +* from physical address)
How about device_addr_to_phys()?
Also please add a full function comment here and below. This uclass header seems to be delinquent.
Quoted 12 lines
include/remoteproc.h +1
-1*/ struct dm_rproc_ops {int (*init)(struct udevice *dev);@@ -72,6 +74,7 @@ struct dm_rproc_ops {int (*reset)(struct udevice *dev);int (*is_running)(struct udevice *dev);int (*ping)(struct udevice *dev); +ulong (*da_to_pa)(struct udevice *dev,ulong da); };/* Accessor */ --
Quoted 2 lines
2.7.4
Regards,
Simon
PATCH 4/7 remoteproc: add elf file load support
In reply to Fabien DessenneThe current implementation supports only binary file load. Add helpers to support ELF format (check validity, sanity check, and load).
Note that since an ELF image is built for the remote processor, the load function uses the da_to_pa ops to translate the addresses.
--- drivers/remoteproc/rproc-uclass.c | 128 ++++++++++++++++++++++++++++++++++++++ include/remoteproc.h | 29 ++++++++- 2 files changed, 156 insertions(+), 1 deletion(-)
drivers/remoteproc/rproc-uclass.c +128 -0
@@ -5,6 +5,7 @@*/ #define pr_fmt (fmt) "%s: " fmt, __func__#include <common.h> +#include <elf.h> #include <errno.h> #include <fdtdec.h> #include <malloc.h>
@@ -291,6 +292,133 @@ int rproc_dev_init(int id)return ret; } +/* +* Determine if a valid ELF image exists at the given memory location. +* First look at the ELF header magic field, then make sure that it is +* executable. +*/ +bool rproc_elf_is_valid (unsigned long addr,int size) +{ +Elf32_Ehdr *ehdr;/* Elf header structure pointer */ + + ehdr = (Elf32_Ehdr *)addr; + +if (!IS_ELF (*ehdr) || size <=sizeof (Elf32_Ehdr)) { +pr_err ("No elf image@address 0x%08lx\n" , addr); +return false; + } + +if (ehdr->e_type !=ET_EXEC ) { +pr_err ("Not a 32-bit elf image at address 0x%08lx\n" , addr); +return false; + } + +return true; +} + +/* Basic function to verify ELF image format */ +int rproc_elf_sanity_check (ulong addr,ulong size) +{ +Elf32_Ehdr *ehdr; +char class; + +if (!addr) { +pr_err ("Invalid fw address?\n" ); +return -EINVAL ; + } + +if (size <sizeof (Elf32_Ehdr)) { +pr_err ("Image is too small\n" ); +return -EINVAL ; + } + + ehdr = (Elf32_Ehdr *)addr; + +/* We only support ELF32@this point */ + class = ehdr->e_ident[EI_CLASS ]; +if (class !=ELFCLASS32 ) { +pr_err ("Unsupported class: %d\n" , class); +return -EINVAL ; + } + +/* 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_err ("Unsupported firmware endianness\n" ); +return -EINVAL ; + } + +if (size < ehdr->e_shoff +sizeof (Elf32_Shdr)) { +pr_err ("Image is too small\n" ); +return -EINVAL ; + } + +if (memcmp (ehdr->e_ident,ELFMAG ,SELFMAG )) { +pr_err ("Image is corrupted (bad magic)\n" ); +return -EINVAL ; + } + +if (ehdr->e_phnum ==0 ) { +pr_err ("No loadable segments\n" ); +return -EINVAL ; + } + +if (ehdr->e_phoff > size) { +pr_err ("Firmware size is too small\n" ); +return -EINVAL ; + } + +return 0 ; +} + +/* A very simple elf loader, assumes the image is valid */ +int rproc_elf_load_image (struct udevice *dev,unsigned long addr) +{ +Elf32_Ehdr *ehdr;/* Elf header structure pointer */ +Elf32_Phdr *phdr;/* Program header structure pointer */ +const struct dm_rproc_ops *ops; +unsigned int i; + + ehdr = (Elf32_Ehdr *)addr; + phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff); + + ops =rproc_get_ops (dev); +if (!ops) { +dev_dbg (dev,"Driver has no ops?\n" ); +return -EINVAL ; + } + +/* Load each program header */ +for (i =0 ; i < ehdr->e_phnum; ++i) { +void *dst = (void *)(uintptr_t )phdr->p_paddr; +void *src = (void *)addr + phdr->p_offset; + +if (phdr->p_type !=PT_LOAD ) +continue ; + +if (ops->da_to_pa) + dst = (void *)ops->da_to_pa (dev, (ulong )dst); + +dev_dbg (dev,"Loading phdr %i to 0x%p (%i bytes)\n" , + i, dst, phdr->p_filesz); +if (phdr->p_filesz) +memcpy (dst, src, phdr->p_filesz); +if (phdr->p_filesz != phdr->p_memsz) +memset (dst + phdr->p_filesz,0x00 , + phdr->p_memsz - phdr->p_filesz); +flush_cache (rounddown ((unsigned long )dst,ARCH_DMA_MINALIGN ), +roundup ((unsigned long )dst + phdr->p_filesz, +ARCH_DMA_MINALIGN ) - +rounddown ((unsigned long )dst,ARCH_DMA_MINALIGN )); + ++phdr; + } + +return 0 ; +} +int rproc_load (int id,ulong addr,ulong size) {struct udevice *dev =NULL ;
include/remoteproc.h +28 -1
@@ -104,7 +104,7 @@ int rproc_dev_init(int id);bool rproc_is_initialized (void );/** -* rproc_load() - load binary to a remote processor +* rproc_load() - load binary or elf to a remote processor * @id: id of the remote processor * @addr: address in memory where the binary image is located * @size: size of the binary image
@@ -159,6 +159,27 @@ int rproc_ping(int id);* Return: 0 if all ok, else appropriate error value. */ int rproc_is_running (int id); + +/** +* rproc_elf_is_valid() - check if an image is a valid ELF one +* @addr: image address +* @size: image size +*/ +bool rproc_elf_is_valid (unsigned long addr,int size); + +/** +* rproc_elf_sanity_check() - verify an ELF image format +* @addr: ELF image address +* @size: ELF image size +*/ +int rproc_elf_sanity_check (ulong addr,ulong size); + +/** +* rproc_elf_load_image() - load an ELF image +* @dev: device loading the ELF image +* @addr: valid ELF image address +*/ +int rproc_elf_load_image (struct udevice *dev,unsigned long addr);#else static inline int rproc_init (void ) {return -ENOSYS ; }static inline int rproc_dev_init (int id) {return -ENOSYS ; }
@@ -169,6 +190,12 @@ static inline int rproc_stop(int id) { return -ENOSYS; }static inline int rproc_reset (int id) {return -ENOSYS ; }static inline int rproc_ping (int id) {return -ENOSYS ; }static inline int rproc_is_running (int id) {return -ENOSYS ; } +static inline bool rproc_elf_is_valid (unsigned long addr, +int size) {return -ENOSYS ; } +static inline int rproc_elf_sanity_check (ulong addr, +ulong size) {return -ENOSYS ; } +static inline int rproc_elf_load_image (struct udevice *dev, +unsigned long addr) {return -ENOSYS ; }#endif #endif /* _RPROC_H_ */
Signature · 1 line
2.7.4
PATCH 4/7 remoteproc: add elf file load support
Hi Fabien,
Quoted 7 lines · Fabien Dessenne
The current implementation supports only binary file load. Add helpers to support ELF format (check validity, sanity check, and load).
Note that since an ELF image is built for the remote processor, the load function uses theda_to_paops to translate the addresses.
Quoted 6 lines
Signed-off-by Loic Pallardy <[email protected]>Signed-off-by Fabien Dessenne <[email protected]>--- drivers/remoteproc/rproc-uclass.c | 128 ++++++++++++++++++++++++++++++++++++++ include/remoteproc.h | 29 ++++++++- 2 files changed, 156 insertions(+), 1 deletion(-)
It doesn't look like we can easily make use of the existing ELF loader.
But please add a test for this in test/dm/remoteproc.c and see below.
Quoted 40 lines
drivers/remoteproc/rproc-uclass.c +24
-0@@ -5,6 +5,7 @@*/ #define pr_fmt (fmt) "%s: " fmt, __func__#include <common.h> +#include <elf.h> #include <errno.h> #include <fdtdec.h> #include <malloc.h> @@ -291,6 +292,133 @@ int rproc_dev_init(int id)return ret; } +/* +* Determine if a valid ELF image exists at the given memory location. +* First look at the ELF header magic field, then make sure that it is +* executable. +*/ +bool rproc_elf_is_valid (unsigned long addr,int size) +{ +Elf32_Ehdr *ehdr;/* Elf header structure pointer */ + + ehdr = (Elf32_Ehdr *)addr; + +if (!IS_ELF (*ehdr) || size <=sizeof (Elf32_Ehdr)) { +pr_err ("No elf image at address 0x%08lx\n" , addr); +return false; + } + +if (ehdr->e_type !=ET_EXEC ) { +pr_err ("Not a 32-bit elf image at address 0x%08lx\n" , addr); +return false; + } + +return true; +}
drivers/remoteproc/rproc-uclass.c int rproc_dev_init(int id) · line 327
Quoted 10 lines
drivers/remoteproc/rproc-uclass.c +10
-0+ +/* Basic function to verify ELF image format */ +int rproc_elf_sanity_check (ulong addr,ulong size) +{ +Elf32_Ehdr *ehdr; +char class; + +if (!addr) { +pr_err ("Invalid fw address?\n" ); +return -EINVAL ;
EFAULT ?
drivers/remoteproc/rproc-uclass.c int rproc_dev_init(int id) · line 332
Quoted 5 lines
drivers/remoteproc/rproc-uclass.c +5
-0+ } + +if (size <sizeof (Elf32_Ehdr)) { +pr_err ("Image is too small\n" ); +return -EINVAL ;
ENOSPC?
drivers/remoteproc/rproc-uclass.c int rproc_dev_init(int id) · line 341
Quoted 9 lines
drivers/remoteproc/rproc-uclass.c +9
-0+ } + + ehdr = (Elf32_Ehdr *)addr; + +/* We only support ELF32 at this point */ + class = ehdr->e_ident[EI_CLASS ]; +if (class !=ELFCLASS32 ) { +pr_err ("Unsupported class: %d\n" , class); +return -EINVAL ;
EPROTONOSUPP?
Quoted 5 lines
drivers/remoteproc/rproc-uclass.c +5
-0+ } + +/* We assume the firmware has the same endianness as the host */ +# ifdef __LITTLE_ENDIAN +if (ehdr->e_ident[EI_DATA ] !=ELFDATA2LSB ) {
drivers/remoteproc/rproc-uclass.c int rproc_dev_init(int id) · line 356
Quoted 10 lines
drivers/remoteproc/rproc-uclass.c +10
-0+# else /* BIG ENDIAN */ +if (ehdr->e_ident[EI_DATA ] !=ELFDATA2MSB ) { +# endif +pr_err ("Unsupported firmware endianness\n" ); +return -EINVAL ; + } + +if (size < ehdr->e_shoff +sizeof (Elf32_Shdr)) { +pr_err ("Image is too small\n" ); +return -EINVAL ;
ESPC
drivers/remoteproc/rproc-uclass.c int rproc_dev_init(int id) · line 361
Quoted 5 lines
drivers/remoteproc/rproc-uclass.c +5
-0+ } + +if (memcmp (ehdr->e_ident,ELFMAG ,SELFMAG )) { +pr_err ("Image is corrupted (bad magic)\n" ); +return -EINVAL ;
EBADF
Quoted 5 lines
drivers/remoteproc/rproc-uclass.c +5
-0+ } + +if (ehdr->e_phnum ==0 ) { +pr_err ("No loadable segments\n" ); +return -EINVAL ;
drivers/remoteproc/rproc-uclass.c int rproc_dev_init(int id) · line 376
Quoted 10 lines
drivers/remoteproc/rproc-uclass.c +10
-0+ } + +if (ehdr->e_phoff > size) { +pr_err ("Firmware size is too small\n" ); +return -EINVAL ; + } + +return 0 ; +} +
They are just suggestions, but please try to return useful numbers. In general it should be possible to see what went wrong without needing to output text.
Quoted 6 lines
drivers/remoteproc/rproc-uclass.c +6
-0+/* A very simple elf loader, assumes the image is valid */ +int rproc_elf_load_image (struct udevice *dev,unsigned long addr) +{ +Elf32_Ehdr *ehdr;/* Elf header structure pointer */ +Elf32_Phdr *phdr;/* Program header structure pointer */ +const struct dm_rproc_ops *ops;
drivers/remoteproc/rproc-uclass.c int rproc_dev_init(int id) · line 392
Quoted 10 lines
drivers/remoteproc/rproc-uclass.c +10
-0+unsigned int i; + + ehdr = (Elf32_Ehdr *)addr; + phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff); + + ops =rproc_get_ops (dev); +if (!ops) { +dev_dbg (dev,"Driver has no ops?\n" ); +return -EINVAL ; + }
This is not allowed, so you don't need to check for it.
Quoted 46 lines
drivers/remoteproc/rproc-uclass.c +29
-0+ +/* Load each program header */ +for (i =0 ; i < ehdr->e_phnum; ++i) { +void *dst = (void *)(uintptr_t )phdr->p_paddr; +void *src = (void *)addr + phdr->p_offset; + +if (phdr->p_type !=PT_LOAD ) +continue ; + +if (ops->da_to_pa) + dst = (void *)ops->da_to_pa (dev, (ulong )dst); + +dev_dbg (dev,"Loading phdr %i to 0x%p (%i bytes)\n" , + i, dst, phdr->p_filesz); +if (phdr->p_filesz) +memcpy (dst, src, phdr->p_filesz); +if (phdr->p_filesz != phdr->p_memsz) +memset (dst + phdr->p_filesz,0x00 , + phdr->p_memsz - phdr->p_filesz); +flush_cache (rounddown ((unsigned long )dst,ARCH_DMA_MINALIGN ), +roundup ((unsigned long )dst + phdr->p_filesz, +ARCH_DMA_MINALIGN ) - +rounddown ((unsigned long )dst,ARCH_DMA_MINALIGN )); + ++phdr; + } + +return 0 ; +} +int rproc_load (int id,ulong addr,ulong size) {struct udevice *dev =NULL ;include/remoteproc.h +1
-1@@ -104,7 +104,7 @@ int rproc_dev_init(int id);bool rproc_is_initialized (void );/** -* rproc_load() - load binary to a remote processor +* rproc_load() - load binary or elf to a remote processor * @id: id of the remote processor * @addr: address in memory where the binary image is located * @size: size of the binary image
include/remoteproc.h int rproc_ping(int id); · line 159
Quoted 1 line
include/remoteproc.h +0
-0@@ -159,6 +159,27 @@ int rproc_ping(int id);* Return: 0 if all ok, else appropriate error value.
What does ok mean? Running?
include/remoteproc.h int rproc_ping(int id); · line 164
Quoted 5 lines
include/remoteproc.h +3
-0*/ int rproc_is_running (int id); + +/** +* rproc_elf_is_valid() - check if an image is a valid ELF one
In what sense?
include/remoteproc.h int rproc_ping(int id); · line 165
Quoted 1 line
include/remoteproc.h +1
-0+* @addr: image address
Is this address in the remote space?
In general your comments are a bit brief
include/remoteproc.h int rproc_ping(int id); · line 166
Quoted 1 line
include/remoteproc.h +1
-0+* @size: image size
@return - also please use an int return (e.g. 0 is valid and -ve error means not). You could rename to rproc_elf_check_valid()
include/remoteproc.h int rproc_ping(int id); · line 171
Quoted 5 lines
include/remoteproc.h +5
-0+*/ +bool rproc_elf_is_valid (unsigned long addr,int size); + +/** +* rproc_elf_sanity_check() - verify an ELF image format
What is different about this from the above functions?
include/remoteproc.h int rproc_ping(int id); · line 180
Quoted 9 lines
include/remoteproc.h +9
-0+* @addr: ELF image address +* @size: ELF image size +*/ +int rproc_elf_sanity_check (ulong addr,ulong size); + +/** +* rproc_elf_load_image() - load an ELF image +* @dev: device loading the ELF image +* @addr: valid ELF image address
@return
Quoted 19 lines
include/remoteproc.h +8
-1+*/ +int rproc_elf_load_image (struct udevice *dev,unsigned long addr);#else static inline int rproc_init (void ) {return -ENOSYS ; }static inline int rproc_dev_init (int id) {return -ENOSYS ; }@@ -169,6 +190,12 @@ static inline int rproc_stop(int id) { return -ENOSYS; }static inline int rproc_reset (int id) {return -ENOSYS ; }static inline int rproc_ping (int id) {return -ENOSYS ; }static inline int rproc_is_running (int id) {return -ENOSYS ; } +static inline bool rproc_elf_is_valid (unsigned long addr, +int size) {return -ENOSYS ; } +static inline int rproc_elf_sanity_check (ulong addr, +ulong size) {return -ENOSYS ; } +static inline int rproc_elf_load_image (struct udevice *dev, +unsigned long addr) {return -ENOSYS ; }#endif #endif /* _RPROC_H_ */ --
Quoted 2 lines
2.7.4
Regards,
Simon
PATCH 5/7 remoteproc: Introduce STM32 Cortex-M4 remoteproc driver
In reply to Fabien DessenneThis patch introduces support of Cortex-M4 remote processor for STM32 MCU and MPU families.
--- drivers/remoteproc/Kconfig | 10 ++ drivers/remoteproc/Makefile | 1 + drivers/remoteproc/stm32_copro.c | 257 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 268 insertions(+) create mode 100644 drivers/remoteproc/stm32_copro.c
drivers/remoteproc/Kconfig +10 -0
@@ -40,6 +40,16 @@ config REMOTEPROC_SANDBOX Say 'y' here to add support for test processor which does dummy operations for sandbox platform. +config REMOTEPROC_STM32_COPRO + bool "Support for STM32 coprocessor" + select REMOTEPROC + depends on DM + depends on ARCH_STM32MP + depends on OF_CONTROL + help + Say 'y' here to add support for STM32 Cortex-M4 coprocessors via the + remoteproc framework. + config REMOTEPROC_TI_POWER bool "Support for TI Power processor" select REMOTEPROC
drivers/remoteproc/Makefile +1 -0
@@ -10,4 +10,5 @@ obj-$(CONFIG_$(SPL_)REMOTEPROC) += rproc-uclass.o obj-$(CONFIG_K3_SYSTEM_CONTROLLER) += k3_system_controller.o obj-$(CONFIG_REMOTEPROC_K3) += k3_rproc.o obj-$(CONFIG_REMOTEPROC_SANDBOX) += sandbox_testproc.o +obj-$(CONFIG_REMOTEPROC_STM32_COPRO) += stm32_copro.o obj-$(CONFIG_REMOTEPROC_TI_POWER) += ti_power_proc.o
drivers/remoteproc/stm32_copro.c new file +257 -0
257 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 6/7 MAINTAINERS: Add stm32 remoteproc driver
In reply to Fabien Dessenne--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -309,6 +309,7 @@ F: drivers/power/pmic/stpmic1.c F: drivers/power/regulator/stm32-vrefbuf.c F: drivers/power/regulator/stpmic1.c F: drivers/ram/stm32mp1/ +F: drivers/remoteproc/stm32_copro.c F: drivers/misc/stm32_rcc.c F: drivers/reset/stm32-reset.c F: drivers/spi/stm32_qspi.c
Signature · 1 line
2.7.4
PATCH 7/7 configs: stm32mp15: enable stm32 remoteproc
In reply to Fabien DessenneActivate the remote processor support for stm32mp15 configs.
--- configs/stm32mp15_basic_defconfig | 2 ++ configs/stm32mp15_trusted_defconfig | 2 ++ 2 files changed, 4 insertions(+)
configs/stm32mp15_basic_defconfig +2 -0
@@ -67,6 +67,8 @@ CONFIG_DM_REGULATOR_FIXED=y CONFIG_DM_REGULATOR_GPIO=y CONFIG_DM_REGULATOR_STM32_VREFBUF=y CONFIG_DM_REGULATOR_STPMIC1=y +CONFIG_REMOTEPROC=y +CONFIG_REMOTEPROC_STM32_COPRO=y CONFIG_SERIAL_RX_BUFFER=y CONFIG_STM32_SERIAL=y CONFIG_USB=y
configs/stm32mp15_trusted_defconfig +2 -0
@@ -57,6 +57,8 @@ CONFIG_DM_REGULATOR_FIXED=y CONFIG_DM_REGULATOR_GPIO=y CONFIG_DM_REGULATOR_STM32_VREFBUF=y CONFIG_DM_REGULATOR_STPMIC1=y +CONFIG_REMOTEPROC=y +CONFIG_REMOTEPROC_STM32_COPRO=y CONFIG_SERIAL_RX_BUFFER=y CONFIG_STM32_SERIAL=y CONFIG_USB=y
Signature · 1 line
2.7.4