close #18, close #19

softdevice is only enabled with OTA mode
This commit is contained in:
hathach 2018-08-13 21:50:55 +07:00
parent fe712fb588
commit 1c2911a63c
6 changed files with 23 additions and 41 deletions

View File

@ -29,6 +29,8 @@
#include "nrfx.h"
#include "app_timer.h"
#include "boards.h"
#ifdef NRF52840_XXAA
#include "tusb.h"
#endif
@ -58,9 +60,6 @@ typedef enum
static pstorage_handle_t m_bootsettings_handle; /**< Pstorage handle to use for registration and identifying the bootloader module on subsequent calls to the pstorage module for load and store of bootloader setting in flash. */
static bootloader_status_t m_update_status; /**< Current update status for the bootloader module to ensure correct behaviour when updating settings and when update completes. */
// Adafruit modification for dual transports and forced startup DFU
extern bool is_ota(void);
APP_TIMER_DEF( _forced_startup_dfu_timer );
volatile bool forced_startup_dfu_packet_received = false;
volatile static bool _terminate_startup_dfu = false;
@ -182,10 +181,7 @@ bool bootloader_app_is_valid(uint32_t app_addr)
static void bootloader_settings_save(bootloader_settings_t * p_settings)
{
uint8_t sd_en = false;
sd_softdevice_is_enabled(&sd_en);
if ( sd_en )
if ( is_ota() )
{
uint32_t err_code = pstorage_clear(&m_bootsettings_handle, sizeof(bootloader_settings_t));
APP_ERROR_CHECK(err_code);

View File

@ -44,14 +44,14 @@ typedef enum
*/
typedef struct
{
bootloader_bank_code_t bank_0; /**< Variable to store if bank 0 contains a valid application. */
uint16_t bank_0_crc; /**< If bank is valid, this field will contain a valid CRC of the total image. */
bootloader_bank_code_t bank_1; /**< Variable to store if bank 1 has been erased/prepared for new image. Bank 1 is only used in Banked Update scenario. */
uint32_t bank_0_size; /**< Size of active image in bank0 if present, otherwise 0. */
uint32_t sd_image_size; /**< Size of SoftDevice image in bank0 if bank_0 code is BANK_VALID_SD. */
uint32_t bl_image_size; /**< Size of Bootloader image in bank0 if bank_0 code is BANK_VALID_SD. */
uint32_t app_image_size; /**< Size of Application image in bank0 if bank_0 code is BANK_VALID_SD. */
uint32_t sd_image_start; /**< Location in flash where SoftDevice image is stored for SoftDevice update. */
uint16_t bank_0; /**< Variable to store if bank 0 contains a valid application. */
uint16_t bank_0_crc; /**< If bank is valid, this field will contain a valid CRC of the total image. */
uint16_t bank_1; /**< Variable to store if bank 1 has been erased/prepared for new image. Bank 1 is only used in Banked Update scenario. */
uint32_t bank_0_size; /**< Size of active image in bank0 if present, otherwise 0. */
uint32_t sd_image_size; /**< Size of SoftDevice image in bank0 if bank_0 code is BANK_VALID_SD. */
uint32_t bl_image_size; /**< Size of Bootloader image in bank0 if bank_0 code is BANK_VALID_SD. */
uint32_t app_image_size; /**< Size of Application image in bank0 if bank_0 code is BANK_VALID_SD. */
uint32_t sd_image_start; /**< Location in flash where SoftDevice image is stored for SoftDevice update. */
} bootloader_settings_t;
#endif // BOOTLOADER_TYPES_H__

View File

@ -25,6 +25,8 @@
#include "dfu_init.h"
#include "sdk_common.h"
#include "boards.h"
static dfu_state_t m_dfu_state; /**< Current DFU state. */
static uint32_t m_image_size; /**< Size of the image that will be transmitted. */
@ -136,10 +138,7 @@ static void dfu_prepare_func_app_erase(uint32_t image_size)
// for new SoftDevice.
m_dfu_state = DFU_STATE_PREPARING;
uint8_t sd_en = false;
sd_softdevice_is_enabled(&sd_en);
if ( sd_en )
if ( is_ota() )
{
uint32_t err_code;
err_code = pstorage_clear(&m_storage_handle_app, m_image_size);
@ -421,10 +420,7 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet)
p_data = (uint32_t *)p_packet->params.data_packet.p_data_packet;
uint8_t sd_en = false;
sd_softdevice_is_enabled(&sd_en);
if ( sd_en )
if ( is_ota() )
{
err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received);
VERIFY_SUCCESS(err_code);
@ -445,7 +441,7 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet)
}
else
{
if (!sd_en) flash_flush();
if ( !is_ota() ) flash_flush();
// The entire image has been received. Return NRF_SUCCESS.
err_code = NRF_SUCCESS;

View File

@ -70,4 +70,7 @@ static inline bool button_pressed(uint32_t pin)
}
bool is_ota(void);
#endif

View File

@ -299,13 +299,6 @@ uint32_t softdev_init(bool init_softdevice)
return NRF_SUCCESS;
}
void softdev_teardown(void)
{
sd_softdevice_disable();
}
int main(void)
{
// SD is already Initialized in case of BOOTLOADER_DFU_OTA_MAGIC
@ -330,17 +323,12 @@ int main(void)
board_init();
bootloader_init();
// When updating SoftDevice, bootloader will reset before swapping SD
if (bootloader_dfu_sd_in_progress())
{
APP_ERROR_CHECK( bootloader_dfu_sd_update_continue() );
softdev_init(!sd_inited);
sd_inited = true;
APP_ERROR_CHECK( bootloader_dfu_sd_update_finalize() );
}
else
{
// softdev_init();
}
/*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/
// DFU button pressed
@ -362,6 +350,8 @@ int main(void)
// Initiate an update of the firmware.
APP_ERROR_CHECK( bootloader_dfu_start(_ota_update, 0) );
if ( _ota_update ) sd_softdevice_disable();
}
#ifdef NRF52832_XXAA
else
@ -373,9 +363,6 @@ int main(void)
}
#endif
// we are all done with DFU, disable soft device
softdev_teardown();
/*------------- Adafruit Factory reset -------------*/
if ( !button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET) )
{

View File

@ -1,5 +1,5 @@
#define UF2_VERSION "1.00"
#define PRODUCT_NAME "Adafruit Bluefruit nRF52"
#define PRODUCT_NAME "Adafruit Bluefruit nRF52840"
#define BOARD_ID "NRF52-Bluefruit-v0"
#define INDEX_URL "https://www.adafruit.com/product/0000"
#define BOOTLOADER_ID MK_DIS_FIRMWARE