Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Booting the NXP i.MX RT From a Micro SD Card

DZone 's Guide to

Booting the NXP i.MX RT From a Micro SD Card

While it's common to boot a Linux system from a micro SD card, microcontrollers are a different story.

· IoT Zone ·
Free Resource

It is a common thing to boot a Linux system (see the Raspberry Pi) from a micro SD card. It is not that common for a microcontroller. The NXP i.MX RT ARM Cortex-M7 fills the gap between these two worlds. It's no surprise that it features a ROM bootloader, which can boot from a micro SD card.

SD Card with i.MX RT1052

SD Card with i.MX RT1052

Booting from an SD card is kind of cool: load new software to the card, insert it, and boot from it. In some applications, this can be very useful: in my configuration, the processor starts the ROM bootloader, then loads the image from the SD card into RAM and runs it. In that configuration, no internal or external FLASH memory would be needed.

Software and Tools

For this article, I have used the following software and tools:

For an overview of the board, have a read at “MCUXpresso IDE V10.1.0 with i.MX RT1052 Crossover Processor." The latest IDE is described in “New NXP MCUXpresso IDE V10.3.0 Release." I highly recommend using the EVKB (see a comparison with the EVK: “i.MX RT1050 EVK vs. EVKB“).

Creating Project

To verify if loading works as expected, I prefer to create a ‘blinky’ project, which blinks an LED: that’s simple and does not need much.

Because the bootloader on the i.MX RT will load the application into RAM space, I make sure that my project is linked to RAM. An easy way is to specify this during project creation/import:

link to ram

link to ram

The RAM setting is reflected in the project settings:

link application to ram in linker settings

link application to ram in linker settings

In the next step, I need to change the memory map, which is located here in the project settings:

original memory map

original memory map

The bootloader needs some part of the lower end of ITC SRAM, so I have to free up 0x2000 in size.

Note that the NXP documentation uses 0xa000 as the application vector and start address. I was not able to get it working with that address, what worked for me was this 0x2000 address.

I used the ‘Split’ button on the original SRAM_ITC, changed the Location to 0x2000, and reduced the size by 0x2000, too. Finally, we have that lower 0x0-0x2000 RAM area I moved to the bottom (just that I have it still listed). The most important thing is to move that SRAM_ITC with the 0x2000 start address to the beginning of the list: that way, the linker script will place the vector table there. The goal is to have the vector table at that defined address. Below is a screenshot of what it should look like:

changed ram memory map

changed ram memory map

S19 File

The next thing is to configure the MCUXpresso project to generate an S19 (S-Record) file, as this will be needed in a future step. For more info, see this article

So, add this to the project settings and post-build step:

arm-none-eabi-size "${BuildArtifactFileName}"
arm-none-eabi-objcopy -v -O srec "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.s19"

post build step to generate s19 file

post build step to generate s19 file

Build the project, and the S19 file should be generated:

s19 file

s19 file

Test Debug Run

Now, it is a good time to build and debug that project just to make sure it runs: use the MCUXpresso IDE and download the application. I’m using the XiP (External Flash eXecute in Place) boot setting:

xip boot configuration

xip boot configuration

Then, check if everything works correctly:

executing in ram

executing in ram

Watch the LED blinking and you know you reached the ‘blinky’ point already. 

Creating SD Card Boot Image

To boot with the application from the SD card, I have to transform the .s19 into a special format. There are different bootable images, from unsecured sign up to a secure boot image. To keep things simple, I go with an ‘unsecured’ one.

For this, I need the ‘Flashloader’ utility, which I have installed in the following directory:

C:\nxp\Flashloader_i.MXRT1050


Additionally, my ‘blinky’ application is located in this folder:

C:\Users\Erich Styger\Data\GitRepos\McuOnEclipse\Examples\MCUXpresso\i.MX RT1050_EVK\MIMXRT1052_blinky_in_RAM

flashloader installation folder

flashloader installation folder

The first thing to open is the following file in an editor:

C:\nxp\Flashloader_i.MXRT1050\Tools\bd_file\imx10xx\imx-itccm-unsigned.bd


And then, you need to check that it has the following values/content of the .bd configuration file:

options {
    flags = 0x00;
    # Note: This is an example address, it can be any non-zero address in ITCM region
    startAddress = 0x1000;
    ivtOffset = 0x400;
    initialLoadSize = 0x2000;
    # Note: This is required if the default entrypoint is not the Reset_Handler 
    #       Please set the entryPointAddress to Reset_Handler address 
    entryPointAddress = 0x00002000;
}

sources {
    elfFile = extern(0);
}

section (0)
{
}

Note that the NXP default and documentation lists 0x8000 as the ‘startAddress’. I had to change it to 0x1000 to make it work!

Start a DOS shell and ‘cd’ into the following folder:

C:\nxp\Flashloader_i.MXRT1050\Tools\elftosb\win

dos shell

dos shell

Next, copy s19 file to that elftosb folder: C:\nxp\McuBootUtility\Flashloader_i.MXRT1050_GA\Tools\elftosb\win>

copy "C:\Users\Erich Styger\Data\GitRepos\McuOnEclipse\Examples\MCUXpresso\i.MX RT1050_EVK\MIMXRT1052_blinky_in_RAM\Debug\evkbimxrt1050_iled_blinky_in_RAM.s19" .

copied .s19 file

copied .s19 file

Next, build a .bin from the .s19 file

elftosb.exe -f imx -V -c ../../bd_file/imx10xx/imx-itcm-unsigned.bd -o application.bin evkbimxrt1050_iled_blinky_in_RAM.s19

bin files generated

bin files generated

This actually creates two files. The ‘padding’ one starts from 0x0000. What we need is the ‘nopadding.bin’ one as this one starts from 0x2000.

In the next step, generate the boot image file boot_image.sb with:

elftosb.exe -f kinetis -V -c ../../bd_file/imx10xx/program_sdcard_image.bd -o  boot_image.sb application_nopadding.bin

created boot image

created boot image

Generate the boot image:

copy boot_image.sb to the “OS Firmware” folder of the mfgtools:

copy boot_image.sb "C:\nxp\Flashloader_i.MXRT1050\Tools\mfgtools-rel\Profiles\MXRT105X\OS Firmware"

copied boot image

copied boot image

Verify the content of the following file:

C:\nxp\Flashloader_i.MXRT1050\Tools\mfgtools-rel\cfg.ini


It should have this:

[profiles]

chip = MXRT105X

[platform]

board = 

[LIST]

name = MXRT105X-DevBoot


Set the SW07 switch to boot the board in Serial Download mode:

SW07: 1-OFF, 2-OFF, 3-OFF, 4-ON

serial downloader mode

serial downloader mode

I’m powering the board with the USB cable on the OpenSDA USB connector. So, for this, I have to put the jumper near SW1 to the middle position:

powering board through opensda

powering board through opensda

Power the board first with the debug USB port (black cable below on the right), then plug in the USB cable for the Serial Downloader (white/blue cable on the bottom below):

board in serial download mode

board in serial download mode

Next, launch the following tool

C:\nxp\McuBootUtility\Flashloader_i.MXRT1050_GA\Tools\mfgtools-rel\MgTool2.exe


It should show like this, if connected to the Serial Loader:

connected mfg tool

connected mfg tool

Press the ‘Start’ Button, and it should write the boot image to the SD card:

started

started

Then, press Stop followed by Exit to close the tools.

Now, let's take the final step:

Power off the board and change SW7 to boot from the SD card:

SW07: 1-ON, 2-OFF, 3-ON, 4-OFF

SW7 on i.MXRT1050-EVKB for sd card boot

SW7 on i.MXRT1050-EVKB for sd card boot

Now, enjoy the loaded application from the SD card:

blinky blinky blinky blinky blinky

blinky blinky blinky blinky blinky

Summary

It is possible to boot the i.MX RT from the SD card. The data is stored in ‘raw blocks’ on the card and loaded by the ROM bootloader to the RAM and executed from there. It should be possible from here to program the flash, use a file system on the SD card, and many more things. For now, I’m happy that I have the base with a blinky blinky blinky LED.

Happy Booting!

Links

Topics:
iot ,microcontrollers ,nxp mcuxpresso ide ,nxp mcuxpresso ,tutorial ,sd card ,micro sd card

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}