How to jump to APP code from BOOT.

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

How to jump to APP code from BOOT.

Jump to solution
2,137 Views
zp001
Contributor III

Hello NXP team,

I'm developing bootloader on S32K344 platform.There was a hardfult issue when I tried to jump to APP from BOOTLOADER, 

here is my sample code:

typedef void (*AppAddr)(void);
int main(void)
{
/* Write your code here */
resetHandle = (AppAddr)(*(uint32_t *)0x00501420);
(resetHandle)();

.....

}

I get the reset handler address in APP map file, and the address of reset handler is 0x00501420, map file as below:

*(.startup)
*fill* 0x00501414 0xc
.startup 0x00501420 0x1c8 ./Project_Settings/Startup_Code/startup_cm7.o
0x00501420 _start
0x00501420 Reset_Handler
0x00501572 MCAL_LTB_TRACE_OFF
0x00501574 _end_of_eunit_test
0x005015e8 . = ALIGN (0x4)

I'd like to know why this happened and how debug under this situation.

Thank you!

 

0 Kudos
1 Solution
2,097 Views
KalaimaniArumugamdev
Contributor III

Hi @zp001 

           First of all, EPSR means Execution Program Status Register, EPSR. Before getting to this might help you  https://developer.arm.com/documentation/ddi0419/c/System-Level-Architecture/System-Level-Programmers...

     This kind of multi-project in a single MCU design requires a deinitialization process on every jump. Also vector table reallocation and PS & SP. Also, try to jump to 0x00501000 instated 0x00501004.

View solution in original post

0 Kudos
6 Replies
2,115 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi Zhend,

this code will work if the provided address is an address of reset vector. In your case, it looks like you provide an address which is directly address of entry point.

Example:

This is my vector table:

lukaszadrapa_0-1672992842523.png

Reset vector can be found at 0x00400004. So, entry point address is 0x004004C8.

Using you code, it should be called like this:

resetHandle = (AppAddr)(*(uint32_t *)0x00400004);
(resetHandle)();

 

Regards,

Lukas

0 Kudos
2,108 Views
zp001
Contributor III

Hi Lukas,

Thank you for your help!

I don't understand how to get the address of reset handler in my S32K314 project.

Here is the key part of map file:

 

.flash 0x00500000 0x3e61c
*(.boot_header)
.boot_header 0x00500000 0x2c ./Project_Settings/Startup_Code/startup_cm7.o
0x00501000 . = ALIGN (0x1000)
*fill* 0x0050002c 0xfd4
0x00501000 __text_start = .
0x00501000 __interrupts_rom_start = .
*(.intc_vector)
.intc_vector 0x00501000 0x408 ./Project_Settings/Startup_Code/Vector_Table.o
0x00501000 VTABLE
0x00501408 . = ALIGN (0x4)
0x00501408 __interrupts_rom_end = .
*(.core_loop)
.core_loop 0x00501408 0xc ./Project_Settings/Startup_Code/startup_cm7.o
0x00501408 _core_loop
0x00501414 . = ALIGN (0x4)
*(.startup)
*fill* 0x00501414 0xc
.startup 0x00501420 0x1c8 ./Project_Settings/Startup_Code/startup_cm7.o
0x00501420 _start
0x00501420 Reset_Handler
0x00501572 MCAL_LTB_TRACE_OFF
0x00501574 _end_of_eunit_test
0x005015e8 . = ALIGN (0x4)
...
...
...
 *(.mcal_text)
 .mcal_text     0x0051b094       0x14 ./Project_Settings/Startup_Code/exceptions.o
                0x0051b094                NMI_Handler
                0x0051b096                HardFault_Handler
                0x0051b098                MemManage_Handler
                0x0051b09a                BusFault_Handler
                0x0051b09c                UsageFault_Handler
                0x0051b0a0                DebugMon_Handler
                0x0051b0a6                undefined_handler
 .mcal_text     0x0051b0a8       0x52 ./Project_Settings/Startup_Code/nvic.o
                0x0051b0a8                NVIC_SetPriorityGrouping
                0x0051b0bc                NVIC_EnableIRQ
                0x0051b0d4                NVIC_DisableIRQ
                0x0051b0ec                NVIC_SetPriority

 

The corresponding memory conten is shown as below:

zp001_0-1673060155203.png

In my case, the 0x00501004 is physical address of reset vector, is that right?

But I tried to jump 0x00501004 and got failure again!

Did I miss any key point?

An error log printed in the console:

 

UsageFault: An instruction executed with an invalid EPSR.T or EPSR.IT field. 
HardFault: A fault has been escalated to a hard fault. 

 

 I'd like to know how to get the reset vector adrress .would you like to share any reference documents?

0 Kudos
2,098 Views
KalaimaniArumugamdev
Contributor III

Hi @zp001 

           First of all, EPSR means Execution Program Status Register, EPSR. Before getting to this might help you  https://developer.arm.com/documentation/ddi0419/c/System-Level-Architecture/System-Level-Programmers...

     This kind of multi-project in a single MCU design requires a deinitialization process on every jump. Also vector table reallocation and PS & SP. Also, try to jump to 0x00501000 instated 0x00501004.

0 Kudos
2,090 Views
zp001
Contributor III

@KalaimaniArumugamdev ,

Thank you for your reply!

Finally, the code can be run normally by using 0x00501004 as entry of APP image.

Thank you all. 

0 Kudos
1,034 Views
bwp530
Contributor IV

hi, I met a same problem. Could you tell me the detail to slove my problem

0 Kudos
710 Views
xuliwei
Contributor I

需要找到APP代码中断向量表的起始地址,app跳转入口地址就是这个+4

0 Kudos