#include <Typedef.h> | |
#include <predefines.h> | |
#include <Errors.h> | |
#include "GEU.h" | |
#include "GEU_FuseReadMethods.h" | |
#include "GEU_Provisioning.h" | |
// returns number of ones set in value | |
UINT_T countOnes(UINT_T value) | |
{ | |
UINT_T i=0; | |
for(i=0;value;i++) | |
value &=(value-1); | |
return i; | |
} | |
UINT_T GEU_ReadApCpConfigFuseBits(UINT_T* pBuffer, UINT_T Size) | |
{ | |
if (Size < K_APCP_CONFIG_FUSE_SIZE) | |
{ | |
return (FUSE_BufferTooSmall); | |
} | |
GEU_REG_READ(GEU_FUSE_VAL_APCFG1, pBuffer[0]); | |
GEU_REG_READ(GEU_FUSE_VAL_APCFG2, pBuffer[1]); | |
GEU_REG_READ(GEU_FUSE_VAL_APCFG3, pBuffer[2]); | |
return NoError; | |
}; | |
UINT_T GEU_ReadApConfigFuseBits(UINT_T* pBuffer, UINT_T Size) | |
{ | |
UINT_T temp[3]; | |
if (Size < K_AP_CONFIG_FUSE_SIZE) | |
{ | |
return (FUSE_BufferTooSmall); | |
} | |
GEU_REG_READ(GEU_FUSE_VAL_APCFG1, temp[0]); | |
GEU_REG_READ(GEU_FUSE_VAL_APCFG2, temp[1]); | |
GEU_REG_READ(GEU_FUSE_VAL_APCFG3, temp[2]); | |
//AP config[31:0] | |
pBuffer[0] = (temp[0] >> 16) | (temp[1] << 16); | |
//AP config[63:32] | |
pBuffer[1] = (temp[1] >> 16) | (temp[2] << 16); | |
//AP config[79:64] | |
pBuffer[2] = temp[2] >> 16; | |
return NoError; | |
}; | |
UINT_T GEU_ReadCpConfigFuseBits(UINT_T* pBuffer, UINT_T Size) | |
{ | |
UINT_T temp; | |
if (Size < K_TOP_CONFIG_FUSE_SIZE) | |
{ | |
return (FUSE_BufferTooSmall); | |
} | |
GEU_REG_READ(GEU_FUSE_VAL_APCFG1, temp); | |
//CP config[15:0] | |
pBuffer[0] = temp & 0xFFFF; | |
return NoError; | |
}; | |
UINT_T GEU_ReadOemHashKeyFuseBits(UINT_T* pBuffer, UINT_T Size) | |
{ | |
if (!((Size == K_SHA1_SIZE)||(Size == K_SHA256_SIZE))) | |
{ | |
return (FUSE_InvalidBufferSize); | |
} | |
// return 20 bytes regardless of size | |
GEU_REG_READ(GEU_FUSE_VAL_OEM_HASH_KEY+0, pBuffer[0]); | |
GEU_REG_READ(GEU_FUSE_VAL_OEM_HASH_KEY+4, pBuffer[1]); | |
GEU_REG_READ(GEU_FUSE_VAL_OEM_HASH_KEY+8, pBuffer[2]); | |
GEU_REG_READ(GEU_FUSE_VAL_OEM_HASH_KEY+12, pBuffer[3]); | |
GEU_REG_READ(GEU_FUSE_VAL_OEM_HASH_KEY+16, pBuffer[4]); | |
if (Size == K_SHA256_SIZE) //32 | |
{ | |
GEU_REG_READ(GEU_FUSE_VAL_OEM_HASH_KEY+20, pBuffer[5]); | |
GEU_REG_READ(GEU_FUSE_VAL_OEM_HASH_KEY+24, pBuffer[6]); | |
GEU_REG_READ(GEU_FUSE_VAL_OEM_HASH_KEY+28, pBuffer[7]); | |
} | |
return NoError; | |
}; | |
UINT_T GEU_ReadUsbIdFuseBits(UINT_T* pBuffer, UINT_T Size) | |
{ | |
if (Size != K_USBID_FUSE_SIZE) | |
{ | |
return (FUSE_InvalidBufferSize); | |
} | |
// Bootrom only supports 32 bits so only read one register (32 bts of ID). | |
GEU_REG_READ(GEU_FUSE_VAL_USB_VER_ID, pBuffer[0]); | |
return NoError; | |
}; | |
/************************************ | |
* Returns current Lifecycle | |
************************************/ | |
UINT_T GEU_ReadLifeCycle() | |
{ | |
UINT_T regValue, lifeCycleCount = 0; | |
GEU_REG_READ(GEU_FUSE_VAL_LIFECYCLE_LCS, regValue); | |
// Check CM | |
//lifeCycleCount += countOnes((regValue & GEU_FUSE_VAL_LIFECYCLE_CM_MSK) >> GEU_FUSE_VAL_LIFECYCLE_CM_BASE); | |
lifeCycleCount += PHYSICAL_TO_LOGICAL((regValue & GEU_FUSE_VAL_LIFECYCLE_CM_MSK) >> GEU_FUSE_VAL_LIFECYCLE_CM_BASE); | |
// Check DM | |
lifeCycleCount += PHYSICAL_TO_LOGICAL((regValue & GEU_FUSE_VAL_LIFECYCLE_DM_MSK) >> GEU_FUSE_VAL_LIFECYCLE_DM_BASE); | |
// Check SP | |
lifeCycleCount += PHYSICAL_TO_LOGICAL((regValue & GEU_FUSE_VAL_LIFECYCLE_SP_MSK) >> GEU_FUSE_VAL_LIFECYCLE_SP_BASE); | |
// Check RMA | |
lifeCycleCount += PHYSICAL_TO_LOGICAL((regValue & GEU_FUSE_VAL_LIFECYCLE_RMA_MSK) >> GEU_FUSE_VAL_LIFECYCLE_RMA_BASE); | |
return lifeCycleCount; | |
} | |
UINT_T GEU_ReadLifeCycleState() | |
{ | |
UINT_T lcs; | |
GEU_REG_READ(GEU_FUSE_VAL_LIFECYCLE_LCS, lcs); | |
lcs &= 0xFFFF; | |
return lcs; | |
} | |
INT_T GEU_LifeCycleIsSP(void) | |
{ | |
UINT_T lcs; | |
lcs = GEU_ReadLifeCycleState(); | |
lcs = PHYSICAL_TO_LOGICAL((lcs & GEU_FUSE_VAL_LIFECYCLE_SP_MSK) >> GEU_FUSE_VAL_LIFECYCLE_SP_BASE); | |
return lcs; | |
} | |
//TODO, need PE to define | |
UINT_T GEU_ReadOemUidFuseBits(UINT_T* pBuffer, UINT_T Size) | |
{ | |
UINT_T scratch; | |
if (Size != K_OEM_UNIQUE_ID_FUSE_SIZE) | |
{ | |
return (FUSE_InvalidBufferSize); | |
} | |
GEU_REG_READ(GEU_FUSE_VAL_OEM_UID_L, pBuffer[0]); | |
GEU_REG_READ(GEU_FUSE_VAL_OEM_UID_H, pBuffer[1]); | |
return NoError; | |
}; | |
UINT_T GEU_ReadHWLockState() | |
{ | |
UINT_T HwLock; | |
GEU_REG_READ(GEU_FUSE_HW_LOCK, HwLock); | |
HwLock &= 0xFFFF; | |
return HwLock; | |
} | |
UINT_T GEU_BlockIsLocked(UINT_T BlockNum) | |
{ | |
UINT_T scratch; | |
GEU_REG_READ(GEU_FUSE_HW_LOCK, scratch); | |
if(scratch & (1 << BlockNum)) | |
return 1; | |
return 0; | |
} | |
UINT_T GEU_JtagFuseDisabled(VOID) | |
{ | |
UINT_T top_config; | |
GEU_ReadTopConfigFuseBits(&top_config, K_TOP_CONFIG_FUSE_SIZE); | |
if(top_config & BIT_14) | |
return 1; | |
return 0; | |
} | |
UINT_T GEU_ForceDownloadFuseDisabled(VOID) | |
{ | |
UINT_T value; | |
GEU_REG_READ(GEU_FUSE_VAL_APCFG3, value); | |
if(value & BIT_29) | |
return 1; | |
return 0; | |
} | |
UINT_T GEU_RomLogDisabled(VOID) | |
{ | |
UINT_T value; | |
GEU_REG_READ(GEU_FUSE_VAL_APCFG3, value); | |
if(value & BIT_3) | |
return 1; | |
return 0; | |
} | |
/* TODO, kestrel SW version in fuse is not defined */ | |
UINT_T GEU_ReadSoftwareVersion(VOID) | |
{ | |
UINT_T value; | |
//GEU_REG_READ(GEU_FUSE_BANK0_239_208, value); | |
return value; | |
} | |
INT GEU_MajorAntiRollBackEnabled(VOID) | |
{ | |
UINT_T value = GEU_ReadSoftwareVersion(); | |
return (value & 1); | |
} | |
INT_T GEU_ReadMajorVersion(VOID) | |
{ | |
INT_T i, ones = 0; | |
UINT_T value = GEU_ReadSoftwareVersion(); | |
for(i = 0; i < 32; i++) | |
{ | |
if(value & (1 << i)) | |
ones++; | |
} | |
return (ones - 1); /* -1 means no major version burned */ | |
} |