S32K3 sharing data between Bootloader and Application

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

S32K3 sharing data between Bootloader and Application

跳至解决方案
3,349 次查看
HemantKapoor
Contributor II

Hello, 

 

Another Bootloader and application question.... How do I share data between bootloader and application.

I am using S32DS to build my application and have tried following "unified_bootloader_Demo_V2.0" as a reference.

My linker file looks as 

MEMORY 
{         
    int_flash                : ORIGIN = 0x00410400, LENGTH = 0x0007FC00     /* 511K - 176K (sBAF + HSE)*/
    int_itcm                 : ORIGIN = 0x00000000, LENGTH = 0x00010000    /* 32K */
    int_dtcm                 : ORIGIN = 0x20000000, LENGTH = 0x00020000    /* 64K */
    int_sram                 : ORIGIN = 0x20400000, LENGTH = 0x0002DF00    /* 183.9K */
    int_sram_fls_rsv         : ORIGIN = 0x2042DF00, LENGTH = 0x00000100    /* 0.1K */
    int_sram_stack_c0        : ORIGIN = 0x2042E000, LENGTH = 0x00001000    /* 4KB  */
    int_sram_stack_c1        : ORIGIN = 0x2042F000, LENGTH = 0x00001000    /* 4KB  */
    int_sram_no_cacheable    : ORIGIN = 0x20430000, LENGTH = 0x0000FF00    /* 64KB, needs to include int_results  */
    int_sram_results         : ORIGIN = 0x2043FF00, LENGTH = 0x00000100
    int_sram_shareable       : ORIGIN = 0x20440000, LENGTH = 0x00004000-0x80  /* 16KB */
    ram_rsvd2                : ORIGIN = 0x20443F80, LENGTH = 0                /* End of SRAM */
    ram_boot_apploader_share : ORIGIN = 0x20443F80, LENGTH = 0x00000080		  /* Reserve 128 bytes */
}

 When I try to write data in bootloader

*(uint32_t*) 0x20443F80 = DataToShare;

 

it throws hard fault.

 

Can you please let me know what I am missing.

 

The "unified_bootloader_Demo_V2.0" seems to do something similar but it writes to  0x20443F80 + 14.

 

 

0 项奖励
回复
1 解答
3,204 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi Hemant,

I found this function in file boot_Cfg.c:

/*when power on, clear all flag in RAM for ECC.*/
void Boot_PowerONClearAllFlag(void)
{
uint16 infoCrc = 0u;
uint8 index = 0u;

/*clear RAM with 4 bytes for ECC*/
for(index = 0u; index < (gs_stBootInfo.infoDataLen >> 2u); index++)
{
*((uint32 *)gs_stBootInfo.infoStartAddr + index) = 0u;
}

infoCrc = Boot_CalculateInfoCRC();
SetInforCRC(infoCrc);
}

 

So, this piece of memory is initialized only when needed - after power on reset.

However, I think that it is not correct because RAM needs to be initialized by 64bit write as mentioned in the reference manual. I have already contacted authors of the unified bootloader if they can fix it.

To initialize this piece of RAM, you can use something like (just copied from startup files, modify it as needed):

/* Initialize STANDBY RAM if chip comes from POR */
if (MC_RGM->DES & MC_RGM_DES_F_POR_MASK)
{
/* Initialize STANDBY RAM */
cnt = (( uint32_t)(&__STDBYRAM_SIZE)) / 8U;
pDest = (uint64_t *)(&__STDBYRAM_START);
while (cnt--)
{
*pDest = (uint64_t)0xDEADBEEFCAFEFEEDULL;
pDest++;
}
MC_RGM->DES = MC_RGM_DES_F_POR_MASK; /* Write 1 to clear F_POR */

I can see that the access is translated to use STRD instruction which should generate 64bit write.

Regards,

Lukas

 

 

 

在原帖中查看解决方案

0 项奖励
回复
6 回复数
3,230 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi @HemantKapoor 

I guess it's caused by ECC error because the SRAM is not initialized. The unified bootloader uses this code for SRAM initialization:

RamInit:
/* Initialize SRAM ECC */
ldr r0, =__RAM_INIT
cmp r0, 0
/* Skip if __SRAM_INIT is not set */
beq SRAM_LOOP_END
ldr r1, =__INT_SRAM_START
ldr r2, =__INT_SRAM_END

subs r2, r1
subs r2, #1
ble SRAM_LOOP_END

movs r0, 0
movs r3, 0
SRAM_LOOP:
stm r1!, {r0,r3}
subs r2, 8
bge SRAM_LOOP
SRAM_LOOP_END:


Values __INT_SRAM_START and __INT_SRAM_END are defined like this in the linker file:


__INT_SRAM_START = ORIGIN(int_sram);
__INT_SRAM_END = ORIGIN(ram_rsvd2);

But you added your segment after the ram_rscd2:

ram_rsvd2 : ORIGIN = 0x20443F80, LENGTH = 0 /* End of SRAM */
ram_boot_apploader_share : ORIGIN = 0x20443F80, LENGTH = 0x00000080 /* Reserve 128 bytes */
}


So, it's not touched by this SRAM initialization. You need to initialize also this piece of memory.

Regards,

Lukas

0 项奖励
回复
1,020 次查看
zq1
Contributor III

hello, there is a  question to be wroked out , i want to know ,in S32K312 's link file , if i want to set a flag which is used for app vaild flag   in ram ,and after soft reset,the flag will not clear , i must set the flag in  the standby ram or not?  in demo called unified_bootloader_demo_v2.1 ,i found  the flag was set in the lastest section as blew:

zq1_0-1711090569086.pngzq1_1-1711090620877.png

hope your reply ,thank you very much.

0 项奖励
回复
3,220 次查看
HemantKapoor
Contributor II

Hello Lukas,

 

Many thanks for the response.

I followed the unified bootloader linker file usage and it is also doing something similar,

 

ram_rsvd2 : ORIGIN = 0x20443FF0, LENGTH = 0 /* End of SRAM */
ExchangeInfo : ORIGIN = 0x20443FF0, LENGTH = 0x00000010

 

So not sure what I have missed.

 

Regards,

Hemant Kapoor

0 项奖励
回复
3,205 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi Hemant,

I found this function in file boot_Cfg.c:

/*when power on, clear all flag in RAM for ECC.*/
void Boot_PowerONClearAllFlag(void)
{
uint16 infoCrc = 0u;
uint8 index = 0u;

/*clear RAM with 4 bytes for ECC*/
for(index = 0u; index < (gs_stBootInfo.infoDataLen >> 2u); index++)
{
*((uint32 *)gs_stBootInfo.infoStartAddr + index) = 0u;
}

infoCrc = Boot_CalculateInfoCRC();
SetInforCRC(infoCrc);
}

 

So, this piece of memory is initialized only when needed - after power on reset.

However, I think that it is not correct because RAM needs to be initialized by 64bit write as mentioned in the reference manual. I have already contacted authors of the unified bootloader if they can fix it.

To initialize this piece of RAM, you can use something like (just copied from startup files, modify it as needed):

/* Initialize STANDBY RAM if chip comes from POR */
if (MC_RGM->DES & MC_RGM_DES_F_POR_MASK)
{
/* Initialize STANDBY RAM */
cnt = (( uint32_t)(&__STDBYRAM_SIZE)) / 8U;
pDest = (uint64_t *)(&__STDBYRAM_START);
while (cnt--)
{
*pDest = (uint64_t)0xDEADBEEFCAFEFEEDULL;
pDest++;
}
MC_RGM->DES = MC_RGM_DES_F_POR_MASK; /* Write 1 to clear F_POR */

I can see that the access is translated to use STRD instruction which should generate 64bit write.

Regards,

Lukas

 

 

 

0 项奖励
回复
3,104 次查看
HemantKapoor
Contributor II

Hello Lukas,

 

Your solution worked like a charm.

 

Thanks a ton.

0 项奖励
回复
3,334 次查看
HemantKapoor
Contributor II

 

The hard fault is die to IMPRECISERR and my best guess is that I have limited the int_sram_shareable to 0x00004000-0x80 so somehow RAM region from 0x20443F80 got inaccessible.

 

I don't see how ""unified_bootloader_Demo_V2.0"" is getting away with this.

0 项奖励
回复