How to create 2 bootloaders in s32k148

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create 2 bootloaders in s32k148

688 Views
Contributor III

Hello all,

I am working on bootloader part for implementing 2 bootloaders in s32k148.

any one bootloader will be selected based on read the particular memory in EEPROM.

Another one bootloader will be used after development phase.

Could you please provide your inputs on multiple bootloader creation?

11 Replies

37 Views
Contributor III

I created my own bootloader, how to flash this bootloader into s32k148 evb?

Could anybody help me to flash the bootloader into s32k148 evb?

0 Kudos

37 Views
NXP TechSupport
NXP TechSupport

Hello Sathis,

We have an application note for the S32K devices which implements one bootloader and one application. However, you can use it as a reference.

https://www.nxp.com/docs/en/application-note/AN12218.pdf

SW:

https://www.nxp.com/docs/en/application-note-software/AN12218SW.zip 

There can be seen that each project has own Linker File where you can define the start address of the project.

So, I assume you will create two independent projects, each project start at a different address. After that, both complete bootloaders will be loaded into the memory of the MCU.

I hope it helps. If you have any questions, please let me know.

Best Regards,

Diana

0 Kudos

37 Views
Contributor III

Hello Diana,

Thank you so much for the reply.

I created 2 different boot loader projects, and modified the S32K1xx_flash.ld as below

Proj1:

Flash memory:     m_text                (RX)  : ORIGIN = 0x10000000, LENGTH = 0x00001000

Proj2:

Flash memory:     m_text                (RX)  : ORIGIN = 0x10001000, LENGTH = 0x00001000

Currently, after reset(during boot), Program counter (PC) is loaded with address 0x10000000.

i.e PC=0x10000000

So Proj1 is running now.

1) I need run the second bootloader(Proj2).

    To run the 2nd boot loader, load the PC with address 0x10001000.

    I did not find any C or assembler instruction to load the PC with address in S32K14x Series Reference        Manual.pdf .

    Could you please share the info on load the PC with different  address?

0 Kudos

37 Views
NXP TechSupport
NXP TechSupport

Hello Sathis,

The important thing is that the reset vector is expected always at address 0x00000000.

The vector table is placed in the m_interrupt section. 

1. Let's say that the first bootloader starts at address 0x00000000 and the length is 32 KB. see the settings below: 

/* Flash */
m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x00000410, LENGTH = 0x00007BF0

2. When you want to create a project which starts at a different address you need to test it with starting address 0x00000000 after everything is working well you can change the address and load it into the MCU. Also, you should change the m_interrupt address.

So, let's say that the bootloader project is working well and I want to load it into MCU. That is why I change the start address to 0x00008000 with the length 4 KB (for example).

/* Flash */
m_interrupts (RX) : ORIGIN = 0x00008000, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x00008400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x00008410, LENGTH = 0x00001000

I recommend you to look at the section "3. Building compatible applications" in the AN12218

I hope it helps.

If it is not clear please, let me know.

Best Regards,

Diana

0 Kudos

37 Views
Contributor III

Hello Diana,

Thanks for the detailed info.

Flashed the 1st bootloader with below memory details.

Bootloader proj1:

/* Flash */
m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x10000000, LENGTH = 0x00001000 /* Only 4 kB are allowed for the bootloader */

My application program is running successfully. 

Then, 

for 2nd bootloader, modified the memory as below 

Bootloader proj2:

/* Flash */
m_interrupts (RX) : ORIGIN = 0x10001000, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x10001400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x10001410, LENGTH = 0x00001000 /* Only 4 kB are allowed for the bootloader *

 

After flashing the 2nd bootloader also my application is running successfully.

But still confused, which bootloader running now? I think 1st bootloader is used during startup. 

If I want to use the 2nd bootloader, do i need to modify Program counter? or any?

Could you please provide these info if you have an idea?

0 Kudos

37 Views
NXP TechSupport
NXP TechSupport

Hello Sathish,

Yes, if it is not decided otherwise after reset, always the first bootloader will start.

If you want to jump into the 2nd bootloader you can use the approach which we discussed in the thread below 

https://community.nxp.com/message/1143414

Do not forget to relocate interrupt vector table.

Just for example:

I put into the startup.c below functions. The 2ndBootloader function is called in the startup_S32K148.S file.

If the button is pushed the 2nd bootloader will start:

extern void startApplication(unsigned long app_link_location){
asm(" ldr sp, [r0,#0]");
asm(" ldr pc, [r0,#4]");
}


void 2ndBootloader(void)
{
PCC->PCCn[PCC_PORTC_INDEX] = PCC_PCCn_CGC_MASK; // Enable clock for PORTC
PTC->PDDR |= 1<<13; // Port C13 is configured as output
PORTC->PCR[13] = PORT_PCR_MUX(1); // Alternative 1 = GPIO
int button = PTC->PDIR >> 13 & 1; // Read logic level of pin

if(button == 1)
{
S32_SCB->VTOR=(uint32_t)(0x10001000); // Relocate interrupt vector table
startApplication(0x10001000); // Jump to the application reset vector
}
}

I hope it helps

Best Regards,

Diana

37 Views
Contributor III

Hello Diana

I created 3 different projects in s32 design studio,

1) Proj1: S32K148_bootloader_primary - used to select the bootloader proj1 or bootloader proj2

with below memory map:

/* Flash */
m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x10000000, LENGTH = 0x00001000 /* Only 4 kB are allowed for the bootloader */

 Also refer the attached image Primary_bootlder.jpg

2) Proj2:  Bootloader 1 with below memory map.

/* Flash */
m_interrupts (RX) : ORIGIN = 0x10001000, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x10001400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x10001410, LENGTH = 0x00001000 /* Only 4 kB are allowed for the bootloader *

3) Proj3:  Bootloader 2 with below memory map.

 /* Flash */
m_interrupts (RX) : ORIGIN = 0x10002410, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x10002810, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x10002820, LENGTH = 0x00001000 /* Only 4 kB are allowed for the bootloader */

During debugging(via s32 design studio and openSDA), SP and PC registers are loaded with invalid address.

Refer the screen shot.

Primary_bootlder_debugging.jpg

Any idea why the address(0x10001000) are become invalid after calling the function JumpToBootLoader()?

or method of flashing is not correct?

0 Kudos

37 Views
NXP TechSupport
NXP TechSupport

Hello,

Can you please check if your project is loaded at the required address?

You can check the address space in the memory window (menu -> Window -> Show View -> Memory) 

Best Regards,

Diana

0 Kudos

37 Views
Contributor III

Hello Diana,

Resolved this issue on Friday, and I was in vacation yesterday.

Now I am able to load the Proj1 bootloader address in SP and PC registers.

How to flash this bootloaders?

Via S32 design Studio`s debug configuration or create .srec file and then flash?

Because only current bootloader memory is available in memory 0x10001000(bootloader proj1).

Previously I flashed bootloader proj2 with 

 /* Flash */
m_interrupts (RX) : ORIGIN = 0x10002410, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x10002810, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x10002820, LENGTH = 0x00001000 /* Only 4 kB are allowed for the bootloader */

But from 0x10002410, it is all set to 0xFFFFFFFF only.

 

Best Regards

Sathish 

0 Kudos

37 Views
NXP TechSupport
NXP TechSupport

Hello Sathish,

You can, for example, flash your .srec of the second bootloader by the first bootloader (as a reference you can use AN12218) or merge .srec files of both bootloaders into one and then flash into MCU. I believe that there is a lot of possibilities. It's up to you which one fills your application requirements.

Also, please keep in mind that the starting address must be 64-bit aligned (flash address [2:0] = 000) if you are using "36.5.11.4 Program Phrase command"

If you have an interest in S32DS flashing possibilities I recommend you to ask on the S32 Design Studio community.

https://community.nxp.com/community/s32/s32ds

HOWTO: Debug multiple elf files in S32 Design Studio

https://community.nxp.com/docs/DOC-342385

I hope it helps.

Best Regards,

Diana

37 Views
Contributor III

Thanks Diana.

Created 2 bootloaders, an we will test it in s32k148 in future.

0 Kudos