From b9813e57e141c97f1df309b3141c7288a7bfa387 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Thu, 18 Sep 2014 11:23:22 +0100 Subject: [PATCH] add bootloader dfu related headers to nRF-sdk --- .../nrf-sdk/bootloader_dfu/bootloader_types.h | 57 +++++++++++++++ .../nrf-sdk/bootloader_dfu/bootloader_util.h | 38 ++++++++++ .../nrf-sdk/bootloader_dfu/dfu_app_handler.h | 72 +++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100755 nordic/nrf-sdk/bootloader_dfu/bootloader_types.h create mode 100755 nordic/nrf-sdk/bootloader_dfu/bootloader_util.h create mode 100755 nordic/nrf-sdk/bootloader_dfu/dfu_app_handler.h diff --git a/nordic/nrf-sdk/bootloader_dfu/bootloader_types.h b/nordic/nrf-sdk/bootloader_dfu/bootloader_types.h new file mode 100755 index 0000000..badb3a7 --- /dev/null +++ b/nordic/nrf-sdk/bootloader_dfu/bootloader_types.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +/**@file + * + * @defgroup nrf_bootloader_types Types and definitions. + * @{ + * + * @ingroup nrf_bootloader + * + * @brief Bootloader module type and definitions. + */ + +#ifndef BOOTLOADER_TYPES_H__ +#define BOOTLOADER_TYPES_H__ + +#include + +#define BOOTLOADER_DFU_START 0xB1 + +/**@brief DFU Bank state code, which indicates wether the bank contains: A valid image, invalid image, or an erased flash. + */ +typedef enum +{ + BANK_VALID_APP = 0x01, + BANK_VALID_SD = 0xA5, + BANK_VALID_BOOT = 0xAA, + BANK_ERASED = 0xFE, + BANK_INVALID_APP = 0xFF, +} bootloader_bank_code_t; + +/**@brief Structure holding bootloader settings for application and bank data. + */ +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 \ref BANK_VALID_SD. */ + uint32_t bl_image_size; /**< Size of Bootloader image in bank0 if bank_0 code is \ref BANK_VALID_SD. */ + uint32_t app_image_size; /**< Size of Application image in bank0 if bank_0 code is \ref 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__ + +/**@} */ diff --git a/nordic/nrf-sdk/bootloader_dfu/bootloader_util.h b/nordic/nrf-sdk/bootloader_dfu/bootloader_util.h new file mode 100755 index 0000000..aefd764 --- /dev/null +++ b/nordic/nrf-sdk/bootloader_dfu/bootloader_util.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + + /**@file + * + * @defgroup nrf_bootloader_util Bootloader util API. + * @{ + * + * @brief Bootloader util module interface. + */ + +#ifndef BOOTLOADER_UTIL_H__ +#define BOOTLOADER_UTIL_H__ + +#include +#include "bootloader_types.h" + +/**@brief Function for starting the application (or bootloader) at the provided address. + * + * @param[in] start_addr Start address. + * + * @note This function will never retrun. Instead it will reset into the application of the + * provided address. + */ +void bootloader_util_app_start(uint32_t start_addr); + +#endif // BOOTLOADER_UTIL_H__ + +/**@} */ diff --git a/nordic/nrf-sdk/bootloader_dfu/dfu_app_handler.h b/nordic/nrf-sdk/bootloader_dfu/dfu_app_handler.h new file mode 100755 index 0000000..27436f4 --- /dev/null +++ b/nordic/nrf-sdk/bootloader_dfu/dfu_app_handler.h @@ -0,0 +1,72 @@ +/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +/** @file + * + * @defgroup nrf_dfu_app_handler DFU BLE packet handling in Application + * @{ + * + * @brief DFU BLE packet handling for application. + * + * @details This module implements handling of DFU packets transmitted over BLE for switching from + * application mode to Bootloader running full DFU service. + * This module only handles the StartDFU packet allowing for any BLE application to expose + * support for the DFU service. + * Actual DFU service will execute in dedicated environment after a BLE disconnect and + * reset of the nRF51 chip. + * The host must then reconnect and can continue the update procedure with access to full + * DFU service. + * + * @note The application must propagate dfu events to the DFU App handler module by calling + * dfu_app_on_dfu_evt() from the from the @ref ble_dfu_evt_handler_t callback. + */ + +#ifndef DFU_APP_HANDLER_H__ +#define DFU_APP_HANDLER_H__ + +#include "dfu_app_handler.h" +#include "ble_dfu.h" + +/**@brief DFU Application reset prepare function. This function is a callback which allows the + * application to prepare for an upcoming application reset. + */ +typedef void (*dfu_app_reset_prepare_t)(void); + + +/**@brief Function for handling of \ref ble_dfu_evt_t from DFU Service. + * + * @details The application must inject this function into the DFU service or propagate DFU events + * to dfu_app_handler module by calling this function in application specific DFU event + * handler. + * + * @param[in] p_dfu Pointer to the DFU Service structure for which the include event relates. + * @param[in] p_evt Pointer to the DFU event. + */ +void dfu_app_on_dfu_evt(ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt); + + +/**@brief Function for registering for reset prepare calls. + * + * @details The function provided will be executed before reseting the system into Bootloader/DFU + * mode. By setting this function the caller will be notified prior to the reset and can + * thus prepare the application for reset. As example the application can gracefully + * disconnect any peers on BLE, turning of LEDS, ensure all pending flash operations + * has completed, etc. + * + * @param[in] reset_prepare_func Function to be execute prior to a reset. + */ +void dfu_app_reset_prepare_set(dfu_app_reset_prepare_t reset_prepare_func); + + +#endif // DFU_APP_HANDLER_H__ + +/** @} */