/**
*
*
*  Function to initialize BBRAM instance
*
*
* @param	BBRAM instance pointer
*
* @return
*
*	- XST_SUCCESS - In case of Success
*	- XST_FAILURE - If initialization fails
*
* @note
*
*****************************************************************************/
int XilSKey_Bbram_InitData(XilSKey_Bbram *BbramInstancePtr)
{

    u32 Status;

    BbramInstancePtr->ForcePowerCycle		= 	XSK_BBRAM_FORCE_PCYCLE_RECONFIG;
    BbramInstancePtr->JtagDisable			= 	XSK_BBRAM_DISABLE_JTAG_CHAIN;
    BbramInstancePtr->JtagMioTDI 			=	XSK_BBRAM_MIO_JTAG_TDI;
    BbramInstancePtr->JtagMioTDO			=	XSK_BBRAM_MIO_JTAG_TDO;
    BbramInstancePtr->JtagMioTCK			=	XSK_BBRAM_MIO_JTAG_TCK;
    BbramInstancePtr->JtagMioTMS			=	XSK_BBRAM_MIO_JTAG_TMS;
    BbramInstancePtr->JtagMioMuxSel 		=	XSK_BBRAM_MIO_JTAG_MUX_SELECT;
    BbramInstancePtr->JtagMuxSelLineDefVal	=  XSK_BBRAM_MIO_MUX_SEL_DEFAULT_VAL;

    /*
     * Convert key given in xilskey_input.h and
     * assign it to the variable in instance.
     */
    XilSKey_Efuse_ConvertStringToHexBE(XSK_BBRAM_AES_KEY,
                                       &(BbramInstancePtr->AESKey[0]),
                                       XSK_BBRAM_AES_KEY_SIZE_IN_BITS);

    Status = XST_SUCCESS;
    return Status;

}
u32 XilSKey_EfusePs_InitData(XilSKey_EPs *PsInstancePtr)
{
	u32 PsStatus;

	PsStatus = XST_SUCCESS;

    /**
     * Copy the xilskeyinput.h values into PS structure elements
     */
	PsInstancePtr->EnableWriteProtect = XSK_EFUSEPS_ENABLE_WRITE_PROTECT;
	PsInstancePtr->EnableRsaAuth = XSK_EFUSEPS_ENABLE_RSA_AUTH;
	PsInstancePtr->EnableRom128Crc = XSK_EFUSEPS_ENABLE_ROM_128K_CRC;
	PsInstancePtr->EnableRsaKeyHash = XSK_EFUSEPS_ENABLE_RSA_KEY_HASH;

	if (PsInstancePtr->EnableRsaKeyHash == TRUE) {
		/**
		 * Validation of RSA Hash
		 */
		PsStatus = XilSKey_Efuse_ValidateKey(
						(char *)XSK_EFUSEPS_RSA_KEY_HASH_VALUE,
						XSK_EFUSEPL_RSA_KEY_HASH_STRING_SIZE);
		if(PsStatus != XST_SUCCESS)	{
			return PsStatus;
		}

		/**
		 * Convert the input RSA Key Hash string into Hex buffer
		 */
		PsStatus = XilSKey_Efuse_ConvertStringToHexBE(
						XSK_EFUSEPS_RSA_KEY_HASH_VALUE,
						&(PsInstancePtr->RsaKeyHashValue[0]), 64);
		if(PsStatus != XST_SUCCESS)	{
			return PsStatus;
		}
	}
	return PsStatus;
}
static inline u32 XilSKey_EfusePs_ZynqMp_InitData(
				XilSKey_ZynqMpEPs *PsInstancePtr)
{

	u32 PsStatus;

	PsStatus = XST_SUCCESS;

	/*
	 * Copy the xilskey_efuseps_zynqmp_input.h values into
	 * PS eFUSE structure elements
	 */

	/* Secure and control bits for programming */
	PsInstancePtr->PrgrmgSecCtrlBits.AesKeyRead = XSK_EFUSEPS_AES_RD_LOCK;
	PsInstancePtr->PrgrmgSecCtrlBits.AesKeyWrite = XSK_EFUSEPS_AES_WR_LOCK;
	PsInstancePtr->PrgrmgSecCtrlBits.UseAESOnly =
						XSK_EFUSEPs_FORCE_USE_AES_ONLY;
	PsInstancePtr->PrgrmgSecCtrlBits.BbramDisable =
						XSK_EFUSEPS_BBRAM_DISABLE;
	PsInstancePtr->PrgrmgSecCtrlBits.PMUError =
					XSK_EFUSEPS_ERR_OUTOF_PMU_DISABLE;
	PsInstancePtr->PrgrmgSecCtrlBits.JtagDisable = XSK_EFUSEPS_JTAG_DISABLE;
	PsInstancePtr->PrgrmgSecCtrlBits.DFTDisable = XSK_EFUSEPS_DFT_DISABLE;
	PsInstancePtr->PrgrmgSecCtrlBits.ProgGate0 =
					XSK_EFUSEPS_PROG_GATE_0_DISABLE;
	PsInstancePtr->PrgrmgSecCtrlBits.ProgGate1 =
					XSK_EFUSEPS_PROG_GATE_1_DISABLE;
	PsInstancePtr->PrgrmgSecCtrlBits.ProgGate2 =
					XSK_EFUSEPS_PROG_GATE_2_DISABLE;
	PsInstancePtr->PrgrmgSecCtrlBits.SecureLock = XSK_EFUSEPS_SECURE_LOCK;
	PsInstancePtr->PrgrmgSecCtrlBits.RSAEnable = XSK_EFUSEPS_RSA_ENABLE;
	PsInstancePtr->PrgrmgSecCtrlBits.PPK0WrLock = XSK_EFUSEPS_PPK0_WR_LOCK;
	PsInstancePtr->PrgrmgSecCtrlBits.PPK0Revoke = XSK_EFUSEPS_PPK0_REVOKE;
	PsInstancePtr->PrgrmgSecCtrlBits.PPK1WrLock = XSK_EFUSEPS_PPK1_WR_LOCK;
	PsInstancePtr->PrgrmgSecCtrlBits.PPK1Revoke = XSK_EFUSEPS_PPK1_REVOKE;

	/* User control bits */
	PsInstancePtr->PrgrmgSecCtrlBits.UserWrLk0 = XSK_EFUSEPS_USER_WRLK_0;
	PsInstancePtr->PrgrmgSecCtrlBits. UserWrLk1 = XSK_EFUSEPS_USER_WRLK_1;
	PsInstancePtr->PrgrmgSecCtrlBits.UserWrLk2 = XSK_EFUSEPS_USER_WRLK_2;
	PsInstancePtr->PrgrmgSecCtrlBits.UserWrLk3 = XSK_EFUSEPS_USER_WRLK_3;
	PsInstancePtr->PrgrmgSecCtrlBits.UserWrLk4 = XSK_EFUSEPS_USER_WRLK_4;
	PsInstancePtr->PrgrmgSecCtrlBits.UserWrLk5 = XSK_EFUSEPS_USER_WRLK_5;
	PsInstancePtr->PrgrmgSecCtrlBits.UserWrLk6 = XSK_EFUSEPS_USER_WRLK_6;
	PsInstancePtr->PrgrmgSecCtrlBits.UserWrLk7 = XSK_EFUSEPS_USER_WRLK_7;

	/* For writing into eFuse */
	PsInstancePtr->PrgrmAesKey = XSK_EFUSEPS_WRITE_AES_KEY;
	PsInstancePtr->PrgrmUserKey = XSK_EFUSEPS_WRITE_USER_KEY;
	PsInstancePtr->PrgrmPpk0Hash = XSK_EFUSEPS_WRITE_PPK0_HASH;
	PsInstancePtr->PrgrmPpk1Hash = XSK_EFUSEPS_WRITE_PPK1_HASH;
	PsInstancePtr->PrgrmSpkID = XSK_EFUSEPS_WRITE_SPKID;
	PsInstancePtr->PrgrmJtagUserCode = XSK_EFUSEPS_WRITE_JTAG_USERCODE;

	/* Variable for Timer Intialization */
	PsInstancePtr->IntialisedTimer = 0;

	/* Copying PPK hash types */
	PsInstancePtr->IsPpk0Sha3Hash = XSK_EFUSEPS_PPK0_IS_SHA3;
	PsInstancePtr->IsPpk1Sha3Hash = XSK_EFUSEPS_PPK1_IS_SHA3;

	/* Copy the keys to be programmed */
	if (PsInstancePtr->PrgrmUserKey == TRUE) {
		/* Validation of User High Key */
		PsStatus = XilSKey_Efuse_ValidateKey(
				(char *)XSK_EFUSEPS_USER_KEY,
				XSK_EFUSEPS_USER_KEY_STRING_LEN);
		if(PsStatus != XST_SUCCESS) {
			goto ERROR;
		}
		/* Assign the User key [255:0]bits */
		XilSKey_Efuse_ConvertStringToHexLE(
			(char *)XSK_EFUSEPS_USER_KEY ,
			&PsInstancePtr->UserKey[0],
			XSK_EFUSEPS_USER_KEY_LEN_IN_BITS);
	}
	if (PsInstancePtr->PrgrmAesKey == TRUE) {
		/* Validation of AES Key */
		PsStatus = XilSKey_Efuse_ValidateKey(
			(char *)XSK_EFUSEPS_AES_KEY,
			XSK_EFUSEPS_AES_KEY_STRING_LEN);
		if(PsStatus != XST_SUCCESS) {
			goto ERROR;
		}
		/* Assign the AES Key Value */
		XilSKey_Efuse_ConvertStringToHexLE(
			(char *)XSK_EFUSEPS_AES_KEY,
			&PsInstancePtr->AESKey[0],
			XSK_EFUSEPS_AES_KEY_LEN_IN_BITS);
	}

	/* Is PPK0 hash programming is enabled */
	if (PsInstancePtr->PrgrmPpk0Hash == TRUE) {
		/* If Sha3 hash is programming into Efuse PPK0 */
		if (PsInstancePtr->IsPpk0Sha3Hash == TRUE) {
			/* Validation of PPK0 sha3 hash */
			PsStatus = XilSKey_Efuse_ValidateKey(
				(char *)XSK_EFUSEPS_PPK0_HASH,
				XSK_EFUSEPS_PPK_SHA3_HASH_STRING_LEN_96);
			if(PsStatus != XST_SUCCESS) {
				goto ERROR;
			}
			/* Assign the PPK0 sha3 hash */
			XilSKey_Efuse_ConvertStringToHexBE(
				(char *)XSK_EFUSEPS_PPK0_HASH,
				&PsInstancePtr->Ppk0Hash[0],
				XSK_EFUSEPS_PPK_SHA3HASH_LEN_IN_BITS_384);
		}
		/* If Sha2 hash is programming into Efuse PPK0 */
		else {
			/* Validation of PPK0 sha2 hash */
			PsStatus = XilSKey_Efuse_ValidateKey(
				(char *)XSK_EFUSEPS_PPK0_HASH,
				XSK_EFUSEPS_PPK_SHA2_HASH_STRING_LEN_64);
			if(PsStatus != XST_SUCCESS) {
				goto ERROR;
			}
			/* Assign the PPK0 sha3 hash */
			XilSKey_Efuse_ConvertStringToHexBE(
				(char *)XSK_EFUSEPS_PPK0_HASH,
				&PsInstancePtr->Ppk0Hash[0],
				XSK_EFUSEPS_PPK_SHA2HASH_LEN_IN_BITS_256);
		}
	}

	/* Is PPK1 hash programming is enabled */
	if (PsInstancePtr->PrgrmPpk1Hash == TRUE) {
		/* If Sha3 hash is programming into Efuse PPK1 */
		if (PsInstancePtr->IsPpk1Sha3Hash == TRUE) {
			/* Validation of PPK1 sha3 hash */
			PsStatus = XilSKey_Efuse_ValidateKey(
				(char *)XSK_EFUSEPS_PPK1_HASH,
				XSK_EFUSEPS_PPK_SHA3_HASH_STRING_LEN_96);
			if(PsStatus != XST_SUCCESS) {
				goto ERROR;
			}
			/* Assign the PPK1 sha3 hash */
			XilSKey_Efuse_ConvertStringToHexBE(
				(char *)XSK_EFUSEPS_PPK1_HASH,
				&PsInstancePtr->Ppk1Hash[0],
				XSK_EFUSEPS_PPK_SHA3HASH_LEN_IN_BITS_384);
		}
		/* If Sha2 hash is programming into Efuse PPK1 */
		else {
			/* Validation of PPK1 sha2 hash */
			PsStatus = XilSKey_Efuse_ValidateKey(
				(char *)XSK_EFUSEPS_PPK1_HASH,
				XSK_EFUSEPS_PPK_SHA2_HASH_STRING_LEN_64);
			if(PsStatus != XST_SUCCESS) {
				goto ERROR;
			}
			/* Assign the PPK1 sha2 hash */
			XilSKey_Efuse_ConvertStringToHexBE(
				(char *)XSK_EFUSEPS_PPK1_HASH,
				&PsInstancePtr->Ppk1Hash[0],
				XSK_EFUSEPS_PPK_SHA2HASH_LEN_IN_BITS_256);
		}
	}

	if (PsInstancePtr->PrgrmJtagUserCode == TRUE) {
		/* Validation of JTAG user code */
		PsStatus = XilSKey_Efuse_ValidateKey(
				(char *)XSK_EFUSEPS_JTAG_USERCODE,
				XSK_EFUSEPS_JTAG_USER_CODE_STRING_LEN);
		if (PsStatus != XST_SUCCESS) {
			goto ERROR;
		}
		/* Assign the JTAG user code */
		XilSKey_Efuse_ConvertStringToHexLE(
			(char *)XSK_EFUSEPS_JTAG_USERCODE,
			&PsInstancePtr->JtagUserCode[0],
			XSK_EFUSEPS_JTAG_USER_CODE_LEN_IN_BITS);
	}

	if (PsInstancePtr->PrgrmSpkID == TRUE) {
		/* Validation of SPK ID */
		PsStatus = XilSKey_Efuse_ValidateKey(
				(char *)XSK_EFUSEPS_SPK_ID,
				XSK_EFUSEPS_SPK_ID_STRING_LEN);
		if (PsStatus != XST_SUCCESS) {
			goto ERROR;
		}
		/* Assign the JTAG user code */
		XilSKey_Efuse_ConvertStringToHexLE(
			(char *)XSK_EFUSEPS_SPK_ID,
			&PsInstancePtr->SpkId[0],
			XSK_EFUSEPS_SPKID_LEN_IN_BITS);
	}



ERROR:
	return PsStatus;

}