/************************************************************************** * * Copyright (c) 2021 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file Integrity.c * * @author (last) Quang Nguyen * @date (last) 11-May-2021 * * @author (last) Quang Nguyen * @date (last) 11-May-2021 * ***************************************************************************/ #include #include "Integrity.h" #include "Utilities.h" /** * @addtogroup Integrity * @{ */ // ********** private definitions ********** #define CRC_TABLE_STARTING_ADDR 0x20 ///< The starting address of CRC table for firmware image. // ********** private data ********** static BOOL checkCrc( CRC_RECORD const * const recPtr ); /*********************************************************************//** * @brief * The initIntegrity function initializes the Integrity module. * @details Inputs: none * @details Outputs: Integrity module initialized * @return none *************************************************************************/ void initIntegrity( void ) { } /*********************************************************************//** * @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 *************************************************************************/ SELF_TEST_STATUS_T execIntegrityTest( void ) { CRC_TABLE const * const crcTablePtr = (CRC_TABLE *)CRC_TABLE_STARTING_ADDR; BOOL integrityStatus = TRUE; SELF_TEST_STATUS_T result; U32 i; for ( i = 0; i < crcTablePtr->num_recs; ++i ) { integrityStatus &= checkCrc( &crcTablePtr->recs[i] ); } if ( TRUE == integrityStatus ) { result = SELF_TEST_STATUS_PASSED; } else { result = SELF_TEST_STATUS_FAILED; activateAlarmNoData( ALARM_ID_HD_INTEGRITY_POST_TEST_FAILED ); } return result; } /*********************************************************************//** * @brief * The checkCrc function computes the CRC on given memory section and CRC * algorithm. Then it compares with calculated CRC created by linker. * @details Inputs: none * @details Outputs: none * @param recPtr CRC record data pointer * @return TRUE if two CRCs are matched, otherwise FALSE *************************************************************************/ static BOOL checkCrc( CRC_RECORD const * const recPtr ) { U32 crcCalculated = 0; switch ( recPtr->crc_alg_ID ) { case CRC32_C: crcCalculated = crc32( (U08 *)recPtr->addr, recPtr->size ); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_CRC_ALGO, recPtr->crc_alg_ID ) break; } return ( (U32)recPtr->crc_value == crcCalculated ) ? TRUE : FALSE; } /**@}*/