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
Prequisites
To follow the steps described in this article, you must set up the SDK and Toolchain as described in the article Setting Up MCUXpresso SDK and Toolchain for Cortex-M development.
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.
To access the U-Boot terminal, follow the U-Boot guide.
If you're using Colibri iMX7 512/256 MB NAND, please follow this guide instead FreeRTOS on the Cortex-M4 of a Colibri iMX7.
- Copy the binary to your embedded Linux OS using a SD Card, USB drive, SCP command, or any other method you want.
If you’re using the BSP, place the .bin
file in any system's directory (at /home
folder, for example). However, if you’re using Torizon OS, place it inside /var
, because OSTree won’t change this folder.
- If you use Apalis, Colibri, or Verdin iMX8M Mini, list all files using the
ext4ls mmc 0:1
(for Torizon OS) orext4ls mmc 0:2
command (for Linux BSP) to identify your file path from an U-Boot point of view. If you are using Verdin iMX8M Plus, use the commandext4ls mmc 2:1
(for Torizon OS) orext4ls mmc 2:2
(for Linux BSP) instead.
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.
- 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:
- Apalis iMX8 / Colibri iMX8X
- Colibri iMX7D 1GB (eMMC)
- Colibri iMX7D/S 512MB/256MB (NAND)
- Verdin iMX8M Mini / Verdin iMX8M Plus
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 loadm4image_0
loadm4image_0=${load_cmd} ${loadaddr} ${m4_0_image}
- 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"
- 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.bin"
- 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.
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"
- 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
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"
- Set the full path for the binary. If you’re using Torizon OS, for example, it should be like this:
> setenv m4image "/ostree/deploy/torizon/var/hello_world.bin"
- Create and set
m4image_size
alias. It will be responsilble for tracking the size of the binary that we’re using. In case of thehello_world.bin
binary, it has 15KB:
> setenv m4image_size 15000
- Set the rest of the commands:
> setenv loadm4image "${load_cmd} ${loadaddr} ${m4image}"
> setenv m4boot "${loadm4image}; cp.b ${loadaddr} 0x7e0000 ${m4image_size}; dcache flush; 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 (eMMC)
- Colibri iMX7D/S 512MB/256MB (NAND)
- 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 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