CSEC on S32K118 csec_flash part example

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

CSEC on S32K118 csec_flash part example

2,566 次查看
piotrhawrylo
Contributor II

I am working on S32K118. I am trying to run aes encryption using csec module. 

Followed by manual and this post : https://community.nxp.com/t5/S32-SDK/STATUS-ERROR-on-CSEC-DRV-LoadPlainKey/td-p/1075577    I am trying to run csec_flash part example to run flash for csec.

But I got ACCERR(access error) from FLASH_DRV_EraseAllBlock. 

Here is my flash config and code snippet. : 

static const flash_user_config_t flash1_InitConfig0= {
.PFlashBase = 0x00000000U,
.PFlashSize = 0x00180000U,
.DFlashBase = 0x10000000U,
.EERAMBase = 0x14000000U,
.CallBack = NULL_CALLBACK
};

flash_ssd_config_t flashSSDConfig;

FLASH_DRV_Init(&flash1_InitConfig0, &flashSSDConfig);

FLASH_DRV_EraseAllBlock(&flashSSDConfig);    // <-- ACCERR

Because of this problem I am unable to run csec module means calling : 

FLASH_DRV_Program and FLASH_DRV_DEFlashPartition functions.  

Any thoughts where the problem is? The flash config is wrong? What is the purpose of block erasing?

And the second question:

From manual : 

"After clearing CCIF to launch the Erase All Blocks command, the FTFC erases all
program flash memory, data flash memory, data flash IFR space, emulated EEPROM
backup memory, and FlexRAM, then verifies that all are erased."

 

How I should understand erasing all program and data flash memory in runtime of my application?

 

Thanks in advance, 

Piotr

标签 (1)
8 回复数

2,279 次查看
piotrhawrylo
Contributor II

I ran cse_flash_part example from RAM. Now I have locked flash config registers. : "Protection bytes in flash at addr. 0x400 - 0x40F indicate that readout protection is set". This address quite confuses me, I expect that other area of flash will be locked.  0x400 - 0x40F are flash config registers.

I have above info from debugger, and now I cannot load any program on the device, also only to the RAM memory. 

 This is expected situation?  

I disabled erase before download option, because as I know, I cannot erase flash after partition command.

I am wondering how to go further with configuring csec if I cannot load or connect with device using debugger.

Thanks in advance,

PH

0 项奖励
回复

2,548 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi Piotr,

cse_flash_part example must be executed from RAM memory as mentioned in the user manual. The goal of this example is to reset the flash back to default state and run partition command to enable Emulated EEPROM and CSEc.

Once the partition command is executed (and CSE is enabled by this command), it's not possible to run the Erase All Blocks command again until the partition is destroyed by CMD_DBG_CHAL and CMD_DBG_AUTH commands:

lukaszadrapa_0-1646997363564.png

 

Most likely, this is the source of problem you have. I guess that you have the cse_flash_part already executed.

To continue with CSE, you do not need to erase the flash again. Just go ahead and use example csec_keyconfig.

If you want to destroy the partition as I mentioned above, run csec_keyconfig again but change ERASE_ALL_KEYS to 1:

#define ERASE_ALL_KEYS 1

You can find this in main.c file.

If the device was already partitioned by someone else, it's necessary to know MASTER_ECU_KEY, otherwise you won't be able to destroy the partition.

Regards,

Lukas

 

2,521 次查看
piotrhawrylo
Contributor II

Hi Lukas, 

Thanks for answer. 

I have one more question. My understanding is that on manufactory, we need to run csec_flash_part code before loading firmware to flash memory. Otherwise it will be erased on the first run. 

I am correct? 

BR,

Piotr

0 项奖励
回复

2,506 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Yes, that's correct.

Regards,

Lukas

0 项奖励
回复

2,258 次查看
piotrhawrylo
Contributor II

I ran cse_flash_part example from RAM. Now I have locked flash config registers. : "Protection bytes in flash at addr. 0x400 - 0x40F indicate that readout protection is set". This address quite confuses me, I expect that other area of flash will be locked.  0x400 - 0x40F are flash config registers.

I have above info from debugger, and now I cannot load any program on the device, also only to the RAM memory. 

 This is expected situation?  

I disabled erase before download option, because as I know, I cannot erase flash after partition command.

I am wondering how to go further with configuring csec if I cannot load or connect with device using debugger.

Thanks in advance,

PH

0 项奖励
回复

2,237 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

"I have above info from debugger, and now I cannot load any program on the device, also only to the RAM memory. "

I'm not sure if I can understand this question - are you able to load a program to the RAM memory or not?

If the partition is set (CSE is enabled) AND if flash configuration field is somehow corrupted AND if you can't establish JTAG/SWD connection ever, I'm afraid that there's no way to recover.

If you are able to load a program to the RAM, run csec_keyconfig project with ERASE_ALL_KEYS set to 1.

Regards,

Lukas

0 项奖励
回复

2,235 次查看
piotrhawrylo
Contributor II

Hi,

I can't load program to the RAM also. 

So from your answer I understand that this is not expected situation that flash config fields are locked? 

Do you have any thoughts why after running cse_flash_part example from RAM device is corrupted? 

There is possibility to run csec using simulator of device? 

Thanks,

BR,

Piotr

 

0 项奖励
回复

2,230 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

No, this is not expected situation. I did a lot of tests with these projects, testing all possible situations and combinations, also using different debuggers and it was always working as expected. Not sure what happened on your side.

There's no simulator for this device.

Regards,

Lukas

0 项奖励
回复