My own bootloader

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

My own bootloader

2,122 Views
pjanco
Contributor III

Hi,

I have IMXRT1050-EVKB board with Hyperflash and I want to make my own TFTP bootloader. I am using SDK example "lwip_updecho_bm" as base project for my future bootloader. But I am not able to do jump from bootloader to application. I am not sure, if I have configured memory sections corectly. I will appreciate some help. I prefer to use "manage linker script" instead of manually edited *.ld file.


This is my memory configuration of bootloader project:

bootloader_memory.jpg

bootloader_linker.jpg

This is my memory configuration of application project:

application_memory.jpg

application_linker.jpg

This is my "jump_to_application" function. I am inspired with this function in "flashloader" project example in SDK:

#define APP_ADDRESS 0x60080000
static void jump_to_application()
{
 void (*entry)(void);
 uint32_t pc, sp;

 sp = *((volatile uint32_t*)APP_ADDRESS);
 pc = *((volatile uint32_t *)(APP_ADDRESS + 4));
 entry = (void (*)(void))pc;

 if((sp == 0x00000000)||(sp == 0xffffffff)||(pc == 0x00000000)||(pc == 0xffffffff))
 return;

 SCB->VTOR=(uint32_t)(APP_ADDRESS);

 __set_MSP(sp);
 __set_PSP(sp);

 entry();
}

First, I erased whole FLASH memory. Then I uploaded application project. Then I uploaded bootloader project. I can see in debug session of bootloader project:

sp = 0x81e00000

pc = 0x60080325

So, it is look like the application code is in on the correct position in FLASH. But after I call entry() function, it does not jump into application. Instead of this it jump into begin of bootloader project main() function.

I have another question. I can see in generated *.ld file:

__base_FLASH_APP = 0x60080000  ; /* FLASH_APP */  

__top_FLASH_APP = 0x60080000 + 0x3f80000 ; /* 65024K bytes */

Is there a way how to use this constants in my code?

6 Replies

1,307 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Peter Janco,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
According to your description, you will configure the beginning address of the application code to 0x60080000, however, the application image file maybe follow the Image Vector Table structure, in another word, the 0x60080000 is not the really the beginning address of the application code, please validate it.
In further, I'd like to recommend you to refer to the AN12255, which illustrate how to remap flash address to FlexSPI interface, it may provide inspiration for the solution of this issue.

https://www.nxp.com/docs/en/application-note/AN12255.pdf 
Have a great day,
TIC

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

0 Kudos

1,307 Views
pjanco
Contributor III

Hi,

information in AN12255.pdf are very usefull. I can integrate TFTP update function directly into main application. So, I do not need a bootloader. This is the way I am going to continue.

This document is refering to "SW\src\boards\evkmimxrt1060\use_case\flash_remap_test\nor\polling_transfer\". Where exactly I can found this example? I do not see it in SDK_2.5.0_EVK-MIMXRT1060.

But still, I would like to know why I cant jump to application. I think my jump_to_application() function is expecting there is vector table at beginning.

This is data in my FLASH_APP area:

0x60080000 : 81E00000 60080325 600803A1 60088EF3 00000000 00000000 00000000 00000000 00000000  
0x60080024 : 00000000 00000000 600803B1 00000000 00000000 600803E1 60084385 600889E1 600889E9  
0x60080048 : 600889F1 600889F9 60088A01 60088A09 60088A11 60088A19 60088A21 60088A29 60088A31  
0x6008006C : 60088A39 60088A41 60088A49 60088A51 60088A59 60088A61 60088A69 60088A71 60088A79  
0x60080090 : 60088A81 60088A89 60088A91 60088A99 60088AA1 60088AA9 60088AB1 60088AB9 60088AC1  
0x600800B4 : 60088AC9 60088AD1 60088AD9 60088AE1 60088AE9 60088AF1 60088AF9 60088B01 60088B09  
         
‍‍‍‍‍‍‍

So, my enrty() function is pointing to address 0x60080325. I think this is not correct.

I found IVT data structure in this document:
https://www.nxp.com/docs/en/application-note/AN12107.pdf

Data in my FLASH_APP do not fit to IVT data structure. First 4B is header and it should be 0x412000D1. I think problem is in the application project configuration.

Any idea what I am doing wrong?

Regards,
Peter

1,307 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Peter Janco,

Thanks for your reply.
I've attached the code, please check it.
There's a table which illustrates the Image Vector Table Offset information, it can help you to search for the beginning of the application code.

pastedImage_2.png
Have a great day,
TIC

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

1,307 Views
pjanco
Contributor III

Hi,

there is definitely something wrong with "manage linker script" configurationin in application project.

If set start address of my FLASH_APP to 0x6000000, then my generated BIN file have size 61760B.

I can see this section in generated *.ld file:

    /* Image Vector Table and Boot Data for booting from external flash */
    .boot_hdr : ALIGN(4)
    {
        FILL(0xff)
        __boot_hdr_start__ = ABSOLUTE(.) ;
        KEEP(*(.boot_hdr.conf))
        . = 0x1000 ;
        KEEP(*(.boot_hdr.ivt))
        . = 0x1020 ;
        KEEP(*(.boot_hdr.boot_data))
        . = 0x1030 ;
        KEEP(*(.boot_hdr.dcd_data))
        __boot_hdr_end__ = ABSOLUTE(.) ;
        . = 0x2000 ;
    } >FLASH_APP

If I move start address of FLASH_APP to 0x60080000 (like in my prinstreens), then the generated BIN file have size only 53568B. This is 8192B less. In this new generated *.ld file is no .boot_hdr section.

So, there is no IVT at the begin on my application. I can probably solve this by manually created *.ld file instead of using manage linker script, but this not what I want.

1,307 Views
Takashi_Kashiwagi
Senior Contributor I

Hi Peter,

> This is my "jump_to_application" function. I am inspired with this function in "flashloader" project example in SDK:

I did it the same way, but for some reason it did not work. After all, I wrote the code as follows.

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

If Stacktop value is located 0x80000000 and the address of ResetISR is located 0x80000004, use it as follows.

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

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

> Is there a way how to use this constants in my code?

You can use it by declaring "exntern". Please see ResetISR(startup.mimxrt10XX.c) function. I think that the use of "__data_section_table" will be helpful.

Best Regards,

T.Kashiwagi

0 Kudos

1,307 Views
pjanco
Contributor III

Hi,

your jump function did not work me. It have the same behavior as mine.

Peter.