i.MXRT1064 Bootloader

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

i.MXRT1064 Bootloader

6,975 Views
raviranjankumar
Contributor III

Hi,

I am working on i.MXRT1064. I want to run my application from internal flash. I want to store my code in internal flash, and jump to that address. So will it run directly ? Or do I need to follow any boot steps?

To erase or to write internal flash through FlexSPI2, what is the sector size or block size?

Is internal flash is same as W25Q32FVSSIG?

What are the changes I need to do in linker file if I want to run my code from a particular internal flash address?

I am using IAR Workbench.

Please help with the required information.

Regards,

Ravi Ranjan Kumar.

0 Kudos
17 Replies

5,232 Views
Takashi_Kashiwagi
Senior Contributor I

Hi Ravi

I think the above settings are correct.


To isolate the problem, try jumping to application code with MPU and caching disabled.

ARM_MPU_Disable();
SCB_DisableDCache();
SCB_DisableICache();


If you can not jump, check that SP and PC after executing jump to application code are the intended values.

(If you can jump, MPU setting is worong!)

In my environment, the following code executes a function in a specific area.

/**

 * usage

 * JumpApplication(*(uint32_t*)0x80000000, *(uint32_t*)0x80000004);

 */

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

Best Regards,

T.kashiwagi

0 Kudos

5,232 Views
raviranjankumar
Contributor III

Hi Kashiwagi,

I am facing the same issue. All operations, I am performing in Internal Flash mode (SW7 - 0010). I have attached Led app hex file (0x70000000), and linker file for bootloader (at 0x70000000) and application ( at 0x70100000). please check if everything is correct or not?

And if possible then provide some sample code to perform this operation.

Best Regards,

Ravi Ranjan.

0 Kudos

5,232 Views
Takashi_Kashiwagi
Senior Contributor I

Hi Ravi,

please check if everything is correct or not?

It seems that iMXRT1064_Led_0x70100000.hex has DCD table (Vector table and Text Area start from 0x70102000).

Is this what you intended?

In this case, I think that starting the program from 0x70102004 does not work (I confirmed icf & hex files. I think that 0x70100004 is not Reset Handler Vector).

And if possible then provide some sample code to perform this operation.

It is for RT1060, but there is a project to copy the code in ROM to SDRAM and execute it.

https://github.com/tkashi-github/IMXRT1060-EVK

CheckROM of "IMXRT1060-EVK/IMXRT1060-EVK_BOOT/source/common/update.c" is a function to copy ROM to SDRAM and jump to ResetHandler.

(The CheckROM function incorporates a CRC check. Please skip it as appropriate.)

Best Regards,

T.Kashiwagi

0 Kudos

5,232 Views
raviranjankumar
Contributor III
Hi Kashiwagi,
1. I want to run bootloader from the start of flash. My bootloader linker addresses are
define symbol m_interrupts_start        = 0x70002000;
define symbol m_interrupts_end         = 0x700023FF;

define symbol m_text_start                 = 0x70002400;
define symbol m_text_end                  = 0x703FFFFF;

define symbol m_data_start                = 0x20000000;
define symbol m_data_end                 = 0x2001FFFF;

define symbol m_data2_start              = 0x20200000;
define symbol m_data2_end               = 0x202BFFFF;

define exported symbol m_boot_hdr_conf_start = 0x70000000;
define symbol m_boot_hdr_ivt_start                   = 0x70001000;
define symbol m_boot_hdr_boot_data_start       = 0x70001020;
define symbol m_boot_hdr_dcd_data_start        = 0x70001030;
2. I want to run my application from 0x70100000. I am changing  application linker addresses like below
define symbol m_interrupts_start        = 0x70102000;
define symbol m_interrupts_end         = 0x701023FF;

define symbol m_text_start                 = 0x70102400;
define symbol m_text_end                  = 0x703FFFFF;

define symbol m_data_start                = 0x20000000;
define symbol m_data_end                 = 0x2001FFFF;

define symbol m_data2_start              = 0x20200000;
define symbol m_data2_end               = 0x202BFFFF;

define exported symbol m_boot_hdr_conf_start = 0x70100000;
define symbol m_boot_hdr_ivt_start                   = 0x70101000;
define symbol m_boot_hdr_boot_data_start       = 0x70101020;
define symbol m_boot_hdr_dcd_data_start        = 0x70101030;  
With these setting, I am creating an application hex file and copying hex file data to internal flash at address 0x70100000 ( using ROM API).  and jumping to 0x70100000 to run the application. Is it correct?
Best Regards,
Ravi Ranjan Kumar.
0 Kudos

5,232 Views
Takashi_Kashiwagi
Senior Contributor I

Hi Ravi,

With these setting, I am creating an application hex file and copying hex file data to internal flash at address 0x70100000 ( using ROM API).  and jumping to 0x70100000 to run the application. Is it correct?

I think it is correct. In your icf settings, Vector Table locates at 0x70102000 - 0x701023FF. So  The address of the reset handler is stored at 0x70102004. (Please confirm your map file)

Your boot loader must know that address of application's reset handle

if you want to jump your application code, Please Use the JumpApplication function as follows.

JumpApplication(*(uint32_t*)0x70102000, *(uint32_t*)0x70102004);

I confirmed the contents of the hex file, In your application,  JumpApplication function will set "0x20020000" to SP and "0x701061D1" to PC.

led_apl.png

 

Best Regards,

T.Kashiwagi

0 Kudos

5,232 Views
raviranjankumar
Contributor III

Hi Kashiwagi,

Now it is working. Your information was very helpful. 

But if I am not allocating DCD memory in application code, then only application code is running. So now  I am allocating DCD memory only in bootloader and I am using ROM API in bootloader and application also. But my application is not running perfectly like I am facing issue while receiving data in UART.  With DCD memory UART is working perfetly but after jumping application is crashing.

Thanks and regards,

Ravi Ranjan Kumar.

0 Kudos

5,232 Views
Takashi_Kashiwagi
Senior Contributor I

Hi Ravi

With DCD memory UART is working perfetly but after jumping application is crashing.

The DCD table contains register settings for Onchip boot ROM to setup Clock, SPI flash, SDRAM, etc. The problem after jumping to application is that of application.

What state does crashing mean? (Assert, stack destruction, hardfault or etc ...)

Best Regards,

T.Kashiwagi

0 Kudos

5,232 Views
raviranjankumar
Contributor III

Hi Kashiwagi,

If I am including DCD in application. everything is running perfectly but after jumping it is going to hardfault below.

HardFault exception.
The processor has escalated a configurable-priority exception to HardFault.
An MPU or Execute Never (XN) default memory map access violation has occurred on an instruction fetch (CFSR.IACCVIOL, MMFAR).
An imprecise data access error has occurred (CFSR.IMPRECISERR, BFAR).
Exception occured at PC = 0xffffffff, LR = 0x0

Best Regards,

Ravi Ranjan.

0 Kudos

5,232 Views
Takashi_Kashiwagi
Senior Contributor I

Hi Ravi

If I am including DCD in application. everything is running perfectly but after jumping it is going to hardfault below.

Does the PC just before hard fault point to application? Or do you point to the bootloader?

(Do you have a hard fault right after jumping to the application?)

Removing the DCD table from the application will change the position of the vector table in application.

Please confirm that the address to jump.

Best Regards,

T.Kashiwagi

0 Kudos

5,232 Views
raviranjankumar
Contributor III

Hi Kashiwagi,

I am jumping to application address.

Yes right after jumping it is going hardfault. Just after execution of instruction in screenshot.

/* Jump to the Application */
JumpToFBL(*(uint32_t*)0x70102000, *(uint32_t*)0x70102004);

I have attached screenshot of before jumping. 

Please check once.

Regards,

Ravi Ranjan.

0 Kudos

5,232 Views
Takashi_Kashiwagi
Senior Contributor I

Hi Ravi

I saw the screen shot. I think that the value you are trying to set for SP and PC is wrong.

JumpToFBL(*(uint32_t*)0x70102000, *(uint32_t*)0x70102004);

Is the vector table position you are trying to refer to?

The vector table is moved to the beginning of the program when the DCD table is deleted

Maybe You can jump with the following code. However, please check where the vector table is placed.

JumpToFBL(*(uint32_t*)0x70100000, *(uint32_t*)0x70100004);

Best Regards,

T.Kashiwagi

0 Kudos

5,232 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Ravi,

1.When reset, the RT106x always run ROM bootloader first. Then according to the information in 0x70000000, it can XIP in internal QSPI flash.
2.The internal flash is W25Q32JV, page size 256 byte, sector size 4k minimal.
3. They are almost same, except max speed. W25Q32JV max speed is 133MHz, W25Q32FV is 104MHz.
4.Please refer to AN12290.pdf(Migration Guide from i.MX RT1060 to i.MX RT1064)

Regards,

Jing

0 Kudos

5,232 Views
raviranjankumar
Contributor III

Hi Jing Pan,

Thanks for your response. Now I have some more queries.

1.  To read, write, erase, I am using ROM API (Address 0x0020001C) given in reference manual. I am able to write, read. Is it correct or should I use a separate FlexSPI driver?

2. After writing, when I am jumping to that address(internal flash), It is going to hardfault. To jump I am using below instructions.

/* Jump to Application Code */
__asm( "mov r1, r0 \n"
             "ldr r0, [r1, #4] \n"
             "ldr sp, [r1] \n"
             "blx r0"
);

Is it correct or any other ways are there to jump here?

My requirement is to store the code in internal flash and run from there. How to use XIP or NON XIP boot. Can you provide any reference code for bootloader?

Regards,

Ravi Ranjan Kumar.

0 Kudos

5,232 Views
Takashi_Kashiwagi
Senior Contributor I

Hi Ravi

2. After writing, when I am jumping to that address(internal flash), It is going to hardfault. To jump I am using below instructions.

What was the cause of hardfault? Please Check Fault Status Register.

And Is MPU setting for the ROM Area that you jumped correct? If you do not have the right to execute, it will cause a hard fault.

Best Regards,

T.Kashiwagi

0 Kudos

5,232 Views
raviranjankumar
Contributor III

Hi Takashi,

Thanks for your response. Fault status is Forced Hard fault.

Hardfault Warning :

(The processor has escalated a configurable-priority exception to HardFault. An MPU or Execute Never (XN) default memory map access violation has occurred on an instruction fetch (CFSR.IACCVIOL, MMFAR). An imprecise data access error has occurred (CFSR.IMPRECISERR, BFAR).

Whatever procedure I have followed, is it correct? 

What is the use of runBootloader ROM API?  Should I use this instead of using instructions?

Regards,

Ravi  Ranjan Kumar.

0 Kudos

5,232 Views
Takashi_Kashiwagi
Senior Contributor I

Hi Ravi

> Fault status is Forced Hard fault.

If it is Forced Hard fault, the cause is written in other fault status registers. Please read the other fault status registers to find the cause of the fault. 

> What is the use of runBootloader ROM API?  Should I use this instead of using instructions?

I think the usage of runBootloader is correct( to read, write, and erase ).

Since Forced Hard Fault has occurred, please check the settings of the MPU(BOARD_ConfigMPU)?

Best Regards,

T.kashiwagi

0 Kudos

5,232 Views
raviranjankumar
Contributor III

Hi Kashiwagi, 

In BOARD_ConfigMPU, for internal flash, I am using the following

/* Setting Memory with Normal type, not shareable, outer/inner write back. */
MPU->RBAR = ARM_MPU_RBAR(2, 0x70000000U);
MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_RO, 0, 0, 1, 1, 0, ARM_MPU_REGION_SIZE_4MB);

Do I need to change anything? Please correct once.

Regards,

Ravi Ranjan.

0 Kudos