[U-Boot] [PATCH v2 06/26] remoteproc: elf_loader: Introduce rproc_elf_get_boot_addr() api

Lokesh Vutla lokeshvutla at ti.com
Wed Sep 4 10:31:31 UTC 2019


Introduce rproc_elf_get_boot_addr() that returns the entry point of
the elf file. This api auto detects the 64/32 bit elf file and returns
the boot addr accordingly.

Signed-off-by: Lokesh Vutla <lokeshvutla at ti.com>
---
 drivers/remoteproc/rproc-elf-loader.c | 24 ++++++++++++++++++++++++
 include/remoteproc.h                  | 12 ++++++++++++
 test/dm/remoteproc.c                  |  2 ++
 3 files changed, 38 insertions(+)

diff --git a/drivers/remoteproc/rproc-elf-loader.c b/drivers/remoteproc/rproc-elf-loader.c
index 42a78f4207..b38a226065 100644
--- a/drivers/remoteproc/rproc-elf-loader.c
+++ b/drivers/remoteproc/rproc-elf-loader.c
@@ -251,3 +251,27 @@ int rproc_elf_load_image(struct udevice *dev, ulong addr, ulong size)
 	else
 		return rproc_elf32_load_image(dev, addr, size);
 }
+
+static ulong rproc_elf32_get_boot_addr(ulong addr)
+{
+	Elf32_Ehdr *ehdr = (Elf32_Ehdr *)addr;
+
+	return ehdr->e_entry;
+}
+
+static ulong rproc_elf64_get_boot_addr(ulong addr)
+{
+	Elf64_Ehdr *ehdr = (Elf64_Ehdr *)addr;
+
+	return ehdr->e_entry;
+}
+
+ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr)
+{
+	Elf32_Ehdr *ehdr = (Elf32_Ehdr *)addr;
+
+	if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
+		return rproc_elf64_get_boot_addr(addr);
+	else
+		return rproc_elf32_get_boot_addr(addr);
+}
diff --git a/include/remoteproc.h b/include/remoteproc.h
index 812e0f47c4..046cd9e54e 100644
--- a/include/remoteproc.h
+++ b/include/remoteproc.h
@@ -267,6 +267,16 @@ int rproc_elf64_load_image(struct udevice *dev, ulong addr, ulong size);
  * @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);
+
+/**
+ * rproc_elf_get_boot_addr() - Get rproc's boot address.
+ * @dev:	device loading the ELF image
+ * @addr:	valid ELF image address
+ *
+ * This function returns the entry point address of the ELF
+ * image.
+ */
+ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr);
 #else
 static inline int rproc_init(void) { return -ENOSYS; }
 static inline int rproc_dev_init(int id) { return -ENOSYS; }
@@ -292,6 +302,8 @@ static inline int rproc_elf64_load_image(struct udevice *dev, ulong addr,
 static inline int rproc_elf_load_image(struct udevice *dev, ulong addr,
 				       ulong size)
 { return -ENOSYS; }
+static inline ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr)
+{ return 0; }
 #endif
 
 #endif	/* _RPROC_H_ */
diff --git a/test/dm/remoteproc.c b/test/dm/remoteproc.c
index c77361c8f4..1d9a9b32d5 100644
--- a/test/dm/remoteproc.c
+++ b/test/dm/remoteproc.c
@@ -174,6 +174,8 @@ static int dm_test_remoteproc_elf(struct unit_test_state *uts)
 	/* Load firmware in loaded_firmware, and verify it */
 	ut_assertok(rproc_elf32_load_image(dev, (ulong)valid_elf32, size));
 	ut_assertok(memcmp(loaded_firmware, valid_elf32, loaded_firmware_size));
+	ut_asserteq(rproc_elf_get_boot_addr(dev, (unsigned long)valid_elf32),
+		    0x08000000);
 	unmap_physmem(loaded_firmware, MAP_NOCACHE);
 
 	/* Invalid ELF Magic */
-- 
2.22.0



More information about the U-Boot mailing list