lib/sw_apps/zynqmp_fsbl/src/xfsbl_tpm_util.c
u32 XFsbl_TpmDataTransfer(u8* TxBuf, u8* RxBuf, u16 Txlen)
{
	u32 Status = XFSBL_FAILURE;
	u8 StatusVal = 0U;
	u16 RxLen;

	/* Set command ready request */
	Status = XFsbl_TpmStatusSet(XFSBL_TPM_STS_CMD_READY);
	if (Status != XST_SUCCESS) {
		goto END;
	}

	do {
		/* Check for command ready status */
		Status = XFsbl_TpmStatusGet(&StatusVal);
		if (Status != XST_SUCCESS) {
			goto END;
		}
	} while ((StatusVal & XFSBL_TPM_STS_CMD_READY) == 0U);

	/* Write Data to device */
	Status = XFsbl_TpmFifoWrite(TxBuf, Txlen);
	if (Status != XST_SUCCESS) {
		goto END;
	}

	/* Set command to go */
	Status = XFsbl_TpmStatusSet(XFSBL_TPM_STS_GO);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	StatusVal = 0U;
	do {
		/* Check for command ready and valid */
		Status = XFsbl_TpmStatusGet(&StatusVal);
		if (Status != XST_SUCCESS) {
			goto END;
		}
	} while ((StatusVal &
		(XFSBL_TPM_STS_VALID | XFSBL_TPM_STS_DATA_AVAIL)) !=
		(XFSBL_TPM_STS_VALID | XFSBL_TPM_STS_DATA_AVAIL));

	/* Read Data from device */
	Status = XFsbl_TpmFifoRead(RxBuf, XFSBL_TPM_RX_HEAD_SIZE);
	if (Status != XST_SUCCESS) {
		goto END;
	}

	RxLen = RxBuf[XFSBL_TPM_DATA_SIZE_INDEX];
	if (RxLen > XFSBL_TPM_RESP_MAX_SIZE) {
		Status = XST_FAILURE;
		goto END;
	}

	if (RxBuf[XFSBL_TPM_DATA_SIZE_INDEX] > XFSBL_TPM_RX_HEAD_SIZE)
	{
		RxLen = RxBuf[XFSBL_TPM_DATA_SIZE_INDEX] - XFSBL_TPM_RX_HEAD_SIZE;
		Status = XFsbl_TpmFifoRead(&RxBuf[XFSBL_TPM_RX_HEAD_SIZE],
			RxLen);
		if (Status != XST_SUCCESS) {
			goto END;
		}
	}

END:
	return Status;
}
/*****************************************************************************/
/**
*
* This function sends a command to TPM and reads response.
*
* @param	TxBuf is pointer to transmit buffer
* @param	RxBuf is pointer to receive buffer
* @param	Txlen is data transfer length
*
* @return	XFSBL_SUCCESS if successful, else error code.
*
******************************************************************************/
This function sends a command to TPM and reads response.
This function sends a command to TPM and reads response .
u32 XFsbl_TpmDataTransfer(u8* TxBuf, u8* RxBuf, u16 Txlen)
{
	u32 Status = XFSBL_FAILURE;
	u8 StatusVal = 0U;
	u16 RxLen;
	Status = XFsbl_TpmStatusSet(XFSBL_TPM_STS_CMD_READY);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	do {
		Status = XFsbl_TpmStatusGet(&StatusVal);
		if (Status != XST_SUCCESS) {
			goto END;
		}
	} while ((StatusVal & XFSBL_TPM_STS_CMD_READY) == 0U);
	Status = XFsbl_TpmFifoWrite(TxBuf, Txlen);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	Status = XFsbl_TpmStatusSet(XFSBL_TPM_STS_GO);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	StatusVal = 0U;
	do {
		Status = XFsbl_TpmStatusGet(&StatusVal);
		if (Status != XST_SUCCESS) {
			goto END;
		}
	} while ((StatusVal &
		(XFSBL_TPM_STS_VALID | XFSBL_TPM_STS_DATA_AVAIL)) !=
		(XFSBL_TPM_STS_VALID | XFSBL_TPM_STS_DATA_AVAIL));
	Status = XFsbl_TpmFifoRead(RxBuf, XFSBL_TPM_RX_HEAD_SIZE);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	RxLen = RxBuf[XFSBL_TPM_DATA_SIZE_INDEX];
	if (RxLen > XFSBL_TPM_RESP_MAX_SIZE) {
		Status = XST_FAILURE;
		goto END;
	}
	if (RxBuf[XFSBL_TPM_DATA_SIZE_INDEX] > XFSBL_TPM_RX_HEAD_SIZE)
	{
		RxLen = RxBuf[XFSBL_TPM_DATA_SIZE_INDEX] - XFSBL_TPM_RX_HEAD_SIZE;
		Status = XFsbl_TpmFifoRead(&RxBuf[XFSBL_TPM_RX_HEAD_SIZE],
			RxLen);
		if (Status != XST_SUCCESS) {
			goto END;
		}
	}
END:
	return Status;
}
u32 XFsbl_TpmDataTransfer ( u8 * TxBuf , u8 * RxBuf , u16 Txlen ) { u32 Status = XFSBL_FAILURE ; u8 StatusVal = 0U ; u16 RxLen ; Status = XFsbl_TpmStatusSet ( XFSBL_TPM_STS_CMD_READY ) ; if ( Status != XST_SUCCESS ) { goto END ; } do { Status = XFsbl_TpmStatusGet ( & StatusVal ) ; if ( Status != XST_SUCCESS ) { goto END ; } } while ( ( StatusVal & XFSBL_TPM_STS_CMD_READY ) == 0U ) ; Status = XFsbl_TpmFifoWrite ( TxBuf , Txlen ) ; if ( Status != XST_SUCCESS ) { goto END ; } Status = XFsbl_TpmStatusSet ( XFSBL_TPM_STS_GO ) ; if ( Status != XST_SUCCESS ) { goto END ; } StatusVal = 0U ; do { Status = XFsbl_TpmStatusGet ( & StatusVal ) ; if ( Status != XST_SUCCESS ) { goto END ; } } while ( ( StatusVal & ( XFSBL_TPM_STS_VALID | XFSBL_TPM_STS_DATA_AVAIL ) ) != ( XFSBL_TPM_STS_VALID | XFSBL_TPM_STS_DATA_AVAIL ) ) ; Status = XFsbl_TpmFifoRead ( RxBuf , XFSBL_TPM_RX_HEAD_SIZE ) ; if ( Status != XST_SUCCESS ) { goto END ; } RxLen = RxBuf [ XFSBL_TPM_DATA_SIZE_INDEX ] ; if ( RxLen > XFSBL_TPM_RESP_MAX_SIZE ) { Status = XST_FAILURE ; goto END ; } if ( RxBuf [ XFSBL_TPM_DATA_SIZE_INDEX ] > XFSBL_TPM_RX_HEAD_SIZE ) { RxLen = RxBuf [ XFSBL_TPM_DATA_SIZE_INDEX ] - XFSBL_TPM_RX_HEAD_SIZE ; Status = XFsbl_TpmFifoRead ( & RxBuf [ XFSBL_TPM_RX_HEAD_SIZE ] , RxLen ) ; if ( Status != XST_SUCCESS ) { goto END ; } } END : return Status ; }
This function sends a command to TPM and reads response.
This function sends a command to TPM and reads response .
/* Set command ready request */ /* Check for command ready status */ /* Write Data to device */ /* Set command to go */ /* Check for command ready and valid */ /* Read Data from device */