BLE FOTA APP

Dependencies:   BLE_API mbed

It doesn't work with the default FOTA bootloader. It use NVIC_SystemReset() to enter a bootloader.

Committer:
yihui
Date:
Fri Oct 10 03:36:28 2014 +0000
Revision:
1:a607cd9655d7
use NVIC_SystemReset() to run bootloader

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 1:a607cd9655d7 1 /*
yihui 1:a607cd9655d7 2 * Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
yihui 1:a607cd9655d7 3 *
yihui 1:a607cd9655d7 4 * The information contained herein is confidential property of Nordic Semiconductor. The use,
yihui 1:a607cd9655d7 5 * copying, transfer or disclosure of such information is prohibited except by express written
yihui 1:a607cd9655d7 6 * agreement with Nordic Semiconductor.
yihui 1:a607cd9655d7 7 *
yihui 1:a607cd9655d7 8 */
yihui 1:a607cd9655d7 9 /**
yihui 1:a607cd9655d7 10 @defgroup nrf_mbr_api Master Boot Record API
yihui 1:a607cd9655d7 11 @{
yihui 1:a607cd9655d7 12
yihui 1:a607cd9655d7 13 @brief APIs for updating SoftDevice and BootLoader
yihui 1:a607cd9655d7 14
yihui 1:a607cd9655d7 15 */
yihui 1:a607cd9655d7 16
yihui 1:a607cd9655d7 17 /* Header guard */
yihui 1:a607cd9655d7 18 #ifndef NRF_MBR_H__
yihui 1:a607cd9655d7 19 #define NRF_MBR_H__
yihui 1:a607cd9655d7 20
yihui 1:a607cd9655d7 21 #include "nrf_svc.h"
yihui 1:a607cd9655d7 22 #include <stdint.h>
yihui 1:a607cd9655d7 23
yihui 1:a607cd9655d7 24
yihui 1:a607cd9655d7 25 /** @addtogroup NRF_MBR_DEFINES Defines
yihui 1:a607cd9655d7 26 * @{ */
yihui 1:a607cd9655d7 27
yihui 1:a607cd9655d7 28 /**@brief MBR SVC Base number. */
yihui 1:a607cd9655d7 29 #define MBR_SVC_BASE 0x18
yihui 1:a607cd9655d7 30 /** @} */
yihui 1:a607cd9655d7 31
yihui 1:a607cd9655d7 32 /** @addtogroup NRF_MBR_ENUMS Enumerations
yihui 1:a607cd9655d7 33 * @{ */
yihui 1:a607cd9655d7 34
yihui 1:a607cd9655d7 35 /**@brief nRF Master Boot Record API SVC numbers. */
yihui 1:a607cd9655d7 36 enum NRF_MBR_SVCS
yihui 1:a607cd9655d7 37 {
yihui 1:a607cd9655d7 38 SD_MBR_COMMAND = MBR_SVC_BASE, /**< ::sd_mbr_command */
yihui 1:a607cd9655d7 39 };
yihui 1:a607cd9655d7 40
yihui 1:a607cd9655d7 41 /**@brief Possible values for ::sd_mbr_command_t.command */
yihui 1:a607cd9655d7 42 enum NRF_MBR_COMMANDS
yihui 1:a607cd9655d7 43 {
yihui 1:a607cd9655d7 44 SD_MBR_COMMAND_COPY_BL, /**< Copy a new a new BootLoader. @see sd_mbr_command_copy_bl_t */
yihui 1:a607cd9655d7 45 SD_MBR_COMMAND_COPY_SD, /**< Copy a new SoftDevice. @see ::sd_mbr_command_copy_sd_t*/
yihui 1:a607cd9655d7 46 SD_MBR_COMMAND_INIT_SD, /**< Init forwarding interrupts to SD, and run reset function in SD*/
yihui 1:a607cd9655d7 47 SD_MBR_COMMAND_COMPARE, /**< This command works like memcmp. @see ::sd_mbr_command_compare_t*/
yihui 1:a607cd9655d7 48 SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET, /**< Start forwarding all exception to this address @see ::sd_mbr_command_vector_table_base_set_t*/
yihui 1:a607cd9655d7 49 };
yihui 1:a607cd9655d7 50
yihui 1:a607cd9655d7 51 /** @} */
yihui 1:a607cd9655d7 52
yihui 1:a607cd9655d7 53 /** @addtogroup NRF_MBR_TYPES Types
yihui 1:a607cd9655d7 54 * @{ */
yihui 1:a607cd9655d7 55
yihui 1:a607cd9655d7 56 /**@brief This command copies part of a new SoftDevice
yihui 1:a607cd9655d7 57 * The destination area is erased before copying.
yihui 1:a607cd9655d7 58 * If dst is in the middle of a flash page, that whole flash page will be erased.
yihui 1:a607cd9655d7 59 * If (dst+len) is in the middle of a flash page, that whole flash page will be erased.
yihui 1:a607cd9655d7 60 *
yihui 1:a607cd9655d7 61 * The user of this function is responsible for setting the PROTENSET registers.
yihui 1:a607cd9655d7 62 *
yihui 1:a607cd9655d7 63 * @retval ::NRF_SUCCESS indicates that the contents of the memory blocks where copied correctly.
yihui 1:a607cd9655d7 64 * @retval ::NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying.
yihui 1:a607cd9655d7 65 */
yihui 1:a607cd9655d7 66 typedef struct
yihui 1:a607cd9655d7 67 {
yihui 1:a607cd9655d7 68 uint32_t *src; /**< Pointer to the source of data to be copied.*/
yihui 1:a607cd9655d7 69 uint32_t *dst; /**< Pointer to the destination where the content is to be copied.*/
yihui 1:a607cd9655d7 70 uint32_t len; /**< Number of 32 bit words to copy. Must be a multiple of 256 words*/
yihui 1:a607cd9655d7 71 }sd_mbr_command_copy_sd_t;
yihui 1:a607cd9655d7 72
yihui 1:a607cd9655d7 73
yihui 1:a607cd9655d7 74 /**@brief This command works like memcmp, but takes the length in words.
yihui 1:a607cd9655d7 75 *
yihui 1:a607cd9655d7 76 * @retval ::NRF_SUCCESS indicates that the contents of both memory blocks are equal.
yihui 1:a607cd9655d7 77 * @retval ::NRF_ERROR_NULL indicates that the contents of the memory blocks are not equal.
yihui 1:a607cd9655d7 78 */
yihui 1:a607cd9655d7 79 typedef struct
yihui 1:a607cd9655d7 80 {
yihui 1:a607cd9655d7 81 uint32_t *ptr1; /**< Pointer to block of memory */
yihui 1:a607cd9655d7 82 uint32_t *ptr2; /**< Pointer to block of memory */
yihui 1:a607cd9655d7 83 uint32_t len; /**< Number of 32 bit words to compare*/
yihui 1:a607cd9655d7 84 }sd_mbr_command_compare_t;
yihui 1:a607cd9655d7 85
yihui 1:a607cd9655d7 86
yihui 1:a607cd9655d7 87 /**@brief This command copies a new BootLoader.
yihui 1:a607cd9655d7 88 * With this command, destination of BootLoader is always the address written in NRF_UICR->BOOTADDR.
yihui 1:a607cd9655d7 89 *
yihui 1:a607cd9655d7 90 * Destination is erased by this function.
yihui 1:a607cd9655d7 91 * If (destination+bl_len) is in the middle of a flash page, that whole flash page will be erased.
yihui 1:a607cd9655d7 92 *
yihui 1:a607cd9655d7 93 * This function will use PROTENSET to protect the flash that is not intended to be written.
yihui 1:a607cd9655d7 94 *
yihui 1:a607cd9655d7 95 * On Success, this function will not return. It will start the new BootLoader from reset-vector as normal.
yihui 1:a607cd9655d7 96 *
yihui 1:a607cd9655d7 97 * @retval ::NRF_ERROR_INVALID_STATE indicates that something was wrong.
yihui 1:a607cd9655d7 98 * @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
yihui 1:a607cd9655d7 99 * @retval ::NRF_ERROR_FORBIDDEN if NRF_UICR->BOOTADDR is not set
yihui 1:a607cd9655d7 100 * @retval ::NRF_ERROR_INVALID_LENGTH is invalid.
yihui 1:a607cd9655d7 101 */
yihui 1:a607cd9655d7 102 typedef struct
yihui 1:a607cd9655d7 103 {
yihui 1:a607cd9655d7 104 uint32_t *bl_src; /**< Pointer to the source of the Bootloader to be be copied.*/
yihui 1:a607cd9655d7 105 uint32_t bl_len; /**< Number of 32 bit words to copy for BootLoader */
yihui 1:a607cd9655d7 106 }sd_mbr_command_copy_bl_t;
yihui 1:a607cd9655d7 107
yihui 1:a607cd9655d7 108 /**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the MBR
yihui 1:a607cd9655d7 109 *
yihui 1:a607cd9655d7 110 * Once this function has been called, this address is where the MBR will start to forward interrupts to after a reset.
yihui 1:a607cd9655d7 111 *
yihui 1:a607cd9655d7 112 * To restore default forwarding thiss function should be called with @param address set to 0.
yihui 1:a607cd9655d7 113 * The MBR will then start forwarding to interrupts to the adress in NFR_UICR->BOOTADDR or to the SoftDevice if the BOOTADDR is not set.
yihui 1:a607cd9655d7 114 *
yihui 1:a607cd9655d7 115 * @retval ::NRF_SUCCESS
yihui 1:a607cd9655d7 116 */
yihui 1:a607cd9655d7 117 typedef struct
yihui 1:a607cd9655d7 118 {
yihui 1:a607cd9655d7 119 uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
yihui 1:a607cd9655d7 120 }sd_mbr_command_vector_table_base_set_t;
yihui 1:a607cd9655d7 121
yihui 1:a607cd9655d7 122 typedef struct
yihui 1:a607cd9655d7 123 {
yihui 1:a607cd9655d7 124 uint32_t command; /**< type of command to be issued see @ref NRF_MBR_COMMANDS. */
yihui 1:a607cd9655d7 125 union
yihui 1:a607cd9655d7 126 {
yihui 1:a607cd9655d7 127 sd_mbr_command_copy_sd_t copy_sd; /**< Parameters for copy*/
yihui 1:a607cd9655d7 128 sd_mbr_command_copy_bl_t copy_bl; /**< Parameters for copy SoftDevice and BootLoader*/
yihui 1:a607cd9655d7 129 sd_mbr_command_compare_t compare; /**< Parameters for verify*/
yihui 1:a607cd9655d7 130 sd_mbr_command_vector_table_base_set_t base_set; /**< Parameters for vector table base set.*/
yihui 1:a607cd9655d7 131 } params;
yihui 1:a607cd9655d7 132 }sd_mbr_command_t;
yihui 1:a607cd9655d7 133
yihui 1:a607cd9655d7 134 /** @} */
yihui 1:a607cd9655d7 135
yihui 1:a607cd9655d7 136 /** @addtogroup NRF_MBR_FUNCTIONS Functions
yihui 1:a607cd9655d7 137 * @{ */
yihui 1:a607cd9655d7 138
yihui 1:a607cd9655d7 139 /**@brief Issue Master Boot Record commands
yihui 1:a607cd9655d7 140 *
yihui 1:a607cd9655d7 141 * Commands used when updating a SoftDevice and bootloader
yihui 1:a607cd9655d7 142 *
yihui 1:a607cd9655d7 143 * @param[in] param Pointer to a struct describing the command
yihui 1:a607cd9655d7 144 *
yihui 1:a607cd9655d7 145 *@note for retvals see ::sd_mbr_command_copy_sd_t ::sd_mbr_command_copy_bl_t ::sd_mbr_command_compare_t
yihui 1:a607cd9655d7 146
yihui 1:a607cd9655d7 147 */
yihui 1:a607cd9655d7 148 SVCALL(SD_MBR_COMMAND, uint32_t, sd_mbr_command(sd_mbr_command_t* param));
yihui 1:a607cd9655d7 149
yihui 1:a607cd9655d7 150 /** @} */
yihui 1:a607cd9655d7 151 #endif // NRF_MBR_H__
yihui 1:a607cd9655d7 152
yihui 1:a607cd9655d7 153 /**
yihui 1:a607cd9655d7 154 @}
yihui 1:a607cd9655d7 155 */