@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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__ 
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user