.elf loader for M4 core. How to load an ".elf file"?

I found a loader for “.bin” files in oreder to load a bin file in to M4 TCM memory /OCRAM.

But how to load a .elf in to it?
How to load an “.elf” file instead?


m4fwloader is for binary file. Provided your elf is “single sectioner” (contiguous memory area for text and variable initializers sections), you may convert it from elf to bin with objdump.

1 Like

Thanks edward for your kind reply.
The issue is that indeed, it is not a single section. THe code is larger than 32KB (TCMem) and I must used OCRAM thanks to the code parameter

 __attribute__ ((section (".ocram_text")));

This is why I need to load an .elf file. But I didn’t find yet a proper loader.

Hi @Edge,

Moving all the code to OCRAM could again make your binary m4fwloader friendly.

You should make sure that GCC optimizes away unused code functions. It is not done by default. -ffunction-sections compiler switch makes function placed each to new section, then --gc-sections linker switch allows removing unused sections.

For ELF you should either stick to U-Boot’s bootaux command (the way suggested in Toradex Knowledge Base here) or try Linux remoteproc driver.
Remoteproc seems being not listed in KB. Perhaps this thread may help you. Seach on NXP iMX forums may help as well.

Hi @Edge,

Sorry for the delay.

I created an overlay for you to use the remote proc driver from NXP (imx_rproc.c) with our downstream kernel.
This driver is not enabled by default in our downstream kernel, so in order to use that, the easiest way is to bitbake a new image and add a custom layer with the modified kernel config file.

Please, follow these two guides on how to set up your Yocto environment and also how to customize it with a custom meta-layer:

To make things easier, you can use this custom meta layer that I created here with the necessary kernel config to enable the remote proc: Download - Toradex File Sharing Platform

With the custom image with the imx-rproc enabled, you can add the following overlay to your image:


#include <dt-bindings/clock/imx7d-clock.h>

/ {
	compatible = "toradex,colibri-imx7d",

&{/} {
	imx7d-cm4 {
		compatible = "fsl,imx7d-cm4";
        syscon = <&src>;
		clocks =  <&clks IMX7D_ARM_M4_ROOT_CLK>;
		mbox-names = "tx", "rx", "rxdb", "txdb";
		mboxes = <&mu 0 1
			  &mu 1 1
			  &mu 3 1
			  &mu 2 1>;
		memory-region = <&m4_reserved>;
        status = "okay";

Or you can download it here: Download - Toradex File Sharing Platform (I already compiled it, so you can simply copy it to your /boot/overlays folder and enable it. More information here: Device Tree Overlays (Linux) | Toradex Developer Center)

After that, you can reboot your module and the imx-rproc should be ready:

# dmesg | grep rproc
remoteproc remoteproc0: imx-rproc is available

Copy your .elf file to /lib/firmware and then run the following commands:

# cat /sys/class/remoteproc/remoteproc0/state
# echo hello_world.elf > /sys/class/remoteproc/remoteproc0/firmware
# echo start > /sys/class/remoteproc/remoteproc0/state
[ 7818.651262] remoteproc remoteproc0: powering up imx-rproc
[ 7818.659563] remoteproc remoteproc0: Booting fw image hello_world.elf, size 156628
[ 7818.667654] remoteproc remoteproc0: no dtb rsrc-table
[ 7818.672786] imx-rproc imx7d-cm4: No resource table in elf
[ 7818.728362] remoteproc remoteproc0: remote processor imx-rproc is now up

Now you can control the m4 with the “state” file (starting, stopping…) and point the firmware inside /lib/firmware with the /sys/class/remoteproc/remoteproc0/firmware file.

Please, let me know if all the steps are clear and if you need any help with that.

Also, if you would like to use rpmsg with the remote proc, more modifications will be needed, as pointed out by @Edward in this thread: iMX7D 5.4.x kernel. Launching M4 FW using remoteproc - #23 by Edward

Let me know if you wish to use rpmsg, so we can work out a new device tree and a patch to uboot.

Best Regards,

Hi @Edge,

Did you have time to take a look at this?
If my reply helped you, please mark it as a “Solution” so others can benefit from it as well.

Feel free to ask any questions you might have.

Best Regards,