How to Load Compiled Binaries into Cortex-M
Introduction​
This article's goal is to guide you in the process of loading and running binaries compiled with NXP's SDK (Software Development Kit) into the Cortex-M. Although there are several ways to do this, this article will cover only one method, described in the next sections.
This article complies with the typographic conventions.
Typographic Conventions
Throughout the Toradex documentation, the following typographic conventions are used:
$ (dollar sign) Command in the host computer (e.g. your PC)
$ Command in your PC
$$ (double dollar sign) Command in a container in the host computer (e.g. your PC)
$$ Command inside a container in your PC
# (hashtag) Command in the target device/board (e.g. Linux terminal)
# Command in the target board, e.g. Colibri iMX6
## (double hashtag) Command inside a container in the target device (Torizon)
## Command inside a container in Torizon
> (greater-than sign) Command in the bootloader (e.g. U-Boot console)
> Command in the Bootloader
No symbol: Command output
$ Command waiting for output
Output
Prerequisites​
- A module running Torizon OS or Linux BSP
- A terminal connected to the U-Boot Console
- The firmware to run on the Cortex M (see NXP's SDK)
EXT4LOAD Loading Method​
Follow the next steps to load the binary from the eMMC where the OS Image is, using EXT4LOAD in the U-Boot terminal.
If you're using the a Toradex Embedded Linux image, place the .bin
file in any system's directory (at /home
folder, for example). If you're using Torizon OS, it is recommended to place the .bin
in a folder not managed by OSTree, which are /home
or /var
. Refer to OSTree for more information.
If you're using Torizon OS and you placed your binary inside /var
folder, it will be inside /ostree/deploy/torizon/var/
from an U-Boot point of view.
- Apalis iMX8 / Colibri iMX8X
- Colibri iMX7D 1GB
- Colibri iMX7D/S 512MB/256MB
- Verdin iMX8M Mini
- Verdin iMX8M Plus
Copy the binary to your embedded Linux OS using a SD Card, USB drive, SCP command, or any other method you want.
Identify the firmware path from the U-Boot point of view using the
ext4ls
command, usingext4ls mmc 0:1
for Torizon OS, and
ext4ls mmc 0:2
command for Linux BSP.Set up the loading command (
load_cmd
) with theext4load
command. As the loading procedure may be slightly different accordingly to the SoM, select it from the tabs below and follow the instructions:
For these modules, U-Boot already has some useful aliases that you will use to load the binary:
> printenv m4boot_0
m4boot_0=run loadm4image_0; dcache flush; bootaux ${loadaddr} 0
> printenv m4boot_1
m4boot_1=run loadm4image_1; dcache flush; bootaux ${loadaddr} 1
- To load the image, set the loading method with
load_cmd
.
Make sure to use the right device and partition, as explained in the step 2.
> setenv load_cmd "ext4load mmc 0:1"
> setenv load_cmd "ext4load mmc 0:2"
- Use
m4_0_image
to set the full path for your binary. If you're using Torizon OS, for example, it should be like this:
> setenv m4_0_image "/ostree/deploy/torizon/var/hello_world_m40.bin"
- Update the
loadm4image_0
alias to use the new command and image.
> setenv loadm4image_0=${load_cmd} ${loadaddr} ${m4_0_image}
- Save the modifications and boot:
> saveenv
If you're on Apalis iMX8, you can do the same steps using m4_1_image and m4boot_1 to use the second Cortex-M core.
Copy the binary to your embedded Linux OS using a SD Card, USB drive, SCP command, or any other method you want.
Identify the firmware path from the U-Boot point of view using the
ext4ls
command, usingext4ls mmc 0:1
for Torizon OS, and
ext4ls mmc 0:2
command for Linux BSP.Set up the loading command (
load_cmd
) with theext4load
command. As the loading procedure may be slightly different accordingly to the SoM, select it from the tabs below and follow the instructions:
For Colibri iMX7 you only have two aliases already set on U-Boot. So you will have to create and set some aliases to make things easier.
# printenv m4boot
m4boot=;
# printenv loadaddr
loadaddr=0x80800000
- To load the image, set the loading method with
load_cmd
.
Make sure to use the right device and partition, as explained in the step 2.
> setenv load_cmd "ext4load mmc 0:1"
> setenv load_cmd "ext4load mmc 0:2"
- Use
m4_0_image
to set the full path for your binary. If you're using Torizon OS, for example, it should be like this:
> setenv m4image "/ostree/deploy/torizon/var/hello_world.bin"
- Now, set the rest of the commands:
> setenv loadm4image "${load_cmd} ${loadaddr} ${m4image}"
> setenv m4boot "${loadm4image}; dcache flush; bootaux ${loadaddr}"
- Save the modifications and boot:
> saveenv
Copy the binary to your embedded Linux OS using a SD Card, USB drive, SCP command, or any other method you want.
Identify the firmware path from the U-Boot point of view using the
ext4ls
command, usingext4ls mmc 0:1
for Torizon OS, and
ext4ls mmc 0:2
command for Linux BSP.Set up the loading command (
load_cmd
) with theext4load
command. As the loading procedure may be slightly different accordingly to the SoM, select it from the tabs below and follow the instructions:
Since U-Boot don't have the necessary aliases and it isn't allowed to copy the binary to the right Cortex-M address, the process is more complicated. Before loading the binaries to Cortex-M, you will need to copy the binary and then move it to another location.
- To load the image, set the loading method with
load_cmd
.
Make sure to use the right device and partition, as explained in the step 2.
> setenv load_cmd "ext4load mmc 0:1"
> setenv load_cmd "ext4load mmc 0:2"
- Set the full path for the binary. If you're using Torizon OS, for example, it should be like this:
> setenv cm_image "/ostree/deploy/torizon/var/hello_world.bin"
- Create and set an alias for the Cortex-M4 instruction cache size (
cm_isize
) of 16kB. The value should be in hexadecimal (10000h
):
> setenv cm_isize 10000
- Set the rest of the commands:
> setenv load_cm_image "${load_cmd} ${loadaddr} ${cm_image}"
> setenv cm_boot "${load_cm_image}; cp.b ${loadaddr} 0x7e0000 ${cm_isize}; dcache flush; bootaux 0x7e0000"
- Save the modifications and boot:
> saveenv
Copy the binary to your embedded Linux OS using a SD Card, USB drive, SCP command, or any other method you want.
Identify the firmware path from the U-Boot point of view using the
ext4ls
command, usingext4ls mmc 2:1
for Torizon OS, and
ext4ls mmc 2:2
command for Linux BSP.Set up the loading command (
load_cmd
) with theext4load
command. As the loading procedure may be slightly different accordingly to the SoM, select it from the tabs below and follow the instructions:
Since U-Boot don't have the necessary aliases and it isn't allowed to copy the binary to the right Cortex-M address, the process is more complicated. Before loading the binaries to Cortex-M, you will need to copy the binary and then move it to another location.
- To load the image, set the loading method with
load_cmd
.
Make sure to use the right device and partition, as explained in the step 2.
> setenv load_cmd "ext4load mmc 2:1"
> setenv load_cmd "ext4load mmc 2:2"
- Set the full path for the binary. If you're using Torizon OS, for example, it should be like this:
> setenv cm_image "/ostree/deploy/torizon/var/hello_world.bin"
- Create and set an alias for the Cortex-M7 instruction cache size (
cm_isize
) of 32kB. The value should be in hexadecimal (20000h
):
> setenv cm_isize 20000
- Set the rest of the commands:
> setenv load_cm_image "${load_cmd} ${loadaddr} ${cm_image}"
> setenv cm_boot "${load_cm_image}; cp.b ${loadaddr} 0x7e0000 ${cm_isize}; dcache flush; mw.w 0x550ff000 0 64;bootaux 0x7e0000"
- Save the modifications and boot:
> saveenv
Application Start​
To run the application, search for your module at the tabs below and follow the process:
- Apalis iMX8 / Colibri iMX8X
- Colibri iMX7D 1GB
- Colibri iMX7D/S 512MB/256MB
- Verdin iMX8M Mini
- Verdin iMX8M Plus
To start the application, after you save the modifications at a boot level just run the m4boot_0
and the Cortex-M will start running.
> run m4boot_0
To run it automatically with the boot process, i.e. without need to repeat all the description, add the m4boot_0
to the “bootcmd” alias. Do it by running:
> setenv bootcmd "run m4boot_0; ${bootcmd}"
> saveenv
> reset
If you're on Apalis iMX8 and using the second Cortex-M core, just replace the m4boot_0
above with m4boot_1
.
To start the application, after you save the modifications at a boot level just run the m4boot
and the Cortex-M will start running.
> run m4boot
To run it automatically with the boot process, i.e. without need to repeat all the description, add the m4boot
to the “bootcmd” alias. Do it by running:
> setenv bootcmd "run m4boot; ${bootcmd}"
> saveenv
> reset
To start the application, after you save the modifications at a boot level just run the cm_boot
and the Cortex-M will start running.
> run cm_boot
To run it automatically with the boot process, i.e. without need to repeat all the description, add the cm_boot
to the bootcmd
alias. Do it by running:
> setenv bootcmd "run cm_boot; ${bootcmd}"
> saveenv
> reset
To start the application, after you save the modifications at a boot level just run the cm_boot
and the Cortex-M will start running.
> run cm_boot
To run it automatically with the boot process, i.e. without need to repeat all the description, add the cm_boot
to the bootcmd
alias. Do it by running:
> setenv bootcmd "run cm_boot; ${bootcmd}"
> saveenv
> reset