S32K148 Bootloader jump application, but application does not run after flash erase + copy

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

S32K148 Bootloader jump application, but application does not run after flash erase + copy

912 Views
kavyakoney
Contributor II

I am developing a bootloader + application setup on S32K148.

  1. Bootloader is located at flash start (0x00000000)
  2. Application is located at 0x00022000
  3. Application has its own vector table and linker script
  4. Application runs perfectly when flashed standalone

When the bootloader performs flash erase and copy of the application, the jump to application does not work.

However:

  1. If I skip erase and copy, the jump works correctly
  2. jump_to_application() is entered in both cases
  3. No application print is seen after jump when erase + copy is enabled

 

Stack pointer and reset handler values look valid

Application vector table is correct

Application runs fine without bootloader

I did not explicitly enable the watchdog in application code

What additional steps are required after flash erase + copy before jumping to the application on S32K148?

Anyone help me with this.

I have attached my linker file script and jump application code below.

Thank you.

Bootloader linker file

MEMORY
{
int_flash_interrupts : ORIGIN = 0x00000000, LENGTH = 0x00000400 /* 1K */ /* Do not change this section */
int_flash_config : ORIGIN = 0x00000400, LENGTH = 0x00000010 /* 16bytes */ /* Do not change this section */
int_flash : ORIGIN = 0x00000410, LENGTH = 0x0001FBF0 /* 128KB total - 0x410 = 0x1FBF0 bytes for bootloader code */
int_sram_results : ORIGIN = 0x1FFE0000, LENGTH = 0x00000100 /* 256bytes */
int_sram : ORIGIN = 0x1FFE0100, LENGTH = 0x0003DF00 /* ~248K */
int_sram_stack_c0 : ORIGIN = 0x2001E000, LENGTH = 0x00001000 /* 4K */
ram_rsvd2 : ORIGIN = 0x2001F000, LENGTH = 0 /* End of SRAM */
}

Application linker file

MEMORY
{
int_flash_interrupts : ORIGIN = 0x00022000, LENGTH = 0x00000400 /* 1K - Application interrupt vectors at 0x00022000 */
int_flash_config : ORIGIN = 0x00022400, LENGTH = 0x00000010 /* 16bytes - Application flash config */
int_flash : ORIGIN = 0x00022410, LENGTH = 0x00063BF0 /* 400KB application area (0x64000 - 0x410 = 0x63BF0 bytes) */
int_sram_results : ORIGIN = 0x1FFE0000, LENGTH = 0x00000100 /* 256bytes */
int_sram : ORIGIN = 0x1FFE0100, LENGTH = 0x0003DF00 /* ~248K */
int_sram_stack_c0 : ORIGIN = 0x2001E000, LENGTH = 0x00001000 /* 4K */
ram_rsvd2 : ORIGIN = 0x2001F000, LENGTH = 0 /* End of SRAM */
}

main.c

EraseApplication();
CopyApplication(DOWNLOADED_APP_START_ADDRESS,APPLICATION_START_ADDRESS,APPLICATION_SIZE);

jump_to_application();

jump_to_application() function

void jump_to_application(void)
{
uint32 app_msp;
application_entry_t app_reset_handler;

/* Print message before jumping */
// printf("jumping to application\r\n");

/* Small delay to ensure message is sent */
// volatile uint32 delay = 100000U;
// while(delay--);

/* Disable all interrupts */
__asm volatile ("cpsid i");

/* Set vector table offset to application's vector table */
S32_SCB->VTOR = APPLICATION_START_ADDRESS;


/* Load application's MSP from first word of vector table */
app_msp = *((volatile uint32*)APPLICATION_START_ADDRESS);

/* Load application's Reset_Handler address from second word of vector table */
app_reset_handler = (application_entry_t)(*((volatile uint32*)(APPLICATION_START_ADDRESS + 4U)));

/* Set the stack pointer to application's MSP */
__asm volatile ("msr msp, %0" : : "r" (app_msp));

// /* Memory barrier */
// __asm volatile ("dsb");
// __asm volatile ("isb");

/* Jump to application's Reset_Handler */
app_reset_handler();

/* Should never reach here */
while(1)
{
/* Infinite loop */
}
}

 

Tags (1)
0 Kudos
Reply
2 Replies

731 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @kavyakoney,

There may be a flash access collision, because both the bootloader and the application are currently placed inside Flash Block 0 on the S32K148.
The S32K148 device contains three 512 KB flash blocks (Block 0, Block 1, Block 2). Flash programming operations (erase/program) can only be performed on a block that the CPU is not executing code from.
If the bootloader is running from Block 0 and attempts to erase or program memory that is also inside Block 0, the core may execute invalid data, preventing a proper jump to the application.
To avoid this, you should place the application into Flash Block 1 or Flash Block 2, while keeping the bootloader solely in Block 0.

 

Thank you,

BR, Daniel

 

0 Kudos
Reply

809 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Please note that during the Christmas holiday period, our support response times may be longer than usual. In some cases, your request might be addressed after the New Year. Thank you for your understanding.

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2267413%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K148%20Bootloader%20jump%20application%2C%20but%20application%20does%20not%20run%20after%20flash%20erase%20%2B%20copy%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2267413%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20am%20developing%20a%20bootloader%20%2B%20application%20setup%20on%20S32K148.%3C%2FP%3E%3COL%3E%3CLI%3EBootloader%20is%20located%20at%20flash%20start%20(0x00000000)%3C%2FLI%3E%3CLI%3EApplication%20is%20located%20at%200x00022000%3C%2FLI%3E%3CLI%3EApplication%20has%20its%20own%20vector%20table%20and%20linker%20script%3C%2FLI%3E%3CLI%3EApplication%20runs%20perfectly%20when%20flashed%20standalone%3C%2FLI%3E%3C%2FOL%3E%3CP%3EWhen%20the%20bootloader%20performs%20flash%20erase%20and%20copy%20of%20the%20application%2C%20the%20jump%20to%20application%20does%20not%20work.%3C%2FP%3E%3CP%3EHowever%3A%3C%2FP%3E%3COL%3E%3CLI%3EIf%20I%20skip%20erase%20and%20copy%2C%20the%20jump%20works%20correctly%3C%2FLI%3E%3CLI%3Ejump_to_application()%20is%20entered%20in%20both%20cases%3C%2FLI%3E%3CLI%3ENo%20application%20print%20is%20seen%20after%20jump%20when%20erase%20%2B%20copy%20is%20enabled%3C%2FLI%3E%3C%2FOL%3E%3CBR%20%2F%3E%3CP%3EStack%20pointer%20and%20reset%20handler%20values%20look%20valid%3C%2FP%3E%3CP%3EApplication%20vector%20table%20is%20correct%3C%2FP%3E%3CP%3EApplication%20runs%20fine%20without%20bootloader%3C%2FP%3E%3CP%3EI%20did%20not%20explicitly%20enable%20the%20watchdog%20in%20application%20code%3C%2FP%3E%3CP%3EWhat%20additional%20steps%20are%20required%20after%20flash%20erase%20%2B%20copy%20before%20jumping%20to%20the%20application%20on%20S32K148%3F%3C%2FP%3E%3CP%3EAnyone%20help%20me%20with%20this.%3C%2FP%3E%3CP%3EI%20have%20attached%20my%20linker%20file%20script%20and%20jump%20application%20code%20below.%3C%2FP%3E%3CP%3EThank%20you.%3C%2FP%3E%3CP%3E%3CSTRONG%3EBootloader%20linker%20file%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EMEMORY%3CBR%20%2F%3E%7B%3CBR%20%2F%3Eint_flash_interrupts%20%3A%20ORIGIN%20%3D%200x00000000%2C%20LENGTH%20%3D%200x00000400%20%2F*%201K%20*%2F%20%2F*%20Do%20not%20change%20this%20section%20*%2F%3CBR%20%2F%3Eint_flash_config%20%3A%20ORIGIN%20%3D%200x00000400%2C%20LENGTH%20%3D%200x00000010%20%2F*%2016bytes%20*%2F%20%2F*%20Do%20not%20change%20this%20section%20*%2F%3CBR%20%2F%3Eint_flash%20%3A%20ORIGIN%20%3D%200x00000410%2C%20LENGTH%20%3D%200x0001FBF0%20%2F*%20128KB%20total%20-%200x410%20%3D%200x1FBF0%20bytes%20for%20bootloader%20code%20*%2F%3CBR%20%2F%3Eint_sram_results%20%3A%20ORIGIN%20%3D%200x1FFE0000%2C%20LENGTH%20%3D%200x00000100%20%2F*%20256bytes%20*%2F%3CBR%20%2F%3Eint_sram%20%3A%20ORIGIN%20%3D%200x1FFE0100%2C%20LENGTH%20%3D%200x0003DF00%20%2F*%20~248K%20*%2F%3CBR%20%2F%3Eint_sram_stack_c0%20%3A%20ORIGIN%20%3D%200x2001E000%2C%20LENGTH%20%3D%200x00001000%20%2F*%204K%20*%2F%3CBR%20%2F%3Eram_rsvd2%20%3A%20ORIGIN%20%3D%200x2001F000%2C%20LENGTH%20%3D%200%20%2F*%20End%20of%20SRAM%20*%2F%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%3CSTRONG%3EApplication%20linker%20file%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EMEMORY%3CBR%20%2F%3E%7B%3CBR%20%2F%3Eint_flash_interrupts%20%3A%20ORIGIN%20%3D%200x00022000%2C%20LENGTH%20%3D%200x00000400%20%2F*%201K%20-%20Application%20interrupt%20vectors%20at%200x00022000%20*%2F%3CBR%20%2F%3Eint_flash_config%20%3A%20ORIGIN%20%3D%200x00022400%2C%20LENGTH%20%3D%200x00000010%20%2F*%2016bytes%20-%20Application%20flash%20config%20*%2F%3CBR%20%2F%3Eint_flash%20%3A%20ORIGIN%20%3D%200x00022410%2C%20LENGTH%20%3D%200x00063BF0%20%2F*%20400KB%20application%20area%20(0x64000%20-%200x410%20%3D%200x63BF0%20bytes)%20*%2F%3CBR%20%2F%3Eint_sram_results%20%3A%20ORIGIN%20%3D%200x1FFE0000%2C%20LENGTH%20%3D%200x00000100%20%2F*%20256bytes%20*%2F%3CBR%20%2F%3Eint_sram%20%3A%20ORIGIN%20%3D%200x1FFE0100%2C%20LENGTH%20%3D%200x0003DF00%20%2F*%20~248K%20*%2F%3CBR%20%2F%3Eint_sram_stack_c0%20%3A%20ORIGIN%20%3D%200x2001E000%2C%20LENGTH%20%3D%200x00001000%20%2F*%204K%20*%2F%3CBR%20%2F%3Eram_rsvd2%20%3A%20ORIGIN%20%3D%200x2001F000%2C%20LENGTH%20%3D%200%20%2F*%20End%20of%20SRAM%20*%2F%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%3CSTRONG%3Emain.c%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EEraseApplication()%3B%3CBR%20%2F%3ECopyApplication(DOWNLOADED_APP_START_ADDRESS%2CAPPLICATION_START_ADDRESS%2CAPPLICATION_SIZE)%3B%3C%2FP%3E%3CP%3Ejump_to_application()%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3Ejump_to_application()%20function%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Evoid%20jump_to_application(void)%3CBR%20%2F%3E%7B%3CBR%20%2F%3Euint32%20app_msp%3B%3CBR%20%2F%3Eapplication_entry_t%20app_reset_handler%3B%3C%2FP%3E%3CP%3E%2F*%20Print%20message%20before%20jumping%20*%2F%3CBR%20%2F%3E%2F%2F%20printf(%22jumping%20to%20application%5Cr%5Cn%22)%3B%3C%2FP%3E%3CP%3E%2F*%20Small%20delay%20to%20ensure%20message%20is%20sent%20*%2F%3CBR%20%2F%3E%2F%2F%20volatile%20uint32%20delay%20%3D%20100000U%3B%3CBR%20%2F%3E%2F%2F%20while(delay--)%3B%3C%2FP%3E%3CP%3E%2F*%20Disable%20all%20interrupts%20*%2F%3CBR%20%2F%3E__asm%20volatile%20(%22cpsid%20i%22)%3B%3C%2FP%3E%3CP%3E%2F*%20Set%20vector%20table%20offset%20to%20application's%20vector%20table%20*%2F%3CBR%20%2F%3ES32_SCB-%26gt%3BVTOR%20%3D%20APPLICATION_START_ADDRESS%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%2F*%20Load%20application's%20MSP%20from%20first%20word%20of%20vector%20table%20*%2F%3CBR%20%2F%3Eapp_msp%20%3D%20*((volatile%20uint32*)APPLICATION_START_ADDRESS)%3B%3C%2FP%3E%3CP%3E%2F*%20Load%20application's%20Reset_Handler%20address%20from%20second%20word%20of%20vector%20table%20*%2F%3CBR%20%2F%3Eapp_reset_handler%20%3D%20(application_entry_t)(*((volatile%20uint32*)(APPLICATION_START_ADDRESS%20%2B%204U)))%3B%3C%2FP%3E%3CP%3E%2F*%20Set%20the%20stack%20pointer%20to%20application's%20MSP%20*%2F%3CBR%20%2F%3E__asm%20volatile%20(%22msr%20msp%2C%20%250%22%20%3A%20%3A%20%22r%22%20(app_msp))%3B%3C%2FP%3E%3CP%3E%2F%2F%20%2F*%20Memory%20barrier%20*%2F%3CBR%20%2F%3E%2F%2F%20__asm%20volatile%20(%22dsb%22)%3B%3CBR%20%2F%3E%2F%2F%20__asm%20volatile%20(%22isb%22)%3B%3C%2FP%3E%3CP%3E%2F*%20Jump%20to%20application's%20Reset_Handler%20*%2F%3CBR%20%2F%3Eapp_reset_handler()%3B%3C%2FP%3E%3CP%3E%2F*%20Should%20never%20reach%20here%20*%2F%3CBR%20%2F%3Ewhile(1)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%2F*%20Infinite%20loop%20*%2F%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2269040%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K148%20Bootloader%20jump%20application%2C%20but%20application%20does%20not%20run%20after%20flash%20erase%20%2B%20copy%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2269040%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EPlease%20note%20that%20during%20the%20Christmas%20holiday%20period%2C%20our%20support%20response%20times%20may%20be%20longer%20than%20usual.%20In%20some%20cases%2C%20your%20request%20might%20be%20addressed%20after%20the%20New%20Year.%20Thank%20you%20for%20your%20understanding.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2269392%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K148%20Bootloader%20jump%20application%2C%20but%20application%20does%20not%20run%20after%20flash%20erase%20%2B%20copy%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2269392%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F256520%22%20target%3D%22_blank%22%3E%40kavyakoney%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3EThere%20may%20be%20a%20flash%20access%20collision%2C%20because%20both%20the%20bootloader%20and%20the%20application%20are%20currently%20placed%20inside%20Flash%20Block%200%20on%20the%20S32K148.%3CBR%20%2F%3EThe%20S32K148%20device%20contains%20three%20512%20KB%20flash%20blocks%20(Block%200%2C%20Block%201%2C%20Block%202).%20Flash%20programming%20operations%20(erase%2Fprogram)%20can%20only%20be%20performed%20on%20a%20block%20that%20the%20CPU%20is%20not%20executing%20code%20from.%3CBR%20%2F%3EIf%20the%20bootloader%20is%20running%20from%20Block%200%20and%20attempts%20to%20erase%20or%20program%20memory%20that%20is%20also%20inside%20Block%200%2C%20the%20core%20may%20execute%20invalid%20data%2C%20preventing%20a%20proper%20jump%20to%20the%20application.%3CBR%20%2F%3ETo%20avoid%20this%2C%20you%20should%20place%20the%20application%20into%20Flash%20Block%201%20or%20Flash%20Block%202%2C%20while%20keeping%20the%20bootloader%20solely%20in%20Block%200.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EThank%20you%2C%3C%2FP%3E%0A%3CP%3EBR%2C%20Daniel%3C%2FP%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E