Skip to main content

How to Load Compiled Binaries into Cortex-M


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


  1. A module running Torizon OS or Linux BSP
  2. A terminal connected to the U-Boot Console
  3. 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.

  1. Copy the binary to your embedded Linux OS using a SD Card, USB drive, SCP command, or any other method you want.

  2. Identify the firmware path from the U-Boot point of view using the ext4ls command, using ext4ls mmc 0:1 for Torizon OS, and
    ext4ls mmc 0:2 command for Linux BSP.

  3. Set up the loading command (load_cmd) with the ext4load 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 loadm4image_0
loadm4image_0=${load_cmd} ${loadaddr} ${m4_0_image}
  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"
  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"
  1. 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.

Application Start

To run the application, search for your module at the tabs below and follow the process:

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.

Send Feedback!