Commit 81e39fbd9251bfbef3bc156735e95b67cd7a828f
Committed by
Tom Rini
1 parent
856c0ad413
Exists in
smarc_8mq_lf_v2020.04
and in
9 other branches
remoteproc: elf_loader: Introduce rproc_elf_get_boot_addr() api
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@ti.com>
Showing 3 changed files with 38 additions and 0 deletions Side-by-side Diff
drivers/remoteproc/rproc-elf-loader.c
... | ... | @@ -251,4 +251,28 @@ |
251 | 251 | else |
252 | 252 | return rproc_elf32_load_image(dev, addr, size); |
253 | 253 | } |
254 | + | |
255 | +static ulong rproc_elf32_get_boot_addr(ulong addr) | |
256 | +{ | |
257 | + Elf32_Ehdr *ehdr = (Elf32_Ehdr *)addr; | |
258 | + | |
259 | + return ehdr->e_entry; | |
260 | +} | |
261 | + | |
262 | +static ulong rproc_elf64_get_boot_addr(ulong addr) | |
263 | +{ | |
264 | + Elf64_Ehdr *ehdr = (Elf64_Ehdr *)addr; | |
265 | + | |
266 | + return ehdr->e_entry; | |
267 | +} | |
268 | + | |
269 | +ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr) | |
270 | +{ | |
271 | + Elf32_Ehdr *ehdr = (Elf32_Ehdr *)addr; | |
272 | + | |
273 | + if (ehdr->e_ident[EI_CLASS] == ELFCLASS64) | |
274 | + return rproc_elf64_get_boot_addr(addr); | |
275 | + else | |
276 | + return rproc_elf32_get_boot_addr(addr); | |
277 | +} |
include/remoteproc.h
... | ... | @@ -267,6 +267,16 @@ |
267 | 267 | * @return 0 if the image is successfully loaded, else appropriate error value. |
268 | 268 | */ |
269 | 269 | int rproc_elf_load_image(struct udevice *dev, unsigned long addr, ulong size); |
270 | + | |
271 | +/** | |
272 | + * rproc_elf_get_boot_addr() - Get rproc's boot address. | |
273 | + * @dev: device loading the ELF image | |
274 | + * @addr: valid ELF image address | |
275 | + * | |
276 | + * This function returns the entry point address of the ELF | |
277 | + * image. | |
278 | + */ | |
279 | +ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr); | |
270 | 280 | #else |
271 | 281 | static inline int rproc_init(void) { return -ENOSYS; } |
272 | 282 | static inline int rproc_dev_init(int id) { return -ENOSYS; } |
... | ... | @@ -292,6 +302,8 @@ |
292 | 302 | static inline int rproc_elf_load_image(struct udevice *dev, ulong addr, |
293 | 303 | ulong size) |
294 | 304 | { return -ENOSYS; } |
305 | +static inline ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr) | |
306 | +{ return 0; } | |
295 | 307 | #endif |
296 | 308 | |
297 | 309 | #endif /* _RPROC_H_ */ |
test/dm/remoteproc.c
... | ... | @@ -174,6 +174,8 @@ |
174 | 174 | /* Load firmware in loaded_firmware, and verify it */ |
175 | 175 | ut_assertok(rproc_elf32_load_image(dev, (ulong)valid_elf32, size)); |
176 | 176 | ut_assertok(memcmp(loaded_firmware, valid_elf32, loaded_firmware_size)); |
177 | + ut_asserteq(rproc_elf_get_boot_addr(dev, (unsigned long)valid_elf32), | |
178 | + 0x08000000); | |
177 | 179 | unmap_physmem(loaded_firmware, MAP_NOCACHE); |
178 | 180 | |
179 | 181 | /* Invalid ELF Magic */ |