//***************************************************************************** // //! Checks if an update is needed or is being requested. //! //! This function detects if an update is being requested or if there is no //! valid code presently located on the microcontroller. This is used to tell //! whether or not to enter update mode. //! //! \return Returns a non-zero value if an update is needed or is being //! requested and zero otherwise. // //***************************************************************************** unsigned long CheckForceUpdate(void) { #ifdef BL_CHECK_UPDATE_FN_HOOK // // If the update check function is hooked, call the application to determine // how to proceed. // return(BL_CHECK_UPDATE_FN_HOOK()); #else unsigned long *pulApp; #ifdef ENABLE_UPDATE_CHECK g_ulForced = 0; #endif // // See if the first location is 0xfffffffff or something that does not // look like a stack pointer, or if the second location is 0xffffffff or // something that does not look like a reset vector. // pulApp = (unsigned long *)APP_START_ADDRESS; if((pulApp[0] == 0xffffffff) || ((pulApp[0] & 0xfff00000) != 0x20000000) || (pulApp[1] == 0xffffffff) || ((pulApp[1] & 0xfff00001) != 0x00000001)) { return(1); } #ifdef ENABLE_UPDATE_CHECK // // If simple GPIO checking is configured, determine whether or not to force // an update. // return(CheckGPIOForceUpdate()); #else // // GPIO checking is not required so, if we get here, a valid image exists // and no update is needed. // return(0); #endif #endif }
//***************************************************************************** // //! Checks if an update is needed or is being requested. //! //! This function detects if an update is being requested or if there is no //! valid code presently located on the microcontroller. This is used to tell //! whether or not to enter update mode. //! //! \return Returns a non-zero value if an update is needed or is being //! requested and zero otherwise. // //***************************************************************************** uint32_t CheckForceUpdate(void) { #ifdef CHECK_CRC uint32_t ui32Retcode; #endif #ifdef BL_CHECK_UPDATE_FN_HOOK // // If the update check function is hooked, call the application to determine // how to proceed. // return(BL_CHECK_UPDATE_FN_HOOK()); #else uint32_t *pui32App; #ifdef ENABLE_UPDATE_CHECK g_ui32Forced = 0; #endif // // See if the first location is 0xfffffffff or something that does not // look like a stack pointer, or if the second location is 0xffffffff or // something that does not look like a reset vector. // pui32App = (uint32_t *)APP_START_ADDRESS; if((pui32App[0] == 0xffffffff) || ((pui32App[0] & 0xfff00000) != 0x20000000) || (pui32App[1] == 0xffffffff) || ((pui32App[1] & 0xfff00001) != 0x00000001)) { return(1); } // // If required, scan the image for an embedded CRC and ensure that it // matches the current CRC of the image. // #ifdef CHECK_CRC InitCRC32Table(); ui32Retcode = CheckImageCRC32(pui32App); // // If ENFORCE_CRC is defined, we only boot the image if the CRC is // present in the image information header and the value calculated // matches the value in the header. If ENFORCE_CRC is not defined, we // the image if the CRC is good but also if the length field of the header // is zero (which typically indicates that the post-build step of running // binpack to add the length and CRC to the header was not run). // #ifdef ENFORCE_CRC if(ui32Retcode != CHECK_CRC_OK) #else if((ui32Retcode != CHECK_CRC_OK) && (ui32Retcode != CHECK_CRC_NO_LENGTH)) #endif { // // The CRC32 image check failed indicating that the image is // corrupt (or doesn't have the CRC embedded correctly). Either way, // fail the update check and force the boot loader to retain control. // return(2); } #endif #ifdef ENABLE_UPDATE_CHECK // // If simple GPIO checking is configured, determine whether or not to force // an update. // return(CheckGPIOForceUpdate()); #else // // GPIO checking is not required so, if we get here, a valid image exists // and no update is needed. // return(0); #endif #endif }