Index: firmware/App/Services/Integrity.c =================================================================== diff -u -r84bb8663dae71170e1743a2bed37b0aa47465b47 -r40e0116bbada6d1780bfa832a9c4684ba9fcfcc8 --- firmware/App/Services/Integrity.c (.../Integrity.c) (revision 84bb8663dae71170e1743a2bed37b0aa47465b47) +++ firmware/App/Services/Integrity.c (.../Integrity.c) (revision 40e0116bbada6d1780bfa832a9c4684ba9fcfcc8) @@ -27,12 +27,18 @@ // ********** private definitions ********** -#define CRC_TABLE_STARTING_ADDR 0x20 ///< The starting address of CRC table for firmware image. +#define CRC_TABLE_STARTING_ADDR 0x20 ///< The starting address of CRC table for firmware image. +#define MAX_CRC_CALC_DATA_SIZE 0x8000 ///< The maximum size of data for each CRC calculation. // ********** private data ********** + +static U32 currentRecord; ///< Current CRC table record to check. +static U32 currentProcessedSize; ///< Current data size processed for CRC calculation. +static U32 crcCalculated; ///< The calculated CRC value. +static SELF_TEST_STATUS_T integrityTestStatus; ///< Current firmware integrity test status. + +static U32 calculateCrc( U32 const crcValue, U08 * dataPtr, U32 size, U32 crcAlgoId ); -static BOOL checkCrc( CRC_RECORD const * const recPtr ); - /*********************************************************************//** * @brief * The initIntegrity function initializes the Integrity module. @@ -42,65 +48,86 @@ *************************************************************************/ void initIntegrity( void ) { + currentRecord = 0; + currentProcessedSize = 0; + crcCalculated = 0; + integrityTestStatus = SELF_TEST_STATUS_IN_PROGRESS; } /*********************************************************************//** * @brief * The execIntegrityTest function executes the integrity check for firmware image. * @details Inputs: firmware image CRC table * @details Outputs: none - * @return Firmware image integrity self-test status + * @return firmware image integrity self-test status *************************************************************************/ SELF_TEST_STATUS_T execIntegrityTest( void ) { CRC_TABLE const * const crcTablePtr = (CRC_TABLE *)CRC_TABLE_STARTING_ADDR; + CRC_RECORD const * const currentRecordPtr = &crcTablePtr->recs[ currentRecord ]; BOOL integrityStatus = TRUE; - SELF_TEST_STATUS_T result; - U32 i; + U32 remainingSize = 0; - for ( i = 0; i < crcTablePtr->num_recs; ++i ) + if ( currentRecord < crcTablePtr->num_recs ) { - integrityStatus &= checkCrc( &crcTablePtr->recs[i] ); + remainingSize = currentRecordPtr->size - currentProcessedSize; + + if ( remainingSize > MAX_CRC_CALC_DATA_SIZE ) + { + crcCalculated = calculateCrc( crcCalculated, (U08 *)( currentRecordPtr->addr + currentProcessedSize ), MAX_CRC_CALC_DATA_SIZE, currentRecordPtr->crc_alg_ID ); + currentProcessedSize += MAX_CRC_CALC_DATA_SIZE; + } + else + { + crcCalculated = calculateCrc( crcCalculated, (U08 *)( currentRecordPtr->addr + currentProcessedSize ), remainingSize, currentRecordPtr->crc_alg_ID ); + integrityStatus &= ( ( (U32)currentRecordPtr->crc_value == crcCalculated ) ? TRUE : FALSE ); + crcCalculated = 0; + currentProcessedSize = 0; + currentRecord++; + } } - if ( TRUE == integrityStatus ) + if ( TRUE != integrityStatus ) { - result = SELF_TEST_STATUS_PASSED; + integrityTestStatus = SELF_TEST_STATUS_FAILED; + activateAlarmNoData( ALARM_ID_HD_INTEGRITY_POST_TEST_FAILED ); } - else + else if ( currentRecord == crcTablePtr->num_recs ) { - result = SELF_TEST_STATUS_FAILED; - activateAlarmNoData( ALARM_ID_HD_INTEGRITY_POST_TEST_FAILED ); + integrityTestStatus = SELF_TEST_STATUS_PASSED; } - return result; + return integrityTestStatus; } /*********************************************************************//** * @brief - * The checkCrc function computes the CRC on given memory section and CRC - * algorithm. Then it compares with calculated CRC created by linker. + * The calculateCrc function computes the CRC on the given memory section + * and CRC algorithm. * @details Inputs: none * @details Outputs: none - * @param recPtr CRC record data pointer - * @return TRUE if two CRCs are matched, otherwise FALSE + * @param crcValue crc initial value + * @param dataPtr pointer to data record for CRC calculation + * @param size data size to calculate crc + * @param crcAlgoId CRC algorithm id number + * @return calculated CRC value *************************************************************************/ -static BOOL checkCrc( CRC_RECORD const * const recPtr ) +static U32 calculateCrc( U32 const crcValue, U08 * dataPtr, U32 size, U32 crcAlgoId ) { - U32 crcCalculated = 0; + U32 crcCalc = 0; - switch ( recPtr->crc_alg_ID ) + switch ( crcAlgoId ) { case CRC32_C: - crcCalculated = crc32( (U08 *)recPtr->addr, recPtr->size ); + crcCalc = crc32( crcValue, dataPtr, size ); break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_CRC_ALGO, recPtr->crc_alg_ID ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_CRC_ALGO, crcAlgoId ) break; } - return ( (U32)recPtr->crc_value == crcCalculated ) ? TRUE : FALSE; + return crcCalc; } /**@}*/