Skip to main content
Version: 5.0

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 two methods, 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.

info

If you're using Colibri iMX7 512/256 MB NAND, please follow this guide instead FreeRTOS on the Cortex-M4 of a Colibri iMX7.

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

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 TorizonCore, place it inside /var, because OSTree won’t change this folder.

  1. If you use Apalis, Colibri, or Verdin iMX8M Mini, list all files using the ext4ls mmc 0:1 (for TorizonCore) or ext4ls mmc 0:2 command (for Linux BSP) to identify your file path from an uBoot point of view. If you are using Verdin iMX8M Plus, use the command ext4ls mmc 2:1 (for Linux BSP) or ext4ls mmc 2:2 (for Linux BSP) instead.
info

If you’re using TorizonCore and you placed your binary inside /var folder, it will be inside /boot/deploy/torizon/var/ from an uBoot point of view.

  1. 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, uBoot 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.
caution

Make sure to use the right device and partition, as explained in the step 2.

> setenv load_cmd "ext4load mmc 0:1"
  1. Use m4_0_image to set the full path for your binary. If you’re using TorizonCore, 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
info

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
info

If you’re on Apalis iMX8 and using the second Cortex-M core, just replace the m4boot_0 above with m4boot_1.

Send Feedback!