Skip to content

Commit

Permalink
Refs #1229. Added support for firmware updates from SD-card to the Ol…
Browse files Browse the repository at this point in the history
…imexino-STM32F3 demo programs.

git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@1064 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
  • Loading branch information
feaser committed Jun 14, 2023
1 parent f05796b commit 5fd33bf
Show file tree
Hide file tree
Showing 20 changed files with 7,090 additions and 2,003 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
<listOptionValue builtIn="false" value="../App"/>
<listOptionValue builtIn="false" value="../Library/STM32_USB_Device_Library/Core/Inc"/>
<listOptionValue builtIn="false" value="../Library/FatFS"/>
<listOptionValue builtIn="false" value="../USB_DEVICE/App"/>
<listOptionValue builtIn="false" value="../USB_DEVICE/Target"/>
<listOptionValue builtIn="false" value="../../../../Source"/>
<listOptionValue builtIn="false" value="../../../../Source/ARMCM4_STM32F3"/>
<listOptionValue builtIn="false" value="../../../../Source/third_party/fatfs/src"/>
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.1605971816" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
</tool>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@
</linkedResources>
<filteredResources>
<filter>
<id>1686569576442</id>
<id>1686649539105</id>
<name>Loader</name>
<type>9</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-ARMCM4_STM32F3</arguments>
</matcher>
</filter>
<filter>
<id>1686649539109</id>
<name>Loader</name>
<type>9</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-third_party</arguments>
</matcher>
</filter>
<filter>
<id>1686569589593</id>
<name>Loader/ARMCM4_STM32F3</name>
Expand All @@ -55,6 +64,33 @@
<arguments>1.0-name-matches-false-false-GCC</arguments>
</matcher>
</filter>
<filter>
<id>1686649554358</id>
<name>Loader/third_party</name>
<type>9</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-fatfs</arguments>
</matcher>
</filter>
<filter>
<id>1686649567497</id>
<name>Loader/third_party/fatfs</name>
<type>9</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-src</arguments>
</matcher>
</filter>
<filter>
<id>1686649590858</id>
<name>Loader/third_party/fatfs/src/option</name>
<type>5</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-unicode.c</arguments>
</matcher>
</filter>
</filteredResources>
<variableList>
<variable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-804685279247832828" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-666769791631151900" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand All @@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-804685279247832828" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-666769791631151900" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,42 @@
#define BOOT_COM_USB_RX_MAX_DATA (63)


/****************************************************************************************
* F I L E S Y S T E M I N T E R F A C E C O N F I G U R A T I O N
****************************************************************************************/
/* The file system interface is selected by setting the BOOT_FILE_SYS_ENABLE configurable
* to 1. This enables support for firmware updates from a file stored on a locally
* attached file system such as an SD-card. Note that this interface can be enabled
* together with one of the remote communication interfaces such as UART, CAN or USB.
*
* Set BOOT_FILE_LOGGING_ENABLE to 1 if you would like log messages to be created during
* a firmware update. The hook function FileFirmwareUpdateLogHook() will be called each
* time a new string formatted log entry is available. This could be used during testing
* by outputting the string on UART or to create a log file on the file system itself.
*
* Set BOOT_FILE_ERROR_HOOK_ENABLE to 1 if you would like to be informed in case an error
* occurs during the firmware update. This could for example be used to turn on an error
* LED to inform the user that something went wrong. Inspecting the log messages provides
* additional information on the error cause.
*
* Set BOOT_FILE_STARTED_HOOK_ENABLE to 1 if you would like to be informed when a new
* firmware update is started by the bootloader.
*
* Set BOOT_FILE_COMPLETED_HOOK_ENABLE to 1 if you would like to be informed when a
* firmware update is completed by the bootloader.
*/
/** \brief Enable/disable support for firmware updates from a locally attached storage.*/
#define BOOT_FILE_SYS_ENABLE (1)
/** \brief Enable/disable logging messages during firmware updates. */
#define BOOT_FILE_LOGGING_ENABLE (1)
/** \brief Enable/disable a hook function that is called upon detection of an error. */
#define BOOT_FILE_ERROR_HOOK_ENABLE (1)
/** \brief Enable/disable a hook function that is called at the start of the update. */
#define BOOT_FILE_STARTED_HOOK_ENABLE (1)
/** \brief Enable/disable a hook function that is called at the end of the update. */
#define BOOT_FILE_COMPLETED_HOOK_ENABLE (1)


/****************************************************************************************
* B A C K D O O R E N T R Y C O N F I G U R A T I O N
****************************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,22 @@ static const tFlashSector flashLayout[] =
/* { 0x08006800, 0x00800 }, flash sector 13 - 2kb (reserved for bootloader)*/
/* { 0x08007000, 0x00800 }, flash sector 14 - 2kb (reserved for bootloader)*/
/* { 0x08007800, 0x00800 }, flash sector 15 - 2kb (reserved for bootloader)*/
{ 0x08008000, 0x08000 }, /* flash sectors 16 to 31 - 32kb */
/* { 0x08008000, 0x00800 }, flash sector 16 - 2kb (reserved for bootloader)*/
/* { 0x08008800, 0x00800 }, flash sector 17 - 2kb (reserved for bootloader)*/
/* { 0x08009000, 0x00800 }, flash sector 18 - 2kb (reserved for bootloader)*/
/* { 0x08009800, 0x00800 }, flash sector 19 - 2kb (reserved for bootloader)*/
{ 0x0800A000, 0x00800 }, /* flash sector 20 - 2kb */
{ 0x0800A800, 0x00800 }, /* flash sector 21 - 2kb */
{ 0x0800B000, 0x00800 }, /* flash sector 22 - 2kb */
{ 0x0800B800, 0x00800 }, /* flash sector 23 - 2kb */
{ 0x0800C000, 0x00800 }, /* flash sector 24 - 2kb */
{ 0x0800C800, 0x00800 }, /* flash sector 25 - 2kb */
{ 0x0800D000, 0x00800 }, /* flash sector 26 - 2kb */
{ 0x0800D800, 0x00800 }, /* flash sector 27 - 2kb */
{ 0x0800E000, 0x00800 }, /* flash sector 28 - 2kb */
{ 0x0800E800, 0x00800 }, /* flash sector 29 - 2kb */
{ 0x0800F000, 0x00800 }, /* flash sector 30 - 2kb */
{ 0x0800F800, 0x00800 }, /* flash sector 31 - 2kb */
{ 0x08010000, 0x08000 }, /* flash sectors 32 to 47 - 32kb */
{ 0x08018000, 0x08000 }, /* flash sectors 48 to 63 - 32kb */
{ 0x08020000, 0x08000 }, /* flash sectors 64 to 79 - 32kb */
Expand Down
162 changes: 162 additions & 0 deletions Target/Demo/ARMCM4_STM32F3_Olimexino_STM32F3_CubeIDE/Boot/App/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,168 @@ blt_bool NvmWriteChecksumHook(void)
#endif /* BOOT_NVM_CHECKSUM_HOOKS_ENABLE > 0 */


/****************************************************************************************
* F I L E S Y S T E M I N T E R F A C E H O O K F U N C T I O N S
****************************************************************************************/

#if (BOOT_FILE_SYS_ENABLE > 0)

/****************************************************************************************
* Constant data declarations
****************************************************************************************/
/** \brief Firmware filename. */
static const blt_char firmwareFilename[] = "/demoprog_olimexino_stm32f3.srec";


/****************************************************************************************
* Local data declarations
****************************************************************************************/
#if (BOOT_FILE_LOGGING_ENABLE > 0)
/** \brief Data structure for grouping log-file related information. */
static struct
{
FIL handle; /**< FatFS handle to the log-file. */
blt_bool canUse; /**< Flag to indicate if the log-file can be used. */
} logfile;
#endif


/************************************************************************************//**
** \brief Callback that gets called to check whether a firmware update from
** local file storage should be started. This could for example be when
** a switch is pressed, when a certain file is found on the local file
** storage, etc.
** \return BLT_TRUE if a firmware update is requested, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FileIsFirmwareUpdateRequestedHook(void)
{
FILINFO fileInfoObject = { 0 }; /* needs to be zeroed according to f_stat docs */;

/* Current example implementation looks for a predetermined firmware file on the
* SD-card. If the SD-card is accessible and the firmware file was found the firmware
* update is started. When successfully completed, the firmware file is deleted.
* During the firmware update, progress information is written to a file called
* bootlog.txt and additionally outputted on UART @57600 bps for debugging purposes.
*/
/* check if firmware file is present and SD-card is accessible */
if (f_stat(firmwareFilename, &fileInfoObject) == FR_OK)
{
/* check if the filesize is valid and that it is not a directory */
if ( (fileInfoObject.fsize > 0) && (!(fileInfoObject.fattrib & AM_DIR)) )
{
/* all conditions are met to start a firmware update from local file storage */
return BLT_TRUE;
}
}
/* still here so no firmware update request is pending */
return BLT_FALSE;
} /*** end of FileIsFirmwareUpdateRequestedHook ***/


/************************************************************************************//**
** \brief Callback to obtain the filename of the firmware file that should be
** used during the firmware update from the local file storage. This
** hook function is called at the beginning of the firmware update from
** local storage sequence.
** \return valid firmware filename with full path or BLT_NULL.
**
****************************************************************************************/
const blt_char *FileGetFirmwareFilenameHook(void)
{
return firmwareFilename;
} /*** end of FileGetFirmwareFilenameHook ***/


#if (BOOT_FILE_STARTED_HOOK_ENABLE > 0)
/************************************************************************************//**
** \brief Callback that gets called to inform the application that a firmware
** update from local storage just started.
** \return none.
**
****************************************************************************************/
void FileFirmwareUpdateStartedHook(void)
{
#if (BOOT_FILE_LOGGING_ENABLE > 0)
/* create/overwrite the logfile */
logfile.canUse = BLT_FALSE;
if (f_open(&logfile.handle, "/bootlog.txt", FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
{
logfile.canUse = BLT_TRUE;
}
#endif
} /*** end of FileFirmwareUpdateStartedHook ***/
#endif /* BOOT_FILE_STARTED_HOOK_ENABLE > 0 */


#if (BOOT_FILE_COMPLETED_HOOK_ENABLE > 0)
/************************************************************************************//**
** \brief Callback that gets called to inform the application that a firmware
** update was successfully completed.
** \return none.
**
****************************************************************************************/
void FileFirmwareUpdateCompletedHook(void)
{
#if (BOOT_FILE_LOGGING_ENABLE > 0)
/* close the log file */
if (logfile.canUse == BLT_TRUE)
{
f_close(&logfile.handle);
}
/* now delete the firmware file from the disk since the update was successful */
f_unlink(firmwareFilename);
#endif
} /*** end of FileFirmwareUpdateCompletedHook ***/
#endif /* BOOT_FILE_COMPLETED_HOOK_ENABLE > 0 */


#if (BOOT_FILE_ERROR_HOOK_ENABLE > 0)
/************************************************************************************//**
** \brief Callback that gets called in case an error occurred during a firmware
** update. Refer to <file.h> for a list of available error codes.
** \return none.
**
****************************************************************************************/
void FileFirmwareUpdateErrorHook(blt_int8u error_code)
{
#if (BOOT_FILE_LOGGING_ENABLE > 0)
/* error detected which stops the firmware update, so close the log file */
if (logfile.canUse == BLT_TRUE)
{
f_close(&logfile.handle);
}
#endif
} /*** end of FileFirmwareUpdateErrorHook ***/
#endif /* BOOT_FILE_ERROR_HOOK_ENABLE > 0 */


#if (BOOT_FILE_LOGGING_ENABLE > 0)
/************************************************************************************//**
** \brief Callback that gets called each time new log information becomes
** available during a firmware update.
** \param info_string Pointer to a character array with the log entry info.
** \return none.
**
****************************************************************************************/
void FileFirmwareUpdateLogHook(blt_char *info_string)
{
/* write the string to the log file */
if (logfile.canUse == BLT_TRUE)
{
if (f_puts(info_string, &logfile.handle) < 0)
{
logfile.canUse = BLT_FALSE;
f_close(&logfile.handle);
}
}
} /*** end of FileFirmwareUpdateLogHook ***/
#endif /* BOOT_FILE_LOGGING_ENABLE > 0 */


#endif /* BOOT_FILE_SYS_ENABLE > 0 */


/****************************************************************************************
* S E E D / K E Y S E C U R I T Y H O O K F U N C T I O N S
****************************************************************************************/
Expand Down
Loading

0 comments on commit 5fd33bf

Please sign in to comment.