Tool/software:
I have to add some source code (marked using red color) and then the hash comparing can be right, if not the hash comparing will be wrong. We enable the cache (CacheP_enable(CacheP_TYPE_ALL);) and we use TI Clang v2.1.3.LTS.
#define Cur_SigInfo_BASEADDR 0x300000
#define Cur_Sha2Hash_IFBADDR (Cur_SigInfo_BASEADDR + 0x200)
uint8 FOTA_Status_Copying_Manage(void)
{
SHA256_State sha2Cur;
static SHA256_State sha2Backup;
ret = ReadBackupSwAndCalcSHA2(&sha2Backup);/* using core 0 software to do hash not HSM hardware */
if(ret == E_OK)
{
memcpy(&(sha2Cur.h[0]),(void*)(Cur_Sha2Hash_IFBADDR|0x60000000), 32);
data[0] = sha2Backup.h[0] >> 24;
data[1] = sha2Backup.h[0] >> 16;
data[2] = sha2Backup.h[0] >> 8;
data[3] = sha2Backup.h[0] >> 0;
data[4] = sha2Cur.h[0] >> 24;
data[5] = sha2Cur.h[0] >> 16;
data[6] = sha2Cur.h[0] >> 8;
data[7] = sha2Cur.h[0] >> 0;
ret = Compare_hash_value(sha2Cur, sha2Backup);
if(ret == E_NOT_OK)
{
Dcm_FOTA_ErrCodeSet(ERR_CODE_SIGNATURE);
}
}
}
uint8 Compare_hash_value(SHA256_State source, SHA256_State target)
{
uint8 ret = E_OK;
for(uint8 i = 0; i < 8; i++)
{
if(source.h[i] != target.h[i])
{
ret = E_NOT_OK;
break;
}
}
return ret;
}