Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/reload dct functions #1868

Merged
merged 3 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bootloader/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ int main(void)
FLASH_UpdateModules(flashModulesCallback);
#ifdef LOAD_DCT_FUNCTIONS
// DCT functions may need to be reloaded after updating a system module
load_dct_functions();
dct_reload_functions();
#endif
#else
if (REFLASH_FROM_BACKUP == 1)
Expand Down
2 changes: 1 addition & 1 deletion bootloader/src/photon/bootloader_dct.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static void init_dct_functions() {
dct_write_app_data_func = dct_write;
}

void load_dct_functions() {
void dct_reload_functions() {
dct_funcs_inited = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion bootloader/src/photon/bootloader_dct.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern "C" {
#endif

void load_dct_functions();
void dct_reload_functions();

#ifdef __cplusplus
} // extern "C"
Expand Down
2 changes: 2 additions & 0 deletions platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/dct.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ int dct_read_app_data_unlock(uint32_t offset);

int dct_write_app_data( const void* data, uint32_t offset, uint32_t size );

void dct_reload_functions();


#ifdef __cplusplus
}
Expand Down
20 changes: 20 additions & 0 deletions platform/MCU/STM32F2xx/STM32_USB_Device_Driver/src/usbd_flash_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
#include "usbd_dfu_mal.h"
#include "usb_bsp.h"
#include "hw_config.h"
#include "platforms.h"
#if PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION || PLATFORM_ID == PLATFORM_P1
#include "module_info.h"
#include "dct.h"
#include "ota_flash_hal.h"

extern const module_bounds_t module_system_part1;
extern const module_bounds_t module_system_part2;
#endif

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
Expand Down Expand Up @@ -155,6 +164,17 @@ uint16_t FLASH_If_Write(uint32_t Add, uint32_t Len)
/* Lock the internal flash */
FLASH_Lock();

/* This make sure that after the system parts being updated,
* the address of DCT functions that resided in system parts are up to date,
* otherwise, bootloader cannot access the DCT after updating the system parts without a reset. */
#if PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION || PLATFORM_ID == PLATFORM_P1
#if MODULE_FUNCTION == MOD_FUNC_BOOTLOADER
if (Add >= module_system_part1.start_address && Add < module_system_part2.end_address) {
dct_reload_functions();
}
#endif
#endif

if (status != FLASH_COMPLETE) return MAL_FAIL;

return MAL_OK;
Expand Down