Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.

Dependents:   nRF51822 nRF51822

Committer:
vcoubard
Date:
Thu Apr 07 17:37:40 2016 +0100
Revision:
19:47192cb9def7
Parent:
10:233fefd8162b
Child:
20:a90c48eb1d30
Synchronized with git rev 9251259f
Author: Liyou Zhou
Copy over coresponding files from nordic-sdk 9.0.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 19:47192cb9def7 1 /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
vcoubard 19:47192cb9def7 2 *
vcoubard 19:47192cb9def7 3 * The information contained herein is property of Nordic Semiconductor ASA.
vcoubard 19:47192cb9def7 4 * Terms and conditions of usage are described in detail in NORDIC
vcoubard 19:47192cb9def7 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
vcoubard 19:47192cb9def7 6 *
vcoubard 19:47192cb9def7 7 * Licensees are granted free, non-transferable use of the information. NO
vcoubard 19:47192cb9def7 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
vcoubard 19:47192cb9def7 9 * the file.
vcoubard 19:47192cb9def7 10 *
Vincent Coubard 0:f2542974c862 11 */
Vincent Coubard 0:f2542974c862 12
Vincent Coubard 0:f2542974c862 13 /**@file
Vincent Coubard 0:f2542974c862 14 *
Vincent Coubard 0:f2542974c862 15 * @defgroup nrf_dfu_init Init packet handling in DFU.
Vincent Coubard 0:f2542974c862 16 * @{
Vincent Coubard 0:f2542974c862 17 *
Vincent Coubard 0:f2542974c862 18 * @brief Device Firmware Update module type and function declaration for init packet handling.
Vincent Coubard 0:f2542974c862 19 *
Vincent Coubard 0:f2542974c862 20 * @details This header contains basic functionality for performing safety checks on software
Vincent Coubard 0:f2542974c862 21 * updates for nRF51 based devices. It provides a skeleton for pre-checking an init packet
Vincent Coubard 0:f2542974c862 22 * to ensure the following image is compatible with this device. A safety check should
Vincent Coubard 0:f2542974c862 23 * always be performed to prevent accidental flashing of unsupported applications or a
Vincent Coubard 0:f2542974c862 24 * wrong combination of application and SoftDevice.
Vincent Coubard 0:f2542974c862 25 * The device information contains information such as:
Vincent Coubard 0:f2542974c862 26 * - Device type (2 bytes), for example Heart Rate. The device type is a number defined by
Vincent Coubard 0:f2542974c862 27 * the customer. It can be located in UICR or FICR.
Vincent Coubard 0:f2542974c862 28 * - Device revision (2 bytes), for example major revision 1, minor revision 0. The device
Vincent Coubard 0:f2542974c862 29 * revision is a number defined by the customer. It can be located in UICR or FICR.
Vincent Coubard 0:f2542974c862 30 * - List of SoftDevices supported by this application, for example
Vincent Coubard 0:f2542974c862 31 * 0x0049 = S110v6_0_0
Vincent Coubard 0:f2542974c862 32 * 0xFFFE = S110 development (any SoftDevice accepted),
Vincent Coubard 0:f2542974c862 33 * - CRC or hash of firmware image
Vincent Coubard 0:f2542974c862 34 *
Vincent Coubard 0:f2542974c862 35 * @note This module does not support security features such as image signing, but the corresponding
Vincent Coubard 0:f2542974c862 36 * implementation allows for such extensions.
Vincent Coubard 0:f2542974c862 37 * If the init packet is signed by a trusted source, it must be decrypted before it can be
Vincent Coubard 0:f2542974c862 38 * processed.
Vincent Coubard 0:f2542974c862 39 */
Vincent Coubard 0:f2542974c862 40
Vincent Coubard 0:f2542974c862 41 #ifndef DFU_INIT_H__
Vincent Coubard 0:f2542974c862 42 #define DFU_INIT_H__
Vincent Coubard 0:f2542974c862 43
Vincent Coubard 0:f2542974c862 44 #include <stdint.h>
Vincent Coubard 0:f2542974c862 45 #include "nrf51.h"
Vincent Coubard 0:f2542974c862 46
Vincent Coubard 0:f2542974c862 47 /**@brief Structure contained in an init packet. Contains information on device type, revision, and
Vincent Coubard 0:f2542974c862 48 * supported SoftDevices.
Vincent Coubard 0:f2542974c862 49 */
Vincent Coubard 0:f2542974c862 50 typedef struct
Vincent Coubard 0:f2542974c862 51 {
Vincent Coubard 0:f2542974c862 52 uint16_t device_type; /**< Device type (2 bytes), for example Heart Rate. This number must be defined by the customer before production. It can be located in UICR or FICR. */
Vincent Coubard 0:f2542974c862 53 uint16_t device_rev; /**< Device revision (2 bytes), for example major revision 1, minor revision 0. This number must be defined by the customer before production. It can be located in UICR or FICR. */
Vincent Coubard 0:f2542974c862 54 uint32_t app_version; /**< Application version for the image software. This field allows for additional checking, for example ensuring that a downgrade is not allowed. */
Vincent Coubard 0:f2542974c862 55 uint16_t softdevice_len; /**< Number of different SoftDevice revisions compatible with this application. The list of SoftDevice firmware IDs is defined in @ref softdevice. */
Vincent Coubard 0:f2542974c862 56 uint16_t softdevice[1]; /**< Variable length array of SoftDevices compatible with this application. The length of the array is specified in the length field. SoftDevice firmware id 0xFFFE indicates any SoftDevice. */
Vincent Coubard 0:f2542974c862 57 } dfu_init_packet_t;
Vincent Coubard 0:f2542974c862 58
Vincent Coubard 0:f2542974c862 59 /**@brief Structure holding basic device information settings.
Vincent Coubard 0:f2542974c862 60 */
Vincent Coubard 0:f2542974c862 61 typedef struct
Vincent Coubard 0:f2542974c862 62 {
Vincent Coubard 0:f2542974c862 63 uint16_t device_type; /**< Device type (2 bytes), for example Heart Rate. This number must be defined by the customer before production. It can be located in UICR or FICR. */
Vincent Coubard 0:f2542974c862 64 uint16_t device_rev; /**< Device revision (2 bytes), for example major revision 1, minor revision 0. This number must be defined by the customer before production. It can be located in UICR or FICR. */
Vincent Coubard 0:f2542974c862 65 } dfu_device_info_t;
Vincent Coubard 0:f2542974c862 66
Vincent Coubard 0:f2542974c862 67 /** The device info offset can be modified to place the device info settings at a different location.
Vincent Coubard 0:f2542974c862 68 * If the customer reserved UICR location is used for other application specific data, the offset
Vincent Coubard 0:f2542974c862 69 * must be updated to avoid collision with that data.
Vincent Coubard 0:f2542974c862 70 */
Vincent Coubard 0:f2542974c862 71 /** [DFU UICR DEV offset] */
Vincent Coubard 0:f2542974c862 72 #define UICR_CUSTOMER_DEVICE_INFO_OFFSET 0x0 /**< Device info offset inside the customer UICR reserved area. Customers may change this value to place the device information in a user-preferred location. */
Vincent Coubard 0:f2542974c862 73 /** [DFU UICR DEV offset] */
Vincent Coubard 0:f2542974c862 74
Vincent Coubard 0:f2542974c862 75 #define UICR_CUSTOMER_RESERVED_OFFSET 0x80 /**< Customer reserved area in the UICR. The area from UICR + 0x80 is reserved for customer usage. */
Vincent Coubard 0:f2542974c862 76 #define DFU_DEVICE_INFO_BASE (NRF_UICR_BASE + \
Vincent Coubard 0:f2542974c862 77 UICR_CUSTOMER_RESERVED_OFFSET + \
Vincent Coubard 0:f2542974c862 78 UICR_CUSTOMER_DEVICE_INFO_OFFSET) /**< The device information base address inside of UICR. */
Vincent Coubard 0:f2542974c862 79 #define DFU_DEVICE_INFO ((dfu_device_info_t *)DFU_DEVICE_INFO_BASE) /**< The memory mapped structure for device information data. */
Vincent Coubard 0:f2542974c862 80
Vincent Coubard 0:f2542974c862 81 #define DFU_DEVICE_TYPE_EMPTY ((uint16_t)0xFFFF) /**< Mask indicating no device type is present in UICR. 0xFFFF is default flash pattern when not written with data. */
Vincent Coubard 0:f2542974c862 82 #define DFU_DEVICE_REVISION_EMPTY ((uint16_t)0xFFFF) /**< Mask indicating no device revision is present in UICR. 0xFFFF is default flash pattern when not written with data. */
Vincent Coubard 0:f2542974c862 83 #define DFU_SOFTDEVICE_ANY ((uint16_t)0xFFFE) /**< Mask indicating that any SoftDevice is allowed for updating this application. Allows for easy development. Not to be used in production images. */
Vincent Coubard 0:f2542974c862 84
Vincent Coubard 0:f2542974c862 85
Vincent Coubard 0:f2542974c862 86 /**@brief DFU prevalidate call for pre-checking the received init packet.
Vincent Coubard 0:f2542974c862 87 *
Vincent Coubard 0:f2542974c862 88 * @details Pre-validation will safety check the firmware image to be transfered in second stage.
Vincent Coubard 0:f2542974c862 89 * The function currently checks the device type, device revision, application firmware
Vincent Coubard 0:f2542974c862 90 * version, and supported SoftDevices. More checks should be added according to
Vincent Coubard 0:f2542974c862 91 * customer-specific requirements.
Vincent Coubard 0:f2542974c862 92 *
Vincent Coubard 0:f2542974c862 93 * @param[in] p_init_data Pointer to the init packet. If the init packet is encrypted or signed,
Vincent Coubard 0:f2542974c862 94 * it must first be decrypted before being checked.
Vincent Coubard 0:f2542974c862 95 * @param[in] init_data_len Length of the init data.
Vincent Coubard 0:f2542974c862 96 *
Vincent Coubard 0:f2542974c862 97 * @retval NRF_SUCCESS If the pre-validation succeeded, that means the image is
Vincent Coubard 0:f2542974c862 98 * supported by the device and it is considered to come from a
Vincent Coubard 0:f2542974c862 99 * trusted source (signing).
Vincent Coubard 0:f2542974c862 100 * @retval NRF_ERROR_INVALID_DATA If the pre-validation failed, that means the image is not
Vincent Coubard 0:f2542974c862 101 * supported by the device or comes from an un-trusted source
Vincent Coubard 0:f2542974c862 102 * (signing).
Vincent Coubard 0:f2542974c862 103 * @retval NRF_ERROR_INVALID_LENGTH If the size of the init packet is not within the limits of
Vincent Coubard 0:f2542974c862 104 * the init packet handler.
Vincent Coubard 0:f2542974c862 105 */
Vincent Coubard 0:f2542974c862 106 uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len);
Vincent Coubard 0:f2542974c862 107
Vincent Coubard 0:f2542974c862 108 /**@brief DFU postvalidate call for post-checking the received image using the init packet.
Vincent Coubard 0:f2542974c862 109 *
Vincent Coubard 0:f2542974c862 110 * @details Post-validation can verify the integrity check the firmware image received before
Vincent Coubard 0:f2542974c862 111 * activating the image.
Vincent Coubard 0:f2542974c862 112 * Checks performed can be:
Vincent Coubard 0:f2542974c862 113 * - A simple CRC as shown in the corresponding implementation of this API in the file
Vincent Coubard 0:f2542974c862 114 * dfu_init_template.c
Vincent Coubard 0:f2542974c862 115 * - A hash for better verification of the image.
Vincent Coubard 0:f2542974c862 116 * - A signature to ensure the image originates from a trusted source.
Vincent Coubard 0:f2542974c862 117 * Checks are intended to be expanded for customer-specific requirements.
Vincent Coubard 0:f2542974c862 118 *
Vincent Coubard 0:f2542974c862 119 * @param[in] p_image Pointer to the received image. The init data provided in the call
Vincent Coubard 0:f2542974c862 120 * \ref dfu_init_prevalidate will be used for validating the image.
Vincent Coubard 0:f2542974c862 121 * @param[in] image_len Length of the image data.
Vincent Coubard 0:f2542974c862 122 *
Vincent Coubard 0:f2542974c862 123 * @retval NRF_SUCCESS If the post-validation succeeded, that meant the integrity of the
Vincent Coubard 0:f2542974c862 124 * image has been verified and the image originates from a trusted
Vincent Coubard 0:f2542974c862 125 * source (signing).
Vincent Coubard 0:f2542974c862 126 * @retval NRF_ERROR_INVALID_DATA If the post-validation failed, that meant the post check of the
Vincent Coubard 0:f2542974c862 127 * image failed such as the CRC is not matching the image transfered
Vincent Coubard 0:f2542974c862 128 * or the verification of the image fails (signing).
Vincent Coubard 0:f2542974c862 129 */
Vincent Coubard 0:f2542974c862 130 uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len);
Vincent Coubard 0:f2542974c862 131
Vincent Coubard 0:f2542974c862 132 #endif // DFU_INIT_H__
Vincent Coubard 0:f2542974c862 133
vcoubard 1:ebc0e0ef0a11 134 /**@} */