The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_VBLUNO51/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/bootloader_dfu/dfu_init.h@169:a7c7b631e539
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2014 Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 3 * All rights reserved.
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * 1. Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 12 * integrated circuit in a product or a software update for such product, must reproduce
AnnaBridge 143:86740a56073b 13 * the above copyright notice, this list of conditions and the following disclaimer in
AnnaBridge 143:86740a56073b 14 * the documentation and/or other materials provided with the distribution.
AnnaBridge 143:86740a56073b 15 *
AnnaBridge 143:86740a56073b 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
AnnaBridge 143:86740a56073b 17 * used to endorse or promote products derived from this software without specific prior
AnnaBridge 143:86740a56073b 18 * written permission.
AnnaBridge 143:86740a56073b 19 *
AnnaBridge 143:86740a56073b 20 * 4. This software, with or without modification, must only be used with a
AnnaBridge 143:86740a56073b 21 * Nordic Semiconductor ASA integrated circuit.
AnnaBridge 143:86740a56073b 22 *
AnnaBridge 143:86740a56073b 23 * 5. Any software provided in binary or object form under this license must not be reverse
AnnaBridge 143:86740a56073b 24 * engineered, decompiled, modified and/or disassembled.
AnnaBridge 143:86740a56073b 25 *
AnnaBridge 143:86740a56073b 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 36 *
AnnaBridge 143:86740a56073b 37 */
AnnaBridge 143:86740a56073b 38
AnnaBridge 143:86740a56073b 39
AnnaBridge 143:86740a56073b 40 /**@file
AnnaBridge 143:86740a56073b 41 *
AnnaBridge 143:86740a56073b 42 * @defgroup nrf_dfu_init Init packet handling in DFU
AnnaBridge 143:86740a56073b 43 * @{
AnnaBridge 143:86740a56073b 44 *
AnnaBridge 143:86740a56073b 45 * @brief Device Firmware Update module type and function declaration for init packet handling.
AnnaBridge 143:86740a56073b 46 *
AnnaBridge 143:86740a56073b 47 * @details This header contains basic functionality for performing safety checks on software
AnnaBridge 143:86740a56073b 48 * updates for \nRFXX based devices. It provides a skeleton for pre-checking an init packet
AnnaBridge 143:86740a56073b 49 * to ensure the following image is compatible with this device. A safety check should
AnnaBridge 143:86740a56073b 50 * always be performed to prevent accidental flashing of unsupported applications or a
AnnaBridge 143:86740a56073b 51 * wrong combination of application and SoftDevice.
AnnaBridge 143:86740a56073b 52 * The device information contains information such as:
AnnaBridge 143:86740a56073b 53 * - Device type (2 bytes), for example Heart Rate. The device type is a number defined by
AnnaBridge 143:86740a56073b 54 * the customer. It can be located in UICR or FICR.
AnnaBridge 143:86740a56073b 55 * - Device revision (2 bytes), for example major revision 1, minor revision 0. The device
AnnaBridge 143:86740a56073b 56 * revision is a number defined by the customer. It can be located in UICR or FICR.
AnnaBridge 143:86740a56073b 57 * - List of SoftDevices supported by this application, for example
AnnaBridge 143:86740a56073b 58 * 0x0049 = S110v6_0_0
AnnaBridge 143:86740a56073b 59 * 0xFFFE = S110 development (any SoftDevice accepted),
AnnaBridge 143:86740a56073b 60 * - CRC or hash of firmware image
AnnaBridge 143:86740a56073b 61 *
AnnaBridge 143:86740a56073b 62 * @note This module does not support security features such as image signing, but the corresponding
AnnaBridge 143:86740a56073b 63 * implementation allows for such extensions.
AnnaBridge 143:86740a56073b 64 * If the init packet is signed by a trusted source, it must be decrypted before it can be
AnnaBridge 143:86740a56073b 65 * processed.
AnnaBridge 143:86740a56073b 66 */
AnnaBridge 143:86740a56073b 67
AnnaBridge 143:86740a56073b 68 #ifndef DFU_INIT_H__
AnnaBridge 143:86740a56073b 69 #define DFU_INIT_H__
AnnaBridge 143:86740a56073b 70
AnnaBridge 143:86740a56073b 71 #include <stdint.h>
AnnaBridge 143:86740a56073b 72 #include "nrf.h"
AnnaBridge 143:86740a56073b 73
AnnaBridge 143:86740a56073b 74 /**@brief Structure contained in an init packet. Contains information on device type, revision, and
AnnaBridge 143:86740a56073b 75 * supported SoftDevices.
AnnaBridge 143:86740a56073b 76 */
AnnaBridge 143:86740a56073b 77 typedef struct
AnnaBridge 143:86740a56073b 78 {
AnnaBridge 143:86740a56073b 79 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. */
AnnaBridge 143:86740a56073b 80 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. */
AnnaBridge 143:86740a56073b 81 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. */
AnnaBridge 143:86740a56073b 82 uint16_t softdevice_len; /**< Number of different SoftDevice revisions compatible with this application. The list of SoftDevice firmware IDs is defined in @ref softdevice. */
AnnaBridge 143:86740a56073b 83 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. */
AnnaBridge 143:86740a56073b 84 } dfu_init_packet_t;
AnnaBridge 143:86740a56073b 85
AnnaBridge 143:86740a56073b 86 /**@brief Structure holding basic device information settings.
AnnaBridge 143:86740a56073b 87 */
AnnaBridge 143:86740a56073b 88 typedef struct
AnnaBridge 143:86740a56073b 89 {
AnnaBridge 143:86740a56073b 90 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. */
AnnaBridge 143:86740a56073b 91 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. */
AnnaBridge 143:86740a56073b 92 } dfu_device_info_t;
AnnaBridge 143:86740a56073b 93
AnnaBridge 143:86740a56073b 94 /** The device info offset can be modified to place the device info settings at a different location.
AnnaBridge 143:86740a56073b 95 * If the customer reserved UICR location is used for other application specific data, the offset
AnnaBridge 143:86740a56073b 96 * must be updated to avoid collision with that data.
AnnaBridge 143:86740a56073b 97 */
AnnaBridge 143:86740a56073b 98 /** [DFU UICR DEV offset] */
AnnaBridge 143:86740a56073b 99 #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. */
AnnaBridge 143:86740a56073b 100 /** [DFU UICR DEV offset] */
AnnaBridge 143:86740a56073b 101
AnnaBridge 143:86740a56073b 102 #define UICR_CUSTOMER_RESERVED_OFFSET 0x80 /**< Customer reserved area in the UICR. The area from UICR + 0x80 is reserved for customer usage. */
AnnaBridge 143:86740a56073b 103 #define DFU_DEVICE_INFO_BASE (NRF_UICR_BASE + \
AnnaBridge 143:86740a56073b 104 UICR_CUSTOMER_RESERVED_OFFSET + \
AnnaBridge 143:86740a56073b 105 UICR_CUSTOMER_DEVICE_INFO_OFFSET) /**< The device information base address inside of UICR. */
AnnaBridge 143:86740a56073b 106 #define DFU_DEVICE_INFO ((dfu_device_info_t *)DFU_DEVICE_INFO_BASE) /**< The memory mapped structure for device information data. */
AnnaBridge 143:86740a56073b 107
AnnaBridge 143:86740a56073b 108 #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. */
AnnaBridge 143:86740a56073b 109 #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. */
AnnaBridge 143:86740a56073b 110 #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. */
AnnaBridge 143:86740a56073b 111
AnnaBridge 143:86740a56073b 112
AnnaBridge 143:86740a56073b 113 /**@brief DFU prevalidate call for pre-checking the received init packet.
AnnaBridge 143:86740a56073b 114 *
AnnaBridge 143:86740a56073b 115 * @details Pre-validation will safety check the firmware image to be transfered in second stage.
AnnaBridge 143:86740a56073b 116 * The function currently checks the device type, device revision, application firmware
AnnaBridge 143:86740a56073b 117 * version, and supported SoftDevices. More checks should be added according to
AnnaBridge 143:86740a56073b 118 * customer-specific requirements.
AnnaBridge 143:86740a56073b 119 *
AnnaBridge 143:86740a56073b 120 * @param[in] p_init_data Pointer to the init packet. If the init packet is encrypted or signed,
AnnaBridge 143:86740a56073b 121 * it must first be decrypted before being checked.
AnnaBridge 143:86740a56073b 122 * @param[in] init_data_len Length of the init data.
AnnaBridge 143:86740a56073b 123 *
AnnaBridge 143:86740a56073b 124 * @retval NRF_SUCCESS If the pre-validation succeeded, that means the image is
AnnaBridge 143:86740a56073b 125 * supported by the device and it is considered to come from a
AnnaBridge 143:86740a56073b 126 * trusted source (signing).
AnnaBridge 143:86740a56073b 127 * @retval NRF_ERROR_INVALID_DATA If the pre-validation failed, that means the image is not
AnnaBridge 143:86740a56073b 128 * supported by the device or comes from an un-trusted source
AnnaBridge 143:86740a56073b 129 * (signing).
AnnaBridge 143:86740a56073b 130 * @retval NRF_ERROR_INVALID_LENGTH If the size of the init packet is not within the limits of
AnnaBridge 143:86740a56073b 131 * the init packet handler.
AnnaBridge 143:86740a56073b 132 */
AnnaBridge 143:86740a56073b 133 uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len);
AnnaBridge 143:86740a56073b 134
AnnaBridge 143:86740a56073b 135 /**@brief DFU postvalidate call for post-checking the received image using the init packet.
AnnaBridge 143:86740a56073b 136 *
AnnaBridge 143:86740a56073b 137 * @details Post-validation can verify the integrity check the firmware image received before
AnnaBridge 143:86740a56073b 138 * activating the image.
AnnaBridge 143:86740a56073b 139 * Checks performed can be:
AnnaBridge 143:86740a56073b 140 * - A simple CRC as shown in the corresponding implementation of this API in the file
AnnaBridge 143:86740a56073b 141 * dfu_init_template.c
AnnaBridge 143:86740a56073b 142 * - A hash for better verification of the image.
AnnaBridge 143:86740a56073b 143 * - A signature to ensure the image originates from a trusted source.
AnnaBridge 143:86740a56073b 144 * Checks are intended to be expanded for customer-specific requirements.
AnnaBridge 143:86740a56073b 145 *
AnnaBridge 143:86740a56073b 146 * @param[in] p_image Pointer to the received image. The init data provided in the call
AnnaBridge 143:86740a56073b 147 * \ref dfu_init_prevalidate will be used for validating the image.
AnnaBridge 143:86740a56073b 148 * @param[in] image_len Length of the image data.
AnnaBridge 143:86740a56073b 149 *
AnnaBridge 143:86740a56073b 150 * @retval NRF_SUCCESS If the post-validation succeeded, that meant the integrity of the
AnnaBridge 143:86740a56073b 151 * image has been verified and the image originates from a trusted
AnnaBridge 143:86740a56073b 152 * source (signing).
AnnaBridge 143:86740a56073b 153 * @retval NRF_ERROR_INVALID_DATA If the post-validation failed, that meant the post check of the
AnnaBridge 143:86740a56073b 154 * image failed such as the CRC is not matching the image transfered
AnnaBridge 143:86740a56073b 155 * or the verification of the image fails (signing).
AnnaBridge 143:86740a56073b 156 */
AnnaBridge 143:86740a56073b 157 uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len);
AnnaBridge 143:86740a56073b 158
AnnaBridge 143:86740a56073b 159 #endif // DFU_INIT_H__
AnnaBridge 143:86740a56073b 160
AnnaBridge 143:86740a56073b 161 /**@} */