I want to generate random number in S32K144.
As I know, FLASH_DRV_EraseAllBlock must be used for CSEC.
But in FLASH_DRV_EraseAllBlock is not working in IAR.
I refer to the sample code of S32 Design Studio.
and I convert to the IAR project.
Below is the code for CSEC
status_t tStatus = STATUS_SUCCESS;
/* Initialize CSEc driver */
CSEC_DRV_Init(&csecState);
/* Init flash */
tStatus = FLASH_DRV_Init(&Flash_InitConfig0, &flashSSDConfig);
DEV_ASSERT(tStatus == STATUS_SUCCESS);
#if 1
if(tStatus != STATUS_SUCCESS)
{
return STATUS_ERROR;
}
if (flashSSDConfig.EEESize == 0)
{
#ifndef DBG_FLASH_TARGET
uint32_t address;
uint32_t size;
#if (FEATURE_FLS_HAS_PROGRAM_PHRASE_CMD == 1u)
uint8_t unsecure_key[FTFx_PHRASE_SIZE] = {0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFEu, 0xFFu, 0xFFu, 0xFFu};
#else /* FEATURE_FLASH_HAS_PROGRAM_LONGWORD_CMD */
uint8_t unsecure_key[FTFx_LONGWORD_SIZE] = {0xFEu, 0xFFu, 0xFFu, 0xFFu};
#endif /* FEATURE_FLS_HAS_PROGRAM_PHRASE_CMD */
/* First, erase all Flash blocks to ensure the IFR region is blank
* before partitioning FlexNVM and FlexRAM */
tStatus = FLASH_DRV_EraseAllBlock(&flashSSDConfig);
APP_DebugPrintf("-->Enter InitFlash status[%d]--<\n",tStatus);
if(tStatus != STATUS_SUCCESS)
{
return STATUS_ERROR;
}
/* Reprogram secure byte in Flash configuration field */
#if (FEATURE_FLS_HAS_PROGRAM_PHRASE_CMD == 1u)
address = 0x408u;
size = FTFx_PHRASE_SIZE;
#else /* FEATURE_FLASH_HAS_PROGRAM_LONGWORD_CMD == 1u */
address = 0x40Cu;
size = FTFx_LONGWORD_SIZE;
#endif /* FEATURE_FLS_HAS_PROGRAM_PHRASE_CMD */
tStatus = FLASH_DRV_Program(&flashSSDConfig, address, size, unsecure_key);
if(tStatus != STATUS_SUCCESS)
{
return STATUS_ERROR;
}
tStatus = FLASH_DRV_DEFlashPartition(&flashSSDConfig, 0x2, 0x4, 0x3, false, true);
if(tStatus != STATUS_SUCCESS)
{
return STATUS_ERROR;
}
#else /*DBG_FLASH_TARGET*/
tStatus = STATUS_ERROR;
#endif
}
#endif
return tStatus;
Solved! Go to Solution.
Which part number do you have exactly? My expectation was that you have derivative with Security option:
Regards,
Lukas
Hi,
if FLASH_DRV_EraseAllBlock doesn't work, the flash is already partitioned / CSEc is enabled. The only solution is to reset the device back to factory state using DBG_CHAL and DBG_AUTH commands with knowledge of MASTER_ECU_KEY:
You can take a look at eraseKeys() function in this example in SDK:
c:\NXP\S32DS.3.4\S32DS\software\S32SDK_S32K1XX_RTM_4.0.2\examples\S32K144\driver_examples\system\csec_keyconfig\
Regards,
Lukas
this issue is not resolved yet.
FLASH_DRV_DEFlashPartition is not working in case the size of key is 1,2,3.
I don't know why this api is working in case the size of key is only 0.
And I alreay know the example which you let me know
Thanks.
Thank you for your response.
In current, FLASH_DRV_EraseAllBlock is working well.
But below api is not working in case uCSEcKeySize is 0x3.
In case the size of key is 0, this api is working well.
tStatus = FLASH_DRV_DEFlashPartition(&flashSSDConfig, 0x02u, 0x04u, 0x3, false, true);
-->FLASH_DRV_DEFlashPartition--<
-->Enter FLASH_DRV_DEFlashPartition--<
-->FLASH_DRV_CommandSequence is called<
-->Enter FLASH_DRV_CommandSequence--<
-->Enter Wait till CCIF bit is set--<
-->Enter FLASH_DRV_CommandSequence status[1]--<
I am implementing using IAR(S32K144_64_ram.icf).
Could you please give me help?
Hi,
the same parameters are used in this example and it works:
c:\NXP\S32DS.3.4\S32DS\software\S32SDK_S32K1XX_RTM_4.0.2\examples\S32K144\driver_examples\system\csec_keyconfig\
What does it mean that it is not working? Does it crash completely? Is the device reset? Is debug connection lost? Or what is returned by the function? If you step the function, can you see if correct parameters are written to FCCOB registers? It could be related to some issue in IAR compiler.
Regards,
Lukas
this issue is not resolved yet.
FLASH_DRV_DEFlashPartition is not working in case the size of key is 1,2,3.
I don't know why this api is working in case the size of key is only 0.
And I alreay know the example which you let me know
Thanks.
The project you shared earlier does not contain elf file. Because I do not have IAR compiler, I can't test it on my side. If you want me to test it, please share the project again but make sure the elf file is present.
Because it works in gcc, it looks like some issue in IAR toolchain.
Regards,
Lukas
Hi @HyunungPark
I'm confused - is this project supposed to be executed from flash? I can see Debug_FLASH folder only in your project, not Debug_RAM. And it can't be compiled for RAM.
I'm asking because FLASH_DRV_EraseAllBlock is called there and it will erase everything.
I tested this project now (executed from RAM):
c:\NXP\S32DS.3.4\S32DS\software\S32SDK_S32K1XX_RTM_4.0.2\examples\S32K144\driver_examples\system\csec_keyconfig\
... and it works as expected when calling:
FLASH_DRV_DEFlashPartition(&flashSSDConfig, 0x2, 0x4, 0x3, false, true);
Regards,
Lukas
I know what the application must be ran from ram for csec key.
So I implemented to run from ram using iar tool.
I will release the project to run from ram based on S32 design studio.
BRs.
Hyunung Park
I change to run the application from ram.
Please find the attached file.
In fact, I think that there are not any problems with the code which I send you.
It is code for the real board. So it sets the configuration like clock etc.
But I don't know why "FLASH_DRV_DEFlashPartition" api is not working.
BRs.
Hyunung Park
I find that FTFx_FSTAT is FTFx_FSTAT_ACCERR_MASK when FLASH_DRV_DEFlashPartition api runs.
what should i do to resolve this issue?
BRs.
Hyunung Park
It works on my side. Most likely, the flash is already partitioned when you are executing this code. These are the reasons why ACCERR can be set:
Only the highlighted one makes sense in this case.
If CSEc is already enabled by partition command, EraseAllBlocks command will not help here (it should return ACCERR too). It doesn't matter if keys were loaded or not. Once the flash is partitioned and Key Size is different from 0, it is necessary to use CMD_DBG_CHAL and CMD_DBG_AUTH commands to destroy the partition. For this, you need to know MASTER_ECU_KEY.
If MASTER_ECU_KEY was not loaded yet, it is necessary to load and then you can use CMD_DBG_CHAL and CMD_DBG_AUTH commands. There's no other way.
You can check Flash Configuration Register 1 (FCFG1) in SIM module to see if the device is partitioned or not.
Regards,
Lukas
Currently, FLASH_DRV_DEFlashPartition is working in case the size of the key is only 0.
I want to know why this api is not working in case of the size of the key is 1 or 2 or 3.
and the device is halted in case CESc api runs like CSEC_DRV_InitRNG.
CMD_DBG_CHAL and CMD_DBG_AUTH commands are not working like csec_keyconfig_s32k144.
It seems that CSEc is not working in my device.
Which part number do you have exactly? My expectation was that you have derivative with Security option:
Regards,
Lukas
Hi.
The chip which I use supports the security.
Thank you for your support.
BRs.
Hyunung Park
When eraseKeys api runs to erase the partition memory, the below step is halted.
eraseKeys->CSEC_DRV_InitRNG -> CSEC_WriteCommandHeader.
Could you please give me any help?
BRs.
Hyunung Park
Hi.
I think that FLASH_DRV_DEFlashPartition is not working in case the size of the key is 1 or 2 or 3.
So I cannot use csec function when the size of the key is 0.
Is there any condition to do the partition for csec?
BRs.
Hyunung Park
I am implementing using the real board.
and the board is not the evaluation board but the commercial board.
Is it possible to test the file if I send you elf file built using GCC compiler?
BRs.
Hyunung Park