Index: Integrity.c =================================================================== diff -u --- Integrity.c (revision 0) +++ Integrity.c (revision 57b76af2edf0f845fec8bfef5cd126a41223b58c) @@ -0,0 +1,105 @@ +/************************************************************************** +* +* 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. +#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. + +/*********************************************************************//** + * @brief + * The initIntegrity function initializes the Integrity module. + * @details Inputs: none + * @details Outputs: Integrity module initialized + * @return none + *************************************************************************/ +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 + *************************************************************************/ +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; + U32 remainingSize = 0; + + if ( currentRecord < crcTablePtr->num_recs ) + { + remainingSize = currentRecordPtr->size - currentProcessedSize; + + if ( remainingSize > MAX_CRC_CALC_DATA_SIZE ) + { + crcCalculated = crc32( crcCalculated, (U08 *)( currentRecordPtr->addr + currentProcessedSize ), MAX_CRC_CALC_DATA_SIZE ); + currentProcessedSize += MAX_CRC_CALC_DATA_SIZE; + } + else + { + crcCalculated = crc32( crcCalculated, (U08 *)( currentRecordPtr->addr + currentProcessedSize ), remainingSize ); + integrityStatus &= ( ( (U32)currentRecordPtr->crc_value == crcCalculated ) ? TRUE : FALSE ); + crcCalculated = 0; + currentProcessedSize = 0; + currentRecord++; + } + } + + if ( TRUE != integrityStatus ) + { + integrityTestStatus = SELF_TEST_STATUS_FAILED; +#ifdef _DG_ + activateAlarmNoData( ALARM_ID_DG_INTEGRITY_POST_TEST_FAILED ); +#else + activateAlarmNoData( ALARM_ID_HD_INTEGRITY_POST_TEST_FAILED ); +#endif + } + else if ( currentRecord == crcTablePtr->num_recs ) + { + integrityTestStatus = SELF_TEST_STATUS_PASSED; + } + + return integrityTestStatus; +} + +/**@}*/ Index: Integrity.h =================================================================== diff -u --- Integrity.h (revision 0) +++ Integrity.h (revision 57b76af2edf0f845fec8bfef5cd126a41223b58c) @@ -0,0 +1,40 @@ +/************************************************************************** +* +* 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.h +* +* @author (last) Quang Nguyen +* @date (last) 11-May-2021 +* +* @author (last) Quang Nguyen +* @date (last) 11-May-2021 +* +***************************************************************************/ + +#ifndef __INTEGRITY_H__ +#define __INTEGRITY_H__ + +#include "Common.h" + +/** + * @defgroup Integrity Integrity + * @brief Integrity module checks for firmware integrity using CRC table generated by TI linker. + * + * @addtogroup Integrity + * @{ + */ + +// ********** public definitions ********** + +// ********** public function prototypes ********** + +void initIntegrity( void ); +SELF_TEST_STATUS_T execIntegrityTest( void ); + +/**@}*/ + +#endif Index: RTC.c =================================================================== diff -u -rbf1596fb2605df8d628b2804e9a8760ae20f2228 -r57b76af2edf0f845fec8bfef5cd126a41223b58c --- RTC.c (.../RTC.c) (revision bf1596fb2605df8d628b2804e9a8760ae20f2228) +++ RTC.c (.../RTC.c) (revision 57b76af2edf0f845fec8bfef5cd126a41223b58c) @@ -500,8 +500,6 @@ hasReadFromRAMRequested = TRUE; RAMBufferLength = length; prepRAMBuffer[ RTC_PREP_RAM_INDEX ] = RTC_PREP_RAM_READ_WRITE; - //prepRAMBuffer[ RTC_RAM_HIGH_ADDRESS_INDEX ] = ( address >> SHIFT_8_BITS_FOR_BYTE_SHIFT ); - //prepRAMBuffer[ RTC_RAM_HIGH_ADDRESS_INDEX ] = ( address & MASK_OFF_NIBBLE_LSB ) >> SHIFT_BITS_BY_4; prepRAMBuffer[ RTC_RAM_HIGH_ADDRESS_INDEX ] = 0x0000; prepRAMBuffer[ RTC_RAM_LOW_ADDRESS_INDEX ] = castedAddress; txBuffer[ BUFFER_INDEX_0 ] = RTC_READ_FROM_RAM;