Issue creating bootable image that executes code from ITCM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issue creating bootable image that executes code from ITCM

2,582 Views
MissaelMaciel
Contributor I

Hi,

I'm trying to create a bootable image (from QSPI) that executes code from ITCM. I'm currently able  to create a bootable image that executes code from flash but I have a timing issues: the code seems not to be executing at the same speed in comparission when executing from ITCM (debugging).

I referred to the following link to create the bootable images: https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/Generating-a-Bootable-Image-for-the-RT1050/ta-p/...


It works fine when creating the image executing from flash, but when I tried to create an image that executes from ITCM (using the file imx-itcm-unsigned-dcd.bd ofcourse) the first command that creates the .bin fails letting the bin as 0Bytes (nopadding bin file isn't created either). So I don't know what it is probably happening. My project is configured like this:

MissaelMaciel_0-1616345260550.png

 

MissaelMaciel_1-1616345312114.png

MissaelMaciel_0-1616349428578.png

 

 

 

So I'm putting the code in ITCM when linking the code to RAM and all the data heap and stack is being placed at DTCM (I'm using FreeRTOS whit the Newlib-semihost configuration).

In the guide they say that we have to change the ivtOffset to 0x1000 but the example is for running in DTCM, I don't know if this applies also for running in ITCM. Also the bd file for ITCM has a note telling: 

# Note: This is an example address, it can be any non-zero address in ITCM region

My ITCM memory starts at 0 so I tried so many addresses for this files (even the 0) but the result is always the same, the bin file is always created with 0Bytes.

Is there something I'm missing or is there an extra configuration I need for running from ITCM?

Thank you so much!!

 

 

0 Kudos
15 Replies

2,497 Views
MissaelMaciel
Contributor I

@kerryzhou  Thank you so much for your answer. I imported the blink led example from the SDK, modified the memory map to link the code to ITCM and put the start location at 0x2000 as you recommended but unfortunately the problem is the same. When I used the file  imx-itcm-unsigned.bd with the elftosb.exe -f imx -V -c command, the bin generated is 0KBs. I tried to do it for the DTCM and the result is the same. The project's configuration is this:

MissaelMaciel_0-1616545756905.png

 

MissaelMaciel_1-1616545784618.png

 

Maybe there is something missing I have to configure, other than the memory regions. This process works fine when I use the imx-flexspinor-normal-unsigned.bd when the code is in flash. But in RAM isn't working

0 Kudos

2,489 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi MissaelMaciel,

   Tell me which RT chip and board you are using? NXP MIMXRT board?

   Please also tell me your SDK version, I suggest you use the newest SDK version.

   As I know, in the previous time, I also tested ITCM, it works OK.

   So, now, please let me know your board and SDK information, do you want to use the app to generate the sb file, and use the MFG tool to download it, right?

   After you tell me, then I will generate one code, and make it work, and sent to you.

 

Best Regards,

Kerry

0 Kudos

2,466 Views
MissaelMaciel
Contributor I

Hi @kerryzhou 

I'm using the RT1052DVJ6B. Our board is custom (we are not using the evaluation or development boards). The SDK is the latest available SDK_2.x_MIMXRT1052xxxxB version 2.9.1 and SDK_2.x_EVKB-IMXRT1050 version 2.9.1.

About your question, I'm using the elftosb tool to generate the "xx_nopadding.bin" file (which is the one I'm having issues) and use the mfgtool to download the image. Is there any other way/tool to generate the bootable image?

If it works to you, could you please share the project too see all the configurations? Cause I'm using the sdk examples to create the sb with the elftosb tool and the binary output is always 0bytes.

Thank you so much

0 Kudos

2,454 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi MissaelMaciel,

   Thanks for your updated information.

   If it is your customer board, I think we need to make sure it works at first.

   Do you fanout the debug pins? SWD interface.

    If yes, I highly recommend you use the debugger to check, whether your board can download code, check the external QSPI flash, and boot at first.

    Just make sure the hardware works OK, then you can use the MFGTool to download the code.

    Because, if your hardware have issues, and you use the MFGtool download, you may just see it can't boot, it is not easy to find the root issues.

   Now, please run this sdk code in your internal RAM at first:

SDK_2.9.1_EVKB-IMXRT1050\boards\evkbimxrt1050\driver_examples\flexspi\nor

kerryzhou_0-1617156123670.png

Please run it at first, when you can finish all the qspi flash read, erase, write successfully?

If it can write successfully, then you can download a simple project with debugger, eg, led_blinky, exit the debugger, and run it, whether your gpio can toggle or not?

Please check it at first, any updated information, please kindly let em know.

 

Best Regards,

Kerry

 

 

 

0 Kudos

2,449 Views
MissaelMaciel
Contributor I

Hi @kerryzhou thanks for your quick answer.

I think I had not explained myself well. The issue is not booting. 

When I posted this issue for help I explained that I'm able to create a bootable image, boot from QSPI and run de code from flash. The board works fine and it seems not to have issues.

Since our product is critical, we cannot take the risk of executing code from flash using cache due to memory overruns, that's why whe want to execute code from ITCM.

The main issue is that when using the elftosb tool, I cannot create the "xx_nopadding.bin" because it is always created as 0KB size when I execute this command: elftosb.exe -f imx -V -c ../../bd_file/imx10xx/imx-itcm-unsigned.bd -o evkbimxrt1050_hello_world_itcm.bin evkbimxrt1050_hello_world_itcm.s19

MissaelMaciel_1-1617157825406.png

So the issue is with the tools and no with the HW. I configured the helloworld SDK example to link code to ITCM, I generated the S19 but the elftosb tool fails in the 1st step.

I can debug this project, I can create the bootable image and boot from QSPI with this project when code executes in flash but not when I want to create the image to execute code from ICTM.

Please revisit the very very first post in the thread (when I open de issue) for this details. The issue is with the tools.

Thank you so much,

Missael Maciel

 

0 Kudos

2,439 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi MissaelMaciel,

  Your issue can't generate the ivt_evkbimxrt1050_iled_blinky_0xa000_nopadding.bin, should still related to your image.

  Please follow me and try again, I already make it works on MIMXRT1050-EVKB board with QSPI flash.

  1. your code, take mcuxpresso project as an example, led_blinky.

kerryzhou_0-1617171250093.pngkerryzhou_1-1617171259841.png

kerryzhou_2-1617171270101.png

Then build the project and generate the .s19 file:

kerryzhou_3-1617171323136.png

You will get the evkbimxrt1050_iled_blinky_0xa000.s19.

Check the .s19 image:

kerryzhou_5-1617171411233.png

From 0xa000, it's correct!

 

2.  imx-itcm-unsigned.bd

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

sources {
    elfFile = extern(0);
}

section (0)
{
}

 

entryPointAddress =0x0000a305; is the app entry point, check 0xa000+4 address data in the app image.

4. generate the related files

kerryzhou_6-1617171916862.png

cmd:

./elftosb.exe -f imx -V -c imx-itcm-unsigned.bd -o ivt_evkbimxrt1050_iled_blinky_0xa000.bin evkbimxrt1050_iled_blinky_0xa000.s19

./elftosb.exe -f kinetis -V -c program_flexspinor_image_qspinor.bd -o boot_image.sb ivt_evkbimxrt1050_iled_blinky_0xa000_nopadding.bin

You can find my related file is OK, and get the .sb file

 

5. use MFGTool to download the code

kerryzhou_7-1617171966467.png

So, totally works OK with ITCM.

Please check my attached project and files.

If you still have issues, please use my attached files.

 

Wish it helps you!

Best Regards,

Kerry

 

 

 

 

 

 

 

0 Kudos

2,422 Views
MissaelMaciel
Contributor I

Thank you so much @kerryzhou 

I was able to build and create the bootable image with this guidance. It was very useful.

Two last questions (I promise) previous to solve the thread:

1st - Our application requires to define the ITCM with 256KB of size. The team is concern that if we define the ITCM start address at 0xa000 we may wasting some space in ITCM that we may need in the future or maybe with this start offset the ITCM is not enough for the 256KB. I remember that in your very very first answer you recommended not to start the ITCM at 0x000 address. Is there any reason for that? What would be the best starting address for ITCM so we can configure and use the 256KB?

2nd - I saw that in the imx-itcm-unsigned.db file you configured the startAddress = 0x8000 and I did not see any relation of this value to any configuration in your project (or at least I was not able to track it). Where this number came from? Is this randomly define as the comment says "it can be any non-zero address in ITCM region"? I ran some experiments changing this start address and I found that if I use the start address defined in MCUXPresso for ITCM (0xa000) it is when I have the problem creating the image.

Thank you so much for your kindly support.

Missael Maciel

 

0 Kudos

2,412 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi MissaelMaciel,

   Answer your two questions:

1st - Our application requires to define the ITCM with 256KB of size. The team is concern that if we define the ITCM start address at 0xa000 we may wasting some space in ITCM that we may need in the future or maybe with this start offset the ITCM is not enough for the 256KB. I remember that in your very very first answer you recommended not to start the ITCM at 0x000 address. Is there any reason for that? What would be the best starting address for ITCM so we can configure and use the 256KB?

Answer:In fact, leave 0X2000 is OK, 0xa000 is just an example for you.

No, if you boot from external flash, it is the XIP method, you must leave 0x2000, first 0X1000 is used for FCBD, from 0x1000 is IVT, DCD, then above 0x2000 can put the app. This is the boot requirement.

But because of the bd file need: startAddress is non-zero address.

# Note: This is an example address, it can be any non-zero address in ITCM region

Then, I think you also can use app start address above from 0x3000.

I don't know why you need to put all your code in the internal TCM, in fact, you can put part of the code which must run in the internal RAM, other code still can in the external flash.

2nd - I saw that in the imx-itcm-unsigned.db file you configured the startAddress = 0x8000 and I did not see any relation of this value to any configuration in your project (or at least I was not able to track it). Where this number came from? Is this randomly define as the comment says "it can be any non-zero address in ITCM region"? I ran some experiments changing this start address and I found that if I use the start address defined in MCUXPresso for ITCM (0xa000) it is when I have the problem creating the image.

Answer:  0X8000 is the FCBD start area, then 0X8000+0X1000 is IVT DCD, then 0X8000+0X2000 is 0xa000 which is your app code. the first 0X2000 is used for FCBD and IVT dcd. That's why the startAddress is 0X8000, and my app is 0XA000.

take an example, if you use startaddress is 0X1000, then your app should be 0X3000.

Wish it helps you!

Best Regards,

kerry

0 Kudos

2,408 Views
carlosflr
Contributor II

Hi Kerry,

I'm following this thread. It was not clear to me in your reply to the 1st question if the ITCM can be configured as 256KB in this use case, and, if the initial offset, let's say 0x2000 = 8192, would be subtracted from the ITCM size (leaving 256KB - 8KB = 248KB for code in this example).

Regards,

Carlos Lopez

0 Kudos

2,406 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi carlosflr,

  Read this application note at first:

https://www.nxp.com/docs/en/application-note/AN12077.pdf

Internal ITCM to RT1050 is 128KB in default, not 256KB.

If you want to use 256K, you need to reconfigure the flexRAM:

kerryzhou_0-1617255499533.png

 

I mean, because the start address can't be 0 in the bd, so maybe you need from 0X3000 instead of 0X2000.

But you can try 0X2000 on your side, whether it work OK or not.

Because I find the MCUBootUtility can use the app from 0X2000, so it should works you can try 0X2000 app on your side.

You also can use this tool instead of the MFGtool, it is more easy to use:


https://github.com/JayHeng/NXP-MCUBootUtility/releases/tag/v3.1.1
the related user manual is:
https://github.com/JayHeng/NXP-MCUBootUtility

 

Wish it helps you!

Best Regards,

Kerry

 

Best Regards,

Kerry

 

0 Kudos

2,346 Views
Miguel-Avina
Contributor IV

Hi,

I'm posting this for anyone that get into a similar issue with the i.MXRT family. The issue behind following the AN12077 is that the way to change FlexRAM sizes on Runtime (section 2.1.1.2) can only be achieved if the image to be load into any of FlexRAM sections (ITC in this case) can fit into the default section size (set by the eFuses). For example, in this specific scenario, we created a >128kb bootable intended to be executed in ITC, in that image program we were trying to reconfigure the ITC size to 256kb, so the image could fit on it. The problem behind this rationale is that the code to reconfigure FlexRAM (normally placed in ResetHandler) won't be executed until bootROM copies all the image from FLASH to ITC, and since ITC default value is set to 128kB, then bootROM fails to copy the image.

One solution for this issue is to add the configuration of the FlexRAM in the DCD file. This DCD file will be executed by the BootROM before copying the image from FLASH to ITC. These are the steps to perform this solution:

1. Using MCUXresso Config Tools, open Device Configuration Data (DCD)
2. Choose Output Format: Binary (So we can provide the .bin to elftosb tool, or MCUBootUtility)
2. Add the commands needed to configure FlexRAM. The commmands for a 256kB ITC, 128kB DTC and 128kB OCRAM are shown below:

Capture11.PNG

 

3. Update the Code so MCUXpresso generates the binary.

Now, we just need to add the dcd.bin file to our boot descriptor (.bd) file by adding the following statement:
DCDFilePath = "/dcd/file/path/dcd.bin";

Then, generate the bootable image with the imx and kinetis commands from elftosb and flash it to the devide using mfgtools (or MCUBootUtility).

Now the bootROM will execute the commands from the dcd file and therefore enlarging ITC to 256kb, then it will copy the image to ITC.

2,337 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Miguel-Avina,

   Thanks so much for your experience sharing!

   Perfect!

   If you have any new questions in the future,  welcome to create a new case or the community question post.

 

Best Regards,

Kerry

  

0 Kudos

2,447 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi MissaelMaciel

   Thanks for your feedback and confirmation, clear now!

   I will generate one ITCM file, test it on my MIMXRT1050-EVKB with qspi flash,  and give you all the related files, please keep patient.

 

Best Regards,

Kerry

0 Kudos

2,519 Views
mjbcswitzerland
Specialist V

Hi

Code from ITC will obtain performance improvements of up to 20x than of running code from QSPI so it is worth while doing it when the code and data can fit.

In case of complications the uTasker i.MX RT 1050 boot loader [https://www.utasker.com/iMX/RT1050.html] can be used to control programs that need to operate optimally in internal RAM. It also gives all encrypted OTA and field up loading functions that are needed in most projects. See complete documentation and video guides at https://www.utasker.com/iMX/developers.html

When there is code to run in ITC (either plain code or AES256 encrypted) it is simply loaded with the boot loader to QSPI flash and the boot loader does all the rest of the work. It decrypts it on boot up and relocates it to ITC. It also reconfigures the ITC/DTC banks on-the-fly to optimise the setup to match the code size (allocating as many FlexRAM banks in ITC space as needed by the code and leaving the rest as DTC for variables). Since it is adaptive it achieve the best setup without need to calculate and control FlexRAM mapping in the application code itself (which can change over time), not does it need eFUSE programming (which is one-shot and so can't be changed either).

The result is simplicity for the developer and optional execution speeds without caching. The i.MX RT 1050 will, like this, allow continuous 1 billion instructions execution a second with parallel zero wait state data access.

Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]
Contact me by personal message or on the uTasker web site to discuss professional training, solutions to problems or rapid product development requirements

For professionals searching for faster, problem-free Kinetis and i.MX RT 10xx developments the uTasker project holds the key: https://www.utasker.com/iMX/RT1050.html

0 Kudos

2,525 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi MissaelMaciel,

   You mentioned, you are using:imx-itcm-unsigned-dcd.bd 

   Do you also use the SDRAM? If not, you don't need to use the dcd.

   About the app, I suggest you use the simple project to try your ITCM, eg, the SDK helloworld, led_blinky code. Generate the related ITCM app code, and use the imx-itcm-unsigned.bd, try it again.

imx-itcm-unsigned.bd can be found from the SDK:

SDK_2.9.1_EVKB-IMXRT1050\middleware\mcu-boot\bin\Tools\bd_file\imxrt105x

  BTW, normally, you need to leave some ITCM space for the ITCM, so you can relocate your app from 0Xa000, or 0x2000. You can't just relocate to ITCM 0.

  Your following picture:

kerryzhou_0-1616473455960.png

  location ITCM from 0X2000/0XA000, SIZE: 0X40000-0X2000/0X40000-0XA000

 In your imx-itcm-unsigned.bd:

options {
flags = 0x00;
# Note: This is an example address, it can be any non-zero address in ITCM region
startAddress = 0xa000;
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 = 0x60002411;
}

 

Please try it again.

If you still have questions about it, please kindly let me know.

Best Regards,

Kerry

 

 

 

  

0 Kudos