2013-07-31 08:48:23 -07:00
|
|
|
/************************************************************************************//**
|
|
|
|
* \file Source\backdoor.c
|
|
|
|
* \brief Bootloader backdoor entry source file.
|
|
|
|
* \ingroup Core
|
|
|
|
* \internal
|
|
|
|
*----------------------------------------------------------------------------------------
|
|
|
|
* C O P Y R I G H T
|
|
|
|
*----------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) 2011 by Feaser http://www.feaser.com All rights reserved
|
|
|
|
*
|
|
|
|
*----------------------------------------------------------------------------------------
|
|
|
|
* L I C E N S E
|
|
|
|
*----------------------------------------------------------------------------------------
|
|
|
|
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2016-07-25 01:33:52 -07:00
|
|
|
* You have received a copy of the GNU General Public License along with OpenBLT. It
|
2016-04-30 15:52:15 -07:00
|
|
|
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
2016-03-01 06:24:23 -08:00
|
|
|
*
|
2013-07-31 08:48:23 -07:00
|
|
|
* \endinternal
|
2011-11-10 09:55:56 -08:00
|
|
|
****************************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Include files
|
|
|
|
****************************************************************************************/
|
|
|
|
#include "boot.h" /* bootloader generic header */
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Macro definitions
|
|
|
|
****************************************************************************************/
|
|
|
|
#if (BOOT_BACKDOOR_HOOKS_ENABLE == 0)
|
2016-03-01 06:24:23 -08:00
|
|
|
#ifndef BACKDOOR_ENTRY_TIMEOUT_MS
|
|
|
|
/** \brief Sets the time in milliseconds that the backdoor is open, but allow an
|
|
|
|
* override for this time. note that this time should be at least 2.5 times
|
|
|
|
* as long as the time that is configured in Microboot's XCP settings for the
|
|
|
|
* connect command response. This is the last entry on XCP Timeouts tab. By
|
|
|
|
* default the connect command response is configured as 20ms by Microboot,
|
|
|
|
* except for TCP/IP where it is 300ms due to accomodate for worldwide
|
|
|
|
* network latency. The default value was chosen safely for compatibility
|
|
|
|
* reasons with all supported communication interfaces. It could be made
|
|
|
|
* shorter your bootloader. To change this value, simply add the macro
|
|
|
|
* BACKDOOR_ENTRY_TIMEOUT_MS to blt_conf.h with your desired backdoor open time
|
|
|
|
* in milliseconds.
|
|
|
|
*/
|
|
|
|
#if (BOOT_COM_NET_ENABLE == 1)
|
|
|
|
#define BACKDOOR_ENTRY_TIMEOUT_MS (750)
|
|
|
|
#else
|
|
|
|
#define BACKDOOR_ENTRY_TIMEOUT_MS (500)
|
|
|
|
#endif
|
|
|
|
#endif
|
2011-11-10 09:55:56 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Hook functions
|
|
|
|
****************************************************************************************/
|
|
|
|
#if (BOOT_BACKDOOR_HOOKS_ENABLE > 0)
|
2013-05-22 06:37:47 -07:00
|
|
|
extern void BackDoorInitHook(void);
|
|
|
|
extern blt_bool BackDoorEntryHook(void);
|
2011-11-10 09:55:56 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Local data declarations
|
|
|
|
****************************************************************************************/
|
|
|
|
#if (BOOT_BACKDOOR_HOOKS_ENABLE == 0)
|
2013-07-31 08:48:23 -07:00
|
|
|
/** \brief To determine if the backdoor is open or closed. */
|
2011-11-10 09:55:56 -08:00
|
|
|
static blt_bool backdoorOpen;
|
2013-07-31 08:48:23 -07:00
|
|
|
/** \brief To determine how long the backdoor has been open in milliseconds. */
|
2013-05-22 06:37:47 -07:00
|
|
|
static blt_int32u backdoorOpenTime;
|
2011-11-10 09:55:56 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-07-31 08:48:23 -07:00
|
|
|
/************************************************************************************//**
|
|
|
|
** \brief Initializes the backdoor entry option.
|
|
|
|
** \return none
|
2011-11-10 09:55:56 -08:00
|
|
|
**
|
|
|
|
****************************************************************************************/
|
|
|
|
void BackDoorInit(void)
|
|
|
|
{
|
|
|
|
#if (BOOT_BACKDOOR_HOOKS_ENABLE > 0)
|
|
|
|
/* initialize application's backdoor functionality */
|
|
|
|
BackDoorInitHook();
|
2016-03-01 06:24:23 -08:00
|
|
|
|
2014-07-22 07:53:07 -07:00
|
|
|
/* attempt to start the user program when no backdoor entry is requested */
|
|
|
|
if (BackDoorEntryHook() == BLT_FALSE)
|
2011-11-10 09:55:56 -08:00
|
|
|
{
|
|
|
|
/* this function does not return if a valid user program is present */
|
|
|
|
CpuStartUserProgram();
|
|
|
|
}
|
2016-03-01 06:24:23 -08:00
|
|
|
#if (BOOT_FILE_SYS_ENABLE > 0)
|
2013-06-17 06:27:31 -07:00
|
|
|
else
|
|
|
|
{
|
2016-03-01 06:24:23 -08:00
|
|
|
/* the backdoor is open so we should check if a update from locally attached storage
|
2014-07-22 07:53:07 -07:00
|
|
|
* is requested and, if so, start it.
|
|
|
|
*/
|
|
|
|
FileHandleFirmwareUpdateRequest();
|
2013-06-17 06:27:31 -07:00
|
|
|
}
|
2016-03-01 06:24:23 -08:00
|
|
|
#endif
|
2011-11-10 09:55:56 -08:00
|
|
|
#else
|
|
|
|
/* open the backdoor after a reset */
|
|
|
|
backdoorOpen = BLT_TRUE;
|
2013-05-22 06:37:47 -07:00
|
|
|
backdoorOpenTime = TimerGet();
|
2011-11-10 09:55:56 -08:00
|
|
|
#endif
|
|
|
|
/* perform the first check that open/closes the backdoor */
|
|
|
|
BackDoorCheck();
|
|
|
|
} /*** end of BackDoorInit ***/
|
|
|
|
|
|
|
|
|
2013-07-31 08:48:23 -07:00
|
|
|
/************************************************************************************//**
|
|
|
|
** \brief The default backdoor entry feature keeps the bootloader active for a
|
|
|
|
** predetermined time after reset, allowing the host application to
|
|
|
|
** establish a connection and start a programming sequence. This function
|
|
|
|
** controls the opening/closing of the backdoor.
|
|
|
|
** \return none
|
2011-11-10 09:55:56 -08:00
|
|
|
**
|
|
|
|
****************************************************************************************/
|
|
|
|
void BackDoorCheck(void)
|
|
|
|
{
|
|
|
|
#if (BOOT_BACKDOOR_HOOKS_ENABLE == 0)
|
2016-03-01 06:24:23 -08:00
|
|
|
#if (BOOT_COM_ENABLE > 0)
|
2011-11-10 09:55:56 -08:00
|
|
|
/* check if a connection with the host was already established. in this case the
|
2016-03-01 06:24:23 -08:00
|
|
|
* backdoor stays open anyway, so no need to check if it needs to be closed.
|
2011-11-10 09:55:56 -08:00
|
|
|
*/
|
|
|
|
if (ComIsConnected() == BLT_TRUE)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-03-01 06:24:23 -08:00
|
|
|
#endif
|
|
|
|
#if (BOOT_FILE_SYS_ENABLE > 0)
|
2013-05-22 06:37:47 -07:00
|
|
|
/* check if the file module is busy, indicating that a firmware update through the
|
2016-03-01 06:24:23 -08:00
|
|
|
* locally attached storage is in progress. in this case the backdoor stays open
|
|
|
|
* anyway, so no need to check if it needs to be closed.
|
2013-05-22 06:37:47 -07:00
|
|
|
*/
|
|
|
|
if (FileIsIdle() == BLT_FALSE)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-03-01 06:24:23 -08:00
|
|
|
#endif
|
|
|
|
|
2011-11-10 09:55:56 -08:00
|
|
|
/* when the backdoor is still open, check if it's time to close it */
|
|
|
|
if (backdoorOpen == BLT_TRUE)
|
|
|
|
{
|
|
|
|
/* check if the backdoor entry time window elapsed */
|
2013-05-22 06:37:47 -07:00
|
|
|
if (TimerGet() >= (BACKDOOR_ENTRY_TIMEOUT_MS + backdoorOpenTime))
|
2011-11-10 09:55:56 -08:00
|
|
|
{
|
|
|
|
/* close the backdoor */
|
|
|
|
backdoorOpen = BLT_FALSE;
|
2016-03-01 06:24:23 -08:00
|
|
|
#if (BOOT_FILE_SYS_ENABLE > 0)
|
2013-06-17 06:27:31 -07:00
|
|
|
/* during the timed backdoor no remote update request was detected. now do one
|
|
|
|
* last check to see if a firmware update from locally attached storage is
|
|
|
|
* pending.
|
|
|
|
*/
|
|
|
|
if (FileHandleFirmwareUpdateRequest() == BLT_FALSE)
|
2016-03-01 06:24:23 -08:00
|
|
|
#endif
|
2013-06-17 06:27:31 -07:00
|
|
|
{
|
|
|
|
/* no firmware update requests detected, so attempt to start the user program.
|
|
|
|
* this function does not return if a valid user program is present.
|
|
|
|
*/
|
|
|
|
CpuStartUserProgram();
|
|
|
|
}
|
2011-11-10 09:55:56 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} /*** end of BackDoorCheck ***/
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************** end of backdoor.c *********************************/
|