how bootloader jumping to application

cancel
Showing results for 
Search instead for 
Did you mean: 

how bootloader jumping to application

587 Views
jianxun_liu
Contributor I

Hello everybody,

     I am new to NXP S32K1xx, I have a bootloader project with S32K116 now. the memory map is:

bootloader : 0 ~ 3FFF

application: 4000 ~ flash end.

   

    in debug mode memory view, I see that application is programmed."Jump_To_Application" is called after programming is done.

  Jump_To_Application(*((uint32_t*)APP_START_ADDRESS),*((uint32_t*)(APP_START_ADDRESS+4))); 

/* APP_START_ADDRESS = 0x4000 */

but seems it doesn't work because I never see the application is running.

below is the implement of "Jump_To_Application"

void Jump_To_Application(uint32_t userSP, uint32_t userStartup)
{
 if(userSP == 0xFFFFFFFF)
 {
  return;
 }
 else
 {
  /* Set up stack pointer */
  __asm("msr msp, r0");
  __asm("msr psp, r0");

  /* Relocate vector table */
  S32_SCB->VTOR = (uint32_t)APP_START_ADDRESS;
  /* Jump to application PC (r1) */
  __asm("mov pc, r1");
 }
}

I set a breakpoint at the beginning of "Jump_To_Application", I check the register "r0" , and "r1",

 "r0" is 0x20003800

"r1"  is 0x4411.

I don't find any problem, am I missing anything.

Any comment is welcome.

0 Kudos
2 Replies

481 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi Jxun,

what does happen when you step over the mov pc,r1 instruction? Does it jump anywhere? Or does the debug session crash?

The most common problem I can see is that interrupts are not disabled before jump. It's necessary to disable interrupts in the core and then also all local enable bits in peripherals. It's good practice to revert everything back to default reset state before jump.

Regards,

Lukas

0 Kudos

481 Views
jianxun_liu
Contributor I

Hello Lukas,

Thank you for the response.

step over "mov pc, r1",  MCU resets. 

interrupts is disabled before jump. but no luck for me.

after I change to a new implementation of Jump_To_Application, the jump works, and application is running.

I put my new implementation here for someone have the same problem. hope it is helpful.

void Jump_To_Application(uint32_t userSP) 
{     
   void (*entry)(void);     
   uint32_t pc;     
   if(userSP == 0xFFFFFFFF)     
   {         
      return;     
   }     
   else    
   {         
   /* Set up stack pointer */        
      __asm("msr msp, r0");         
      __asm("msr psp, r0");         
   /* Relocate vector table */        
      S32_SCB->VTOR = (uint32_t)APP_START_ADDRESS;         
   /* Jump to application PC */        
      pc = *((volatile uint32_t *)(APP_START_ADDRESS + 4));         
      entry = (void (*)(void))pc;         
      entry();     
   } 
}
0 Kudos