i.MX RT ROM bootloader provides a wealth of options to enable user programs to start in various ways. In some cases, people want to copy application image from Flash or other storage device to SDRAM and run there. In this article, I record three ways to realize this. Section 2 and 3 shows load image from NOR flash. Section 4 shows load image from SD card.
Software and Tools:
MCUXpresso IDE v11.1
RT1060 SDK v2.7.0
- Add DCD by MCUxpresso IDE
If customers use MCUXpresso to develop the project, they can add DCD head by MCUXpresso.
To show the work flow, we take evkmimxrt1020_iled_blinky as the example.
Step 1: Add the following to Compiler options:
Step 2: Modify the Memory Configuration
Step 3: Select link application to RAM
Step 4. Compile the project. MCUXpresso will generate linker script automatically.
Step 5. Since the code should be linked to RAM, MCUXpresso will not prefix IVT and DCD. We can add these link information to linker script manually. Add below code to .ld file’s head.
.boot_hdr : ALIGN(4)
__boot_hdr_start__ = ABSOLUTE(.) ;
. = 0x1000 ;
. = 0x1020 ;
. = 0x1030 ;
__boot_hdr_end__ = ABSOLUTE(.) ;
. = 0x2000 ;
Then deselect “Manage linker script” in last screenshot.
Step 6. Recompile the project, IVT/DCD/BOOT_DATA will be add to your project. Then right click the project axf file->Binary Utilities->Create S-record.
After all these step, you can open MCUBootUtility and download the .s19 file to NOR flash.
- Add DCD by MCUBootUtility
We can also keep the linker script managed by IDE. MCUBootUtility can add head too. Sometimes it is more flexible than other manners.
Step 1. This time BOARD_SDRAM location should be changed to 0x80002000 while the size should be 0x1cff000. This is because the start 8k space in bootable image is saved for IVT and DCD.
Step 2. compile the project and generate the .s19 file.
Step 3. Open MCUBootUtility. In MCUBootUtility, we should first set the Device Configuration Data. Here I use MIMXRT1060_EVK. So I select the DCD bin file in NXP-MCUBootUtility-2.2.0\src\targets\MIMXRT1062.
After that, select the application image file and click All-in-one Action button. MCUBootUtility can do all the work without any manual operation.
- Boot from SD card to SDRAM
In some application, customer don’t want XIP. They want to use SD card to keep application image and run the code in RAM. But if the code size is bigger than OCRAM size, they have to copy image into SDRAM when startup.
With MCUBootUtility’s help, this work is very easy too. User just need to change the memory map which is located to 0x80001000.
In MCUBootUtility, select the Boot Device to “uSDHC SD” and insert SD card. Then connect the target board. If RT1060 can read the SD card, it will display the SD card information. Then same as last section, set the DCD file and application image file.
Click the All-in-One Action button, MCUBootUtility will generate the bootable image and write it to SD card.
SD card has huge capacity. It's too wasteful to only store boot image. People may ask that can they also create a FAT32 system and store more data file in it? Yes, but you need tool's help. When booting from SD card, ROM code read IVT and DCD from SD card address 0x400. To FAT32, the first 512 bytes in SD is for MBR(MAIN BOOT RECORD). Data in address 0x1c6 in MBR reords the partition start address. If the space from MBR to partition start address is big enough to store boot image, then FAT32 system and boot image can live in peace.
- To help Boot ROM initialize SDRAM, DCD must be placed at right place and indexed by IVT correctly. When our code seems not work, we should first check IVT and DCD.
- The IVT offset from the base address for each boot device type is defined in the table below. The location of the IVT is the only fixed requirement by the ROM. The remainder or the image memory map is flexible and is determined by the contents of the IVT.