mesh/bootloader/include/dfu_types_mesh.h | 2 +- mesh/bootloader/src/bootloader_info.c | 4 ++-- mesh/bootloader/src/dfu_bank.c | 25 ++++++++++++++----------- mesh/core/include/bl_info_types.h | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/mesh/bootloader/include/dfu_types_mesh.h b/mesh/bootloader/include/dfu_types_mesh.h index fff0f1531..88f90025e 100644 --- a/mesh/bootloader/include/dfu_types_mesh.h +++ b/mesh/bootloader/include/dfu_types_mesh.h @@ -265,7 +265,7 @@ typedef struct /** * State of info bank. Written to allow state machine progression being stored - * in flash without needing erase. + * in flash. */ typedef enum { diff --git a/mesh/bootloader/src/bootloader_info.c b/mesh/bootloader/src/bootloader_info.c index 316250596..00d66a205 100644 --- a/mesh/bootloader/src/bootloader_info.c +++ b/mesh/bootloader/src/bootloader_info.c @@ -48,7 +48,7 @@ #define HEADER_LEN (sizeof(bootloader_info_header_t)) -#define INFO_WRITE_BUFLEN (128) +#define INFO_WRITE_BUFLEN (256) typedef enum { @@ -60,7 +60,7 @@ typedef enum BL_INFO_STATE_RECOVER } bl_info_state_t; -typedef struct +typedef struct __attribute__((aligned(4))) { uint16_t len; uint16_t type; diff --git a/mesh/bootloader/src/dfu_bank.c b/mesh/bootloader/src/dfu_bank.c index e570c14f6..f276be907 100644 --- a/mesh/bootloader/src/dfu_bank.c +++ b/mesh/bootloader/src/dfu_bank.c @@ -217,8 +217,8 @@ static void flash_bank_entry(void) /* Wait for this to take effect before moving on, as the potential mbr commands in the flash_fw state may trigger sudden reboots. */ - break; } + break; case BL_INFO_BANK_STATE_FLASH_FW: m_waiting_for_idle = true; @@ -297,23 +297,26 @@ static void flash_bank_entry(void) /* Update state */ __LOG("Bank: Set state to FLASHED\n"); + m_waiting_for_idle = true; bank_entry_replacement.bank.state = BL_INFO_BANK_STATE_FLASHED; (void) bootloader_info_entry_overwrite((bl_info_type_t) (BL_INFO_TYPE_BANK_BASE + m_dfu_type), &bank_entry_replacement); - } - /* deliberate fallthrough */ + break; case BL_INFO_BANK_STATE_FLASHED: - /* We may invalidate the bank entry in the device page now, - it's all redundant. */ - __LOG("Bank: Invalidate.\n"); - if (bootloader_info_entry_invalidate((bl_info_type_t) (BL_INFO_TYPE_BANK_BASE + m_dfu_type)) == NRF_SUCCESS) { + /* We need to invalidate the bank entry in the device page now. */ + m_waiting_for_idle = true; + (void) bootloader_info_entry_invalidate((bl_info_type_t) (BL_INFO_TYPE_BANK_BASE + m_dfu_type)); __LOG("Bank invalidated.\n"); + + /* clean up bank area since it may be used for application data. */ + bl_evt_t flash_evt; + flash_evt.type = BL_EVT_TYPE_FLASH_ERASE; + flash_evt.params.flash.erase.start_addr = (uint32_t)p_bank_entry->p_bank_addr; + flash_evt.params.flash.erase.length = p_bank_entry->length; + (void) bootloader_evt_send(&flash_evt); mp_bank_entry = NULL; /* reset the static bank pointer, as we no longer need it. */ - } - else - { - m_waiting_for_idle = true; + __LOG("Bank area cleared.\n"); } break; } diff --git a/mesh/core/include/bl_info_types.h b/mesh/core/include/bl_info_types.h index 729c0596a..c66696ecf 100644 --- a/mesh/core/include/bl_info_types.h +++ b/mesh/core/include/bl_info_types.h @@ -107,7 +107,7 @@ typedef struct /** * State of info bank. Written to allow state machine progression being stored - * in flash without needing erase. + * in flash. */ typedef enum {