non-xip example with MCUXpresso

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

non-xip example with MCUXpresso

Jump to solution
6,427 Views
rans
Senior Contributor I

Hello,

Is there any example of non-xip in MCUXpresso ?

It is required for hyperFlash, but any other boot device example can help.

Thank you,

ranran

1 Solution
5,126 Views
Takashi_Kashiwagi
Senior Contributor I

HI ranshalit.

> 1. the binary can be created with objcopy, Right ? (the default compile to axf format)

Yes, I use Post-build steps asfollows. In defult setting, Line of arm-none-eabi-objcopy is comment outed, Please delete '#' and enable arm-none-eabi-objcopy.

post-build-steps.png

> 2. Did you flash the exact binary file size or did you try to calculate its size from the memory map (text+data?) ?

I used the file size of the *. Bin file as it is as u32BinSize. this size is equal to TEXT+DATA.

As follows, Text = 149964, data=3072 and bin file size=153036.

Performing post-build steps
arm-none-eabi-size "IMXRT1060-EVK_APL.axf" ; arm-none-eabi-objcopy -v -O binary "IMXRT1060-EVK_APL.axf" "IMXRT1060-EVK_APL.bin" ; C:/workspace/IMXRT1060-EVK/IMXRT1060-EVK_APL/post-build/crc16.exe -s FFFF -i "IMXRT1060-EVK_APL.bin" -o "IMXRT1060-EVK_APL_crc16.bin" ; # checksum -p MIMXRT1062xxxxA -d "IMXRT1060-EVK_APL.bin"
   text    data     bss     dec     hex filename
 149964    3072 10566376 10719412  a390b4 IMXRT1060-EVK_APL.axf
copy from `IMXRT1060-EVK_APL.axf' [elf32-littlearm] to `IMXRT1060-EVK_APL.bin' [binary]
argc  = 7
[main ( 148)] szInputFile    = <IMXRT1060-EVK_APL.bin>
[main ( 149)] szOutputFile   = <IMXRT1060-EVK_APL_crc16.bin>
[main ( 150)] u16SeedSum     = 0xFFFF
[main ( 151)] u32InputSize   = 153036
[main ( 152)] u16crc16       = 0xFAD5
[main ( 154)] OUTPUT OK        <IMXRT1060-EVK_APL_crc16.bin>
 

> 3. Is ResetISR  equals to DefDST_RAM_TOP+4 in your case ?

Yes. I have used g_pfnVectors. StackTop value and address of ResetISR are allocated as follows.

void (* const g_pfnVectors[])(void) = {
    // Core Level - CM7
    &_vStackTop, // The initial stack pointer
    ResetISR, // The reset handler

Please see your axf file by symbol Viewer. Is g_pfnVectors allocated in RAM_TOP(maybe 0x20000000) in your Project?

symbol_broser.png

> 4. I also didn't understand why stack pointer equals to DefDST_RAM_TOP.

Stack Top is *(uint32_t *)DefDST_RAM_TOP.  I attached sample project (Personally I bought IMXRT1060 - EVK and made a sample project with my hobby). please build and see "IMXRT1060-EVK_APL/Debug/IMXRT1060-EVK_APL.bin" by binaryEditor. Stack Top is 0x20280000 in APL Project.

> 5. Isn't it possible to jump with c function instead of the assembly commands?

I tried that method, but for some reason it did not work. I think your understanding is correct.

> 6. Did you create both application in MCUXpresso or IAR ? (We also consider which IDE to use in project)

I attached Sample Project(it's my hobby) for IMXRT1060-EVK In MCUXpressoIDE ( SDK is "SDK_2.4.0_EVK-MIMXRT1060"). 

"Check ROM"(IMXRT1060-EVK\IMXRT1060-EVK_BOOT\source\common\update.c) actually develops APL from ROM to RAM.

If you write binary image, Please use WriteDebugApl.bat/WriteDebugBoot.bat. (please modify MCUX_IDE_DIR) .

Best Regards,

T.Kashiwagi

View solution in original post

19 Replies
5,127 Views
Takashi_Kashiwagi
Senior Contributor I

HI ranshalit.

> 1. the binary can be created with objcopy, Right ? (the default compile to axf format)

Yes, I use Post-build steps asfollows. In defult setting, Line of arm-none-eabi-objcopy is comment outed, Please delete '#' and enable arm-none-eabi-objcopy.

post-build-steps.png

> 2. Did you flash the exact binary file size or did you try to calculate its size from the memory map (text+data?) ?

I used the file size of the *. Bin file as it is as u32BinSize. this size is equal to TEXT+DATA.

As follows, Text = 149964, data=3072 and bin file size=153036.

Performing post-build steps
arm-none-eabi-size "IMXRT1060-EVK_APL.axf" ; arm-none-eabi-objcopy -v -O binary "IMXRT1060-EVK_APL.axf" "IMXRT1060-EVK_APL.bin" ; C:/workspace/IMXRT1060-EVK/IMXRT1060-EVK_APL/post-build/crc16.exe -s FFFF -i "IMXRT1060-EVK_APL.bin" -o "IMXRT1060-EVK_APL_crc16.bin" ; # checksum -p MIMXRT1062xxxxA -d "IMXRT1060-EVK_APL.bin"
   text    data     bss     dec     hex filename
 149964    3072 10566376 10719412  a390b4 IMXRT1060-EVK_APL.axf
copy from `IMXRT1060-EVK_APL.axf' [elf32-littlearm] to `IMXRT1060-EVK_APL.bin' [binary]
argc  = 7
[main ( 148)] szInputFile    = <IMXRT1060-EVK_APL.bin>
[main ( 149)] szOutputFile   = <IMXRT1060-EVK_APL_crc16.bin>
[main ( 150)] u16SeedSum     = 0xFFFF
[main ( 151)] u32InputSize   = 153036
[main ( 152)] u16crc16       = 0xFAD5
[main ( 154)] OUTPUT OK        <IMXRT1060-EVK_APL_crc16.bin>
 

> 3. Is ResetISR  equals to DefDST_RAM_TOP+4 in your case ?

Yes. I have used g_pfnVectors. StackTop value and address of ResetISR are allocated as follows.

void (* const g_pfnVectors[])(void) = {
    // Core Level - CM7
    &_vStackTop, // The initial stack pointer
    ResetISR, // The reset handler

Please see your axf file by symbol Viewer. Is g_pfnVectors allocated in RAM_TOP(maybe 0x20000000) in your Project?

symbol_broser.png

> 4. I also didn't understand why stack pointer equals to DefDST_RAM_TOP.

Stack Top is *(uint32_t *)DefDST_RAM_TOP.  I attached sample project (Personally I bought IMXRT1060 - EVK and made a sample project with my hobby). please build and see "IMXRT1060-EVK_APL/Debug/IMXRT1060-EVK_APL.bin" by binaryEditor. Stack Top is 0x20280000 in APL Project.

> 5. Isn't it possible to jump with c function instead of the assembly commands?

I tried that method, but for some reason it did not work. I think your understanding is correct.

> 6. Did you create both application in MCUXpresso or IAR ? (We also consider which IDE to use in project)

I attached Sample Project(it's my hobby) for IMXRT1060-EVK In MCUXpressoIDE ( SDK is "SDK_2.4.0_EVK-MIMXRT1060"). 

"Check ROM"(IMXRT1060-EVK\IMXRT1060-EVK_BOOT\source\common\update.c) actually develops APL from ROM to RAM.

If you write binary image, Please use WriteDebugApl.bat/WriteDebugBoot.bat. (please modify MCUX_IDE_DIR) .

Best Regards,

T.Kashiwagi

5,126 Views
rans
Senior Contributor I

It works now for me! 

but I think that you also need to add in JumpApplication

initialization of VTOR:

SCB->VTOR=(uint32_t)(start_address);      /*Relocate interrupt table ptr*/

Thanks,

Ran

0 Kudos
5,126 Views
Takashi_Kashiwagi
Senior Contributor I

Hi ranshalit

VTOR is initialized by InstallIRQHandler(). Please see main function and fsl_common.c.

InstallIRQHandler will copy g_pfnVectors and set VectorTable in VTOR.

By the way, Since gcc did not work well, the vector table is forcibly placed at the beginning of the DTCM.

(So, TOP of SRAM_DTC is set to 0x20000400).

Best Regards,

T.Kashiwagi

0 Kudos
5,126 Views
rans
Senior Contributor I

Hello T.Kashiwagi,

Thank you very very much!

0 Kudos
5,126 Views
Takashi_Kashiwagi
Senior Contributor I

HI ranshalit

 

> 1. Why do you do :

> memcpy((void*)DefDST_RAM_TOP, (void*)(DefORM_BIN_TOP), u32BinSize);
> if(memcmp((void*)(DefROM_BIN_TOP), (void*)DefDST_RAM_TOP, u32BinSize) == 0){
> Isn't it required to use only the 1st memcpy above (from ROM to RAM) ?

It can be memcpy alone. memcmp is included for verification.

 

> 2. you said before that "binary image is written in specific area on ROM".

>    How did you do this ? A project is compiled into .axf format, how did you wrote it into flash ? 

In my case, I make *.bin file by Post-build-action. And I used GUI Flash Tool to write binary image as follows.

(GUI Flash Tool is included in MCUXpresso IDE). 

GUI Flash Tool.png

Base Address 0x60400000 is the specific area(DefROM_BIN_TOP).

> 3. Where can do find binsize, ramstart, and romstart ? Did you add it somehow into the bootloader project ?

You can design this freely. binsize may be fixed or it may be placed in a specific area of the binary (For example, it is fixed to 4MB, it is placed at the offset 0xXXXX position, and so on.). 

RamStart and RomStart are determined by your design. 

In my Project, Unlike the sample code, binary size is appended to the beginning of the binary image and CRC is added to the end.

StartEndContents
0x600000000x603FFFFFROM : BOOT Project
0x604000000x6040003ROM : Size of APL(uint32_t)
0x604000040x607FFFFFROM : APL Project(Binary Image with CRC)
0x800000000x803FFFFFRAM : APL Project(Area to actually run)

> 4. It also seems that the code is not the code you're using becuase the syntax code error: "DefORM_BIN_TOP"
> If you can attach the 2 projects it will be helpful.

Sorry It is type miss..... "DefROM_BIN_TOP" is correct. And, Since I do the two projects at work, I can not attach project....

Best Regards,

T.Kashiwagi

5,126 Views
rans
Senior Contributor I

Hello T.Kashiwagi,

 

Thank you very very much ! It's very helpful !

 

May I please ask some very more important questions on your concept above:

 

1. the binary can be created with objcopy, Right ? (the default compile to axf format)

2. Did you flash the exact binary file size or did you try to calculate its size from the memory map (text+data?) ?

3. About the jump assembly functions you previosuly said:
 "JumpApplication set StackPointer to MSP and Address of ResetISR to PC."

 But I see the the 2nd parameter is:

  JumpApplication(*(uint32_t*)DefDST_RAM_TOP, *(uint32_t*)(DefDST_RAM_TOP + 4));

 

Is ResetISR  equals to DefDST_RAM_TOP+4 in your case ? I am not sure it is always mapped to the start of RAM, because I see in my helloworld .map file that it is mapped to:

0x20000340                ResetISR

 

4. I also didn't understand why stack pointer equals to DefDST_RAM_TOP.

 

5. 

Isn't it possible to jump with c function instead of the assembly commands?

I mean, why not do the follwoing:

check where the resetIDR in map file for example let's say that in map file:

0x20000340                ResetISR

 

and then call it from the bootloader as following:

 

void (*foo)(void) = 0x20000340 ;

foo();

6. Did you create both application in MCUXpresso or IAR ? (We also consider which IDE to use in project)

 

Thank you very very much,

ranran

0 Kudos
5,126 Views
Takashi_Kashiwagi
Senior Contributor I

Hi ranshalit

> Can you give instruction and example code as to how to do this copy and then jump to start of the application ?

The simple sample code is as follows. Change the addresses of ROM and RAM as necessary.

There are the following preconditions.

  • The binary of the application must be written in ROM(0x6040000) beforehand.
  • The vector table is placed at the top of the application.

#define DefROM_BIN_TOP    (0x60400000)
#define DefDST_RAM_TOP    (0x80000000)

__attribute__((always_inline)) static inline void JumpApplication(uint32_t topOfMainStack, uint32_t AppliAddr)
{
__ASM volatile ("mov r13, %0" : : "r" (topOfMainStack) : );
__ASM volatile ("mov r15, %0" : : "r" (AppliAddr) : );
}

_Bool ExampleCheckROM(uint32_t u32BinSize)
{
    memcpy((void*)DefDST_RAM_TOP, (void*)(DefROM_BIN_TOP), u32BinSize);
/** Verify */
    if(memcmp((void*)(DefROM_BIN_TOP), (void*)DefDST_RAM_TOP, u32BinSize) == 0)
{
        printf("memcpy OK\r\n");
        vTaskDelay(100u);
       
        NVIC_DisableIRQ();
        ARM_MPU_Disable();
        SCB_DisableDCache();
        SCB_DisableICache();
/** Set Stack Pointer and PC */
        JumpApplication(*(uint32_t*)DefDST_RAM_TOP, *(uint32_t*)(DefDST_RAM_TOP + 4));
    }
 
    return bret;
}

In above sample codes,

  1. ExampleCheckROM copies data from 0x60400000 to 0x80000000.
  2. JumpApplication set StackPointer to MSP and Address of ResetISR to PC.

 

Best Regards,

T.Kashiwagi

5,126 Views
rans
Senior Contributor I

Hello T.Kashiwagi,

Can I please ask one more question ?

We plan to use your idea in our project, but I find some strange things in this code snippet:

1. Why do you do :

memcpy((void*)DefDST_RAM_TOP, (void*)(DefORM_BIN_TOP), u32BinSize);
if(memcmp((void*)(DefROM_BIN_TOP), (void*)DefDST_RAM_TOP, u32BinSize) == 0){
Isn't it required to use only the 1st memcpy above (from ROM to RAM) ?

2. you said before that "binary image is written in specific area on ROM".

    How did you do this ? A project is compiled into .axf format, how did you wrote it into flash ? 

3. Where can do find binsize, ramstart, and romstart ? Did you add it somehow into the bootloader project ?

4. It also seems that the code is not the code you're using becuase the syntax code error: "DefORM_BIN_TOP"
 If you can attach the 2 projects it will be helpful.

Thank you very much for the assistance !
ranran

0 Kudos
5,126 Views
rans
Senior Contributor I

T.Kashiwagi,

Thank you very much!

Ran

0 Kudos
5,126 Views
Takashi_Kashiwagi
Senior Contributor I

Hi, ranshalit.

> I haven't tried it yet, (I will probably do it with IAR, not MCUXpresso), but according to my understanding, after doing as you advised, and pressing debug, it > will start it in RAM, but won't program it in flash as I needed (as I said, we need to program it in flash, so that after reset it starts automatically).

If the image of the program is written in the ROM and you want to execute on the RAM,  BootLoader transfers the binary image stored in the ROM to RAM at startup.

There are several methods.

  1. Make all functions a RAM execution function by "attribute" or "pragma" key word. 
  2. Changing the IVT(I do not know how to do it in detail)..
  3. Using Traditional 2nd Boot.

In my case, Since changing the IVT was troublesome, I made two Projects as follows. 

  1. Boot Project (traditional 2nd bootloader)
    1. This program has DCD table. 
    2. This program is allocated to ROM, and running on ROM.
    3. This program copies the binary image placed in a specific area on ROM to RAM.
  2. Application Project
    1. This program has no DCD Table.
    2. This program is allocated to RAM, and running on RAM
    3. When debugging is executed, the debugger expands the image to RAM. Normally at boot time, binary image is written in specific area on ROM, and Bootloader expands to RAM.

Best Regards,

T.Kashiwagi

5,126 Views
rans
Senior Contributor I

Hello T.Kashiwagi,

Thank you very much for the help.

I am very interested in knowing how you did step (3) above for your bootloader:

(3) This program copies the binary image placed in a specific area on ROM to RAM.

Can you give instruction and example code as to how to do this copy and then jump to start of the application ?

Thank you very much,

ranran

0 Kudos
5,126 Views
Takashi_Kashiwagi
Senior Contributor I

Hi, ranshalit.

> No I need to do the same, but I need that these same demo (for example helloworld demo) shall run in ram, not in flash (yes it must be programmed in flash so that after reset it shall start running). These is what I means when saying non-xip. 

When executing a program in RAM, the TEXT section must first be located in the RAM. you nead to check "Link Application to RAM" as follows.

Link application to RAM.png

As a result, the Text section is placed in the first RAM area set in "Memory Configration Editor".

And the debugger writes the program directly to RAM.  You can check from the memory browser whether the program was written in RAM. Please check whether the program was placed at the intended address.

In the following example, the .text section is placed in "RAM" (0x80000000 -).

MCE.png

Symbol.png

Best Regards,

T.Kashiwagi

5,126 Views
rans
Senior Contributor I

Hello T.Kashiwagi,

 

Thank you very much for the help.

I haven't tried it yet, (I will probably do it with IAR, not MCUXpresso), but according to my understanding, after doing as you advised, and pressing debug, it will start it in RAM, but won't program it in flash as I needed (as I said, we need to program it in flash, so that after reset it starts automatically).

 

I need to program a bootable image in flash using the jtag (just as we did with the xip example by simply pressing debug button)

 

Thank you,

ranran 

0 Kudos
5,126 Views
igorpadykov
NXP Employee
NXP Employee

Hi ranran

boot from sd always non-xip, so one can look at

AN12107 How to Enable Boot from Octal SPI Flash and SD Card

or https://community.nxp.com/docs/DOC-340655 

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

5,126 Views
rans
Senior Contributor I

Hello Igor,

Thank you for the link.

Is there an example , such as helloworld xip example in MCUXpresso SDK, which can be used as non-xip ?

I mean such an example which can be run/debug with MCUXpresso, and after reset shall behave as non-xip (exactly like the bubble and helloworld xip example, but as non-xip)

Thank you,

ranran

0 Kudos
5,126 Views
Takashi_Kashiwagi
Senior Contributor I

Hi, ranshalit.

Is there an example , such as helloworld xip example in MCUXpresso SDK, which can be used as non-xip ?

I do not understand the meaning of non-XIP well, but if you want to delete the DCD table, please delete the XIP folder from the project. As a result, ".boot_hdr" section is deleted and "g_pfnVectors" is placed at the beginning of the ROM.

By the way, Do you want to create a project running on SDRAM?

If so, I think that "RT1050_BriefOverview_v201.pdf" is useful.(https://community.nxp.com/community/mcuxpresso/mcuxpresso-ide/blog/2017/12/07/overview-of-using-the-...)

Chapter 13 describes how to debug the RAM project ("Building and Debugging Prijects fir RAM").

Best Regards,

T.Kashiwagi

0 Kudos
5,126 Views
rans
Senior Contributor I

Hello T.Kashiwagi, Igor,

I already run many demos from SDK 2.4.2.

It has 2 xip projects (helloworld and bubbles).

On pressing "debug" button, these project are programmed in flash (with all appropriate image header), so after reset it boot correctly and start running the demo.

No I need to do the same, but I need that these same demo (for example helloworld demo) shall run in ram, not in flash (yes it must be programmed in flash so that after reset it shall start running). These is what I means when saying non-xip. 

I just now need to understand what modifications are required in the hello world to make it work (so that pressing debug shall program it into flash, and on reset it shall start )

Thank you,

ranran

0 Kudos
3,161 Views
VIGNESH_BABU
Contributor II

Is there is any non-xip program in sdk examples.

0 Kudos
5,126 Views
igorpadykov
NXP Employee
NXP Employee

Hi ranran

any sd example is non-xip

Best regards
igor

0 Kudos