xilskey
Vitis Drivers API Documentation
xilskey_utils.c File Reference

Overview

Note
None.

MODIFICATION HISTORY:

Ver Who Date Changes


1.00a rpoolla 04/26/13 First release 2.00 hk 22/01/14 Corrected PL voltage checks to VCCINT and VCCAUX. CR#768077 2.1 kvn 04/01/15 Fixed warnings. CR#716453. 3.00 vns 31/07/15 Added efuse functionality for Ultrascale. 4.0 vns 10/01/15 Modified conditional compilation to support ZynqMp platform also. Added new API Xsk_Ceil Modified Xilskey_CrcCalculation() API for providing support for efuse ZynqMp also. 6.0 vns 07/07/16 Modified XilSKey_Timer_Intialise API to initialize TimerTicks to 10us. As Hardware module only takes care of programming time(5us), through software we only need to control hardware module. Modified sysmon read to 16 bit resolution as sysmon driver has modified conversion formulae to 16 bit resolution. vns 07/18/16 Initialized sysmonpsu driver and added XilSKey_ZynqMP_EfusePs_ReadSysmonVol and XilSKey_ZynqMP_EfusePs_ReadSysmonTemp functions 6.6 vns 06/06/18 Added doxygen tags 6.7 arc 01/05/19 Fixed MISRA-C violations. vns 02/09/19 Fixed buffer overflow access in XilSKey_Efuse_ConvertStringToHexLE() arc 25/02/19 Added asserts for pointer parameter for NULL verification Fixed Length parameter as length in bits for XilSKey_Efuse_ConvertStringToHexBE and added length validations arc 03/13/19 Added assert to validate lengths in XilSKey_Efuse_ValidateKey() arc 03/15/19 Modified initial default status value as XST_FAILURE 6.7 psl 03/21/19 Fixed MISRA-C violation. vns 03/23/19 Fixed CRC calculation for Ultra plus arc 04/04/19 Fixed CPP warnings. 6.8 psl 06/07/19 Added doxygen tags. psl 06/25/19 Fixed Coverity warnings. psl 06/28/19 Added doxygen tags. psl 07/29/19 Fixed MISRA-C violation. vns 08/29/19 Initialized Status variables mmd 07/31/19 Avoided reconfiguration of sysmon, if it is in use 6.9 kpt 02/16/20 Fixed coverity warnings 02/27/20 Replaced XSYSMON_DEVICE_ID with XSYSMON_PSU_DEVICE_ID vns 03/18/20 Fixed Armcc compilation errors 7.0 am 10/04/20 Resolved MISRA C violations 7.1 am 11/26/20 Resolved Coverity warnings kpt 03/17/21 Corrected error code when VCCINT levels are out of range in XilSKey_ZynqMp_EfusePs_Temp_Vol_Checks 7.2 am 07/13/21 Fixed doxygen warnings 7.5 ng 07/13/23 added SDT support

Functions

u32 XilSKey_EfusePs_XAdcInit (void)
 This function is used to initialize the XADC driver. More...
 
void XilSKey_EfusePs_XAdcReadTemperatureAndVoltage (XSKEfusePs_XAdc *XAdcInstancePtr)
 This function reads current value of the temperature from sysmon. More...
 
u32 XilSKey_ZynqMp_EfusePs_Temp_Vol_Checks (void)
 This function checks temperature and voltage ranges of ZynqMP to access PS eFUSE. More...
 
void XilSKey_Efuse_StartTimer (void)
 Initializes the global timer & starts it. More...
 
u64 XilSKey_Efuse_GetTime (void)
 Returns the timer ticks from start of timer to till now. More...
 
void XilSKey_Efuse_SetTimeOut (volatile u64 *t, u64 us)
 Calculates the timer ticks to wait to set the time out. More...
 
u8 XilSKey_Efuse_IsTimerExpired (u64 t)
 Checks whether the timer has been expired or not. More...
 
u32 XilSKey_Efuse_ConvertStringToHexBE (const char *Str, u8 *Buf, u32 Len)
 Converts the string into the equivalent Hex buffer. More...
 
u32 XilSKey_Efuse_ConvertStringToHexLE (const char *Str, u8 *Buf, u32 Len)
 Converts the string into the equivalent Hex buffer. More...
 
void XilSKey_EfusePs_ConvertBytesBeToLe (const u8 *Be, u8 *Le, u32 Len)
 This function is used to convert the Big Endian Byte data to Little Endian Byte data For ex: 1234567890abcdef -> 78563412efcdab90. More...
 
void XilSKey_Efuse_ConvertBitsToBytes (const u8 *Bits, u8 *Bytes, u32 Len)
 Convert the Bits to Bytes in Little Endian format Ex: 0x5C -> {0, 0, 1, 1, 1, 0, 1, 0}. More...
 
void XilSKey_EfusePs_ConvertBytesToBits (const u8 *Bytes, u8 *Bits, u32 Len)
 Convert the Bytes to Bits in little endian format 0th byte is LSB, 7th byte is MSB Ex: {0, 0, 1, 1, 1, 0, 1, 0} -> 0x5C. More...
 
u32 XilSKey_Efuse_ValidateKey (const char *Key, u32 Len)
 Validate the key for proper characters & proper length. More...
 
u32 XilSKey_Efuse_IsValidChar (const char *c)
 Checks whether the passed character is a valid hash key character. More...
 
u32 XilSKey_Timer_Intialise (void)
 This API initializes the Timer based on platform. More...
 
u32 XilSKey_CrcCalculation (const u8 *Key)
 This function Calculates CRC value based on hexadecimal string passed. More...
 
u32 XilSKey_RowCrcCalculation (u32 PrevCRC, u32 Data, u32 Addr)
 Calculates CRC value for each row of AES key. More...
 
u32 XilSKey_Efuse_ReverseHex (u32 Input)
 This API reverse the value. More...
 
u32 XilSkey_CrcCalculation_AesKey (const u8 *Key)
 Calculates CRC value of the provided key. More...
 

Variables

u32 TimerTicksfor1000ns
 Global Variable for 10 micro secs for microblaze. More...
 

Function Documentation

void XilSKey_Efuse_ConvertBitsToBytes ( const u8 *  Bits,
u8 *  Bytes,
u32  Len 
)

Convert the Bits to Bytes in Little Endian format Ex: 0x5C -> {0, 0, 1, 1, 1, 0, 1, 0}.

Parameters
BitsInput Buffer.
Bytesis Output buffer.
Lenof the input buffer in bits
Returns
None Test Cases: Input with All Zeroes Input with All Ones Input Little Endian (General Cases ) Input Check Big Endian - False case Check for Len not a multiple of 8 Check for Len 0 Memory Bounds of buffer checking

Make sure the bytes array is 0'ed first.

Convert 8 Bit One Byte to 1 Bit 8 Bytes

Convert from LSB -> MSB - Little Endian

If len is not Byte aligned

Referenced by XilSKey_ZynqMp_EfusePs_Write(), XilSKey_ZynqMp_EfusePs_WritePufAux(), XilSKey_ZynqMp_EfusePs_WritePufChash(), and XilSKey_ZynqMp_EfusePs_WritePufHelprData().

u32 XilSKey_Efuse_ConvertStringToHexBE ( const char *  Str,
u8 *  Buf,
u32  Len 
)

Converts the string into the equivalent Hex buffer.

Function used to convert the string to Hex in Little Endian format.

 Ex: "abc123" -> {0xab, 0xc1, 0x23}
Parameters
Stris a Input String. Will support the lower and upper case values. Value should be between 0-9, a-f and A-F
Bufis Output buffer.
Lenof the input string in bits and it should have even values
Returns
  • XST_SUCCESS no errors occurred.
  • XST_FAILURE an error when input parameters are not valid
  • an error when input buffer has invalid values

TDD Test Cases: —Initialization— Len is odd Len is zero Str is NULL Buf is NULL —Functionality— Str input with only numbers Str input with All values in A-F Str input with All values in a-f Str input with values in a-f, 0-9, A-F Str input with values in a-z, 0-9, A-Z Boundary Cases Memory Bounds of buffer checking

Check the parameters

Len has to be multiple of 2

Convert char to nibble

Convert char to nibble

Merge upper and lower nibble to Hex

Error converting Lower nibble

Error converting Upper nibble

Converted upper and lower nibbles

References XSK_EFUSEPS_ERROR_INVALID_PARAM, XSK_EFUSEPS_ERROR_PARAMETER_NULL, and XSK_EFUSEPS_ERROR_STRING_INVALID.

Referenced by XilSKey_Bbram_InitData(), XilSKey_CrcCalculation(), and XilSKey_EfusePs_InitData().

u32 XilSKey_Efuse_ConvertStringToHexLE ( const char *  Str,
u8 *  Buf,
u32  Len 
)

Converts the string into the equivalent Hex buffer.

Function used to convert the string to Hex in Little Endian format.

 Ex: "abc123" -> {0x23, 0xc1, 0xab}
Parameters
Stris a Input String. Will support the lower and upper case values. Value should be between 0-9, a-f and A-F
Bufis Output buffer.
Lenof the input string in bits and it should have even values
Returns
  • XST_SUCCESS no errors occurred.
  • XST_FAILURE an error when input parameters are not valid
  • an error when input buffer has invalid values

TDD Test Cases: —Initialization— Len is odd Len is zero Str is NULL Buf is NULL —Functionality— Str input with only numbers Str input with All values in A-F Str input with All values in a-f Str input with values in a-f, 0-9, A-F Str input with values in a-z, 0-9, A-Z Boundary Cases Memory Bounds of buffer checking

Check the parameters

Len has to be multiple of 2

Convert char to nibble

Convert char to nibble

Merge upper and lower nibble to Hex

Error converting Lower nibble

Error converting Upper nibble

Converted upper and lower nibbles

References XSK_EFUSEPS_ERROR_INVALID_PARAM, XSK_EFUSEPS_ERROR_PARAMETER_NULL, and XSK_EFUSEPS_ERROR_STRING_INVALID.

Referenced by main(), and XilSKey_EfusePl_InitData().

u64 XilSKey_Efuse_GetTime ( void  )

Returns the timer ticks from start of timer to till now.

Returns
  t - Timer ticks lapsed till now.
Note
None.

Referenced by XilSKey_Efuse_IsTimerExpired(), and XilSKey_Efuse_SetTimeOut().

u8 XilSKey_Efuse_IsTimerExpired ( u64  t)

Checks whether the timer has been expired or not.

Parameters
t- timeout value in us
Returns
  t_end - Returns the global timer value in case of timer expired
Note
None.

References XilSKey_Efuse_GetTime().

Referenced by Bbram_Init(), JtagWrite(), JtagWrite_Ultrascale(), and XilSKey_EfusePs_WriteEfuseBit().

u32 XilSKey_Efuse_IsValidChar ( const char *  c)

Checks whether the passed character is a valid hash key character.

Parameters
c- Character to check proper value
Returns
XST_SUCCESS - In case of Success XST_FAILURE - In case of Failure

Referenced by XilSKey_Efuse_ValidateKey().

u32 XilSKey_Efuse_ReverseHex ( u32  Input)

This API reverse the value.

Parameters
Inputis a 32 bit variable
Returns
Reverse the given value.
Note
None.

Referenced by JtagRead_Status_Ultrascale().

void XilSKey_Efuse_SetTimeOut ( volatile u64 *  t,
u64  us 
)

Calculates the timer ticks to wait to set the time out.

Parameters
t- timer ticks to wait to set the timeout
us- Timeout period in us
Returns
None.
Note
None.

us: time to wait in microseconds. Convert to clock ticks and add to current time.

References XilSKey_Efuse_GetTime().

Referenced by Bbram_Init(), JtagWrite(), and XilSKey_EfusePs_WriteEfuseBit().

void XilSKey_Efuse_StartTimer ( void  )

Initializes the global timer & starts it.

Calculates the timer ticks for 1us.

Returns
  None
Note
None.

Referenced by JtagWrite_Ultrascale(), and XilSKey_EfusePs_Write().

u32 XilSKey_Efuse_ValidateKey ( const char *  Key,
u32  Len 
)

Validate the key for proper characters & proper length.

Function used to validate the AES & RSA key provided as input.

Parameters
Key- Hash Key
Len- Valid length of key
Returns
XST_SUCCESS - In case of Success XST_FAILURE - In case of Failure

Make sure the key has valid length

Make sure the key has valid characters

References XilSKey_Efuse_IsValidChar(), XSK_EFUSEPL_ERROR_KEY_VALIDATION, XSK_EFUSEPL_ERROR_NONE, XSK_EFUSEPL_ERROR_NOT_VALID_KEY_CHAR, and XSK_EFUSEPL_ERROR_NOT_VALID_KEY_LENGTH.

Referenced by XilSKey_EfusePl_InitData(), and XilSKey_EfusePs_InitData().

void XilSKey_EfusePs_ConvertBytesBeToLe ( const u8 *  Be,
u8 *  Le,
u32  Len 
)

This function is used to convert the Big Endian Byte data to Little Endian Byte data For ex: 1234567890abcdef -> 78563412efcdab90.

Parameters
BeBig endian data
LeLittle endian data
LenLength of data to be converted and it should be in number of words (multiple of 4 bytes)
Returns
None.

TDD Test Cases:

Referenced by XilSKey_ZynqMp_EfusePs_ReadPpk0Hash(), XilSKey_ZynqMp_EfusePs_ReadPpk1Hash(), and XilSKey_ZynqMp_EfusePs_Write().

void XilSKey_EfusePs_ConvertBytesToBits ( const u8 *  Bytes,
u8 *  Bits,
u32  Len 
)

Convert the Bytes to Bits in little endian format 0th byte is LSB, 7th byte is MSB Ex: {0, 0, 1, 1, 1, 0, 1, 0} -> 0x5C.

Parameters
BytesInput Buffer.
Bitsis Output buffer.
Lenof the input buffer.
Returns
None Test Cases: Input with All Zeroes Input with All Ones Input Little Endian (General Cases ) Input Check Big Endian - False case Check for Len not a multiple of 8 Check for Len 0 Memory Bounds of buffer checking

Make sure the bits array is 0 first.

Convert 1 Bit 8 Bytes to 8 Bit 1 Byte

Store from LSB -> MSB - Little Endian

If Len is not Byte aligned

u32 XilSKey_EfusePs_XAdcInit ( void  )

This function is used to initialize the XADC driver.

Returns
  • XST_SUCCESS in case of no errors.
  • XSK_EFUSEPS_ERROR_XADC_CONFIG Error occurred with XADC config.
  • XSK_EFUSEPS_ERROR_XADC_INITIALIZE Error occurred while XADC initialization
  • XSK_EFUSEPS_ERROR_XADC_SELF_TEST Error occurred in XADC self test.

TDD Cases:

References XSK_EFUSEPS_ERROR_XADC_CONFIG, XSK_EFUSEPS_ERROR_XADC_INITIALIZE, and XSK_EFUSEPS_ERROR_XADC_SELF_TEST.

Referenced by XilSKey_EfusePs_Read(), XilSKey_EfusePs_Write(), and XilSKey_ZynqMp_EfusePs_Init().

void XilSKey_EfusePs_XAdcReadTemperatureAndVoltage ( XSKEfusePs_XAdc *  XAdcInstancePtr)

This function reads current value of the temperature from sysmon.

Parameters
XAdcInstancePtrPointer to the XSKEfusePs_XAdc.
Returns
None
Note
Read temperature will be stored in XSKEfusePS_XAdc pointer's temperature This function is used to copy the min, max and current value of the temperature and voltage which are read from XADC.
Parameters
XAdcInstancePtrPointer to the XSKEfusePs_XAdc. User has to fill the VType to specify the type of voltage. Valid values for VType are
  • XSK_EFUSEPS_VPINT
  • XSK_EFUSEPS_VPDRO
  • XSK_EFUSEPS_VPAUX
  • XSK_EFUSEPS_VINT
  • XSK_EFUSEPS_VAUX
Returns
none

TDD Cases:

References Jtag_Read_Sysmon().

u32 XilSKey_RowCrcCalculation ( u32  PrevCRC,
u32  Data,
u32  Addr 
)

Calculates CRC value for each row of AES key.

Parameters
PrevCRCholds the prev row's CRC.
Dataholds the present row's key.
Addrstores the current row number.
Returns
Crc of current row.
Note
None.

Referenced by XilSKey_CrcCalculation(), and XilSkey_CrcCalculation_AesKey().

u32 XilSKey_Timer_Intialise ( void  )

This API initializes the Timer based on platform.

Returns
RefClk will be returned.
Note
None.

References TimerTicksfor1000ns.

Referenced by XilSKey_EfusePs_Read(), and XilSKey_EfusePs_Write().

u32 XilSKey_ZynqMp_EfusePs_Temp_Vol_Checks ( void  )

This function checks temperature and voltage ranges of ZynqMP to access PS eFUSE.

Returns
Error code: On failure XST_SUCCESS on Success
Note
This function returns XST_SUCCESS if we try to access eFUSE on the Remus, as Sysmon access is not permitted on Remus.

Check the temperature and voltage(VCC_AUX and VCC_PINT_LP)

References XSK_EFUSEPS_ERROR_READ_TMEPERATURE_OUT_OF_RANGE, XSK_EFUSEPS_ERROR_READ_VCCPAUX_VOLTAGE_OUT_OF_RANGE, and XSK_EFUSEPS_ERROR_READ_VCCPINT_VOLTAGE_OUT_OF_RANGE.

Referenced by XilSKey_ZynqMp_EfusePs_Write(), XilSKey_ZynqMp_EfusePs_WritePufAux(), XilSKey_ZynqMp_EfusePs_WritePufChash(), and XilSKey_ZynqMp_EfusePs_WritePufHelprData().

Variable Documentation

u32 TimerTicksfor1000ns

Global Variable for 10 micro secs for microblaze.

Referenced by JtagWrite_Ultrascale(), and XilSKey_Timer_Intialise().