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.
TARGET_TY51822R3/TOOLCHAIN_IAR/nrf_mbr.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 146:22da6e220af6 | 1 | /* |
AnnaBridge | 146:22da6e220af6 | 2 | * Copyright (c) 2000 Nordic Semiconductor ASA |
AnnaBridge | 146:22da6e220af6 | 3 | * All rights reserved. |
AnnaBridge | 146:22da6e220af6 | 4 | * |
AnnaBridge | 146:22da6e220af6 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AnnaBridge | 146:22da6e220af6 | 6 | * are permitted provided that the following conditions are met: |
AnnaBridge | 146:22da6e220af6 | 7 | * |
AnnaBridge | 146:22da6e220af6 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this list |
AnnaBridge | 146:22da6e220af6 | 9 | * of conditions and the following disclaimer. |
AnnaBridge | 146:22da6e220af6 | 10 | * |
AnnaBridge | 146:22da6e220af6 | 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA |
AnnaBridge | 146:22da6e220af6 | 12 | * integrated circuit in a product or a software update for such product, must reproduce |
AnnaBridge | 146:22da6e220af6 | 13 | * the above copyright notice, this list of conditions and the following disclaimer in |
AnnaBridge | 146:22da6e220af6 | 14 | * the documentation and/or other materials provided with the distribution. |
AnnaBridge | 146:22da6e220af6 | 15 | * |
AnnaBridge | 146:22da6e220af6 | 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be |
AnnaBridge | 146:22da6e220af6 | 17 | * used to endorse or promote products derived from this software without specific prior |
AnnaBridge | 146:22da6e220af6 | 18 | * written permission. |
AnnaBridge | 146:22da6e220af6 | 19 | * |
AnnaBridge | 146:22da6e220af6 | 20 | * 4. This software, with or without modification, must only be used with a |
AnnaBridge | 146:22da6e220af6 | 21 | * Nordic Semiconductor ASA integrated circuit. |
AnnaBridge | 146:22da6e220af6 | 22 | * |
AnnaBridge | 146:22da6e220af6 | 23 | * 5. Any software provided in binary or object form under this license must not be reverse |
AnnaBridge | 146:22da6e220af6 | 24 | * engineered, decompiled, modified and/or disassembled. |
AnnaBridge | 146:22da6e220af6 | 25 | * |
AnnaBridge | 146:22da6e220af6 | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AnnaBridge | 146:22da6e220af6 | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AnnaBridge | 146:22da6e220af6 | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AnnaBridge | 146:22da6e220af6 | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AnnaBridge | 146:22da6e220af6 | 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AnnaBridge | 146:22da6e220af6 | 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AnnaBridge | 146:22da6e220af6 | 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AnnaBridge | 146:22da6e220af6 | 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AnnaBridge | 146:22da6e220af6 | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AnnaBridge | 146:22da6e220af6 | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AnnaBridge | 146:22da6e220af6 | 36 | * |
AnnaBridge | 146:22da6e220af6 | 37 | */ |
AnnaBridge | 146:22da6e220af6 | 38 | |
AnnaBridge | 146:22da6e220af6 | 39 | /** |
AnnaBridge | 146:22da6e220af6 | 40 | @defgroup nrf_mbr_api Master Boot Record API |
AnnaBridge | 146:22da6e220af6 | 41 | @{ |
AnnaBridge | 146:22da6e220af6 | 42 | |
AnnaBridge | 146:22da6e220af6 | 43 | @brief APIs for updating SoftDevice and BootLoader |
AnnaBridge | 146:22da6e220af6 | 44 | |
AnnaBridge | 146:22da6e220af6 | 45 | */ |
AnnaBridge | 146:22da6e220af6 | 46 | |
AnnaBridge | 146:22da6e220af6 | 47 | /* Header guard */ |
AnnaBridge | 146:22da6e220af6 | 48 | #ifndef NRF_MBR_H__ |
AnnaBridge | 146:22da6e220af6 | 49 | #define NRF_MBR_H__ |
AnnaBridge | 146:22da6e220af6 | 50 | |
AnnaBridge | 146:22da6e220af6 | 51 | #include "nrf_svc.h" |
AnnaBridge | 146:22da6e220af6 | 52 | #include <stdint.h> |
AnnaBridge | 146:22da6e220af6 | 53 | |
AnnaBridge | 146:22da6e220af6 | 54 | #ifndef NRF51 |
AnnaBridge | 146:22da6e220af6 | 55 | #error "This header file shall only be included for nRF51 projects" |
AnnaBridge | 146:22da6e220af6 | 56 | #endif |
AnnaBridge | 146:22da6e220af6 | 57 | |
AnnaBridge | 146:22da6e220af6 | 58 | #ifdef __cplusplus |
AnnaBridge | 146:22da6e220af6 | 59 | extern "C" { |
AnnaBridge | 146:22da6e220af6 | 60 | #endif |
AnnaBridge | 146:22da6e220af6 | 61 | |
AnnaBridge | 146:22da6e220af6 | 62 | /** @addtogroup NRF_MBR_DEFINES Defines |
AnnaBridge | 146:22da6e220af6 | 63 | * @{ */ |
AnnaBridge | 146:22da6e220af6 | 64 | |
AnnaBridge | 146:22da6e220af6 | 65 | /**@brief MBR SVC Base number. */ |
AnnaBridge | 146:22da6e220af6 | 66 | #define MBR_SVC_BASE (0x18) |
AnnaBridge | 146:22da6e220af6 | 67 | |
AnnaBridge | 146:22da6e220af6 | 68 | /**@brief Page size in words. */ |
AnnaBridge | 146:22da6e220af6 | 69 | #define PAGE_SIZE_IN_WORDS 256 |
AnnaBridge | 146:22da6e220af6 | 70 | /** @} */ |
AnnaBridge | 146:22da6e220af6 | 71 | |
AnnaBridge | 146:22da6e220af6 | 72 | /** @brief The size that must be reserved for the MBR when a softdevice is written to flash. |
AnnaBridge | 146:22da6e220af6 | 73 | This is the offset where the first byte of the softdevice hex file is written.*/ |
AnnaBridge | 146:22da6e220af6 | 74 | #define MBR_SIZE (0x1000) |
AnnaBridge | 146:22da6e220af6 | 75 | |
AnnaBridge | 146:22da6e220af6 | 76 | /** @addtogroup NRF_MBR_ENUMS Enumerations |
AnnaBridge | 146:22da6e220af6 | 77 | * @{ */ |
AnnaBridge | 146:22da6e220af6 | 78 | |
AnnaBridge | 146:22da6e220af6 | 79 | /**@brief nRF Master Boot Record API SVC numbers. */ |
AnnaBridge | 146:22da6e220af6 | 80 | enum NRF_MBR_SVCS |
AnnaBridge | 146:22da6e220af6 | 81 | { |
AnnaBridge | 146:22da6e220af6 | 82 | SD_MBR_COMMAND = MBR_SVC_BASE, /**< ::sd_mbr_command */ |
AnnaBridge | 146:22da6e220af6 | 83 | }; |
AnnaBridge | 146:22da6e220af6 | 84 | |
AnnaBridge | 146:22da6e220af6 | 85 | /**@brief Possible values for ::sd_mbr_command_t.command */ |
AnnaBridge | 146:22da6e220af6 | 86 | enum NRF_MBR_COMMANDS |
AnnaBridge | 146:22da6e220af6 | 87 | { |
AnnaBridge | 146:22da6e220af6 | 88 | SD_MBR_COMMAND_COPY_BL, /**< Copy a new BootLoader. @see sd_mbr_command_copy_bl_t */ |
AnnaBridge | 146:22da6e220af6 | 89 | SD_MBR_COMMAND_COPY_SD, /**< Copy a new SoftDevice. @see ::sd_mbr_command_copy_sd_t*/ |
AnnaBridge | 146:22da6e220af6 | 90 | SD_MBR_COMMAND_INIT_SD, /**< Init forwarding interrupts to SD, and run reset function in SD*/ |
AnnaBridge | 146:22da6e220af6 | 91 | SD_MBR_COMMAND_COMPARE, /**< This command works like memcmp. @see ::sd_mbr_command_compare_t*/ |
AnnaBridge | 146:22da6e220af6 | 92 | SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET, /**< Start forwarding all exception to this address @see ::sd_mbr_command_vector_table_base_set_t*/ |
AnnaBridge | 146:22da6e220af6 | 93 | }; |
AnnaBridge | 146:22da6e220af6 | 94 | |
AnnaBridge | 146:22da6e220af6 | 95 | /** @} */ |
AnnaBridge | 146:22da6e220af6 | 96 | |
AnnaBridge | 146:22da6e220af6 | 97 | /** @addtogroup NRF_MBR_TYPES Types |
AnnaBridge | 146:22da6e220af6 | 98 | * @{ */ |
AnnaBridge | 146:22da6e220af6 | 99 | |
AnnaBridge | 146:22da6e220af6 | 100 | /**@brief This command copies part of a new SoftDevice |
AnnaBridge | 146:22da6e220af6 | 101 | * The destination area is erased before copying. |
AnnaBridge | 146:22da6e220af6 | 102 | * If dst is in the middle of a flash page, that whole flash page will be erased. |
AnnaBridge | 146:22da6e220af6 | 103 | * If (dst+len) is in the middle of a flash page, that whole flash page will be erased. |
AnnaBridge | 146:22da6e220af6 | 104 | * |
AnnaBridge | 146:22da6e220af6 | 105 | * The user of this function is responsible for setting the PROTENSET registers. |
AnnaBridge | 146:22da6e220af6 | 106 | * |
AnnaBridge | 146:22da6e220af6 | 107 | * @retval ::NRF_SUCCESS indicates that the contents of the memory blocks where copied correctly. |
AnnaBridge | 146:22da6e220af6 | 108 | * @retval ::NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying. |
AnnaBridge | 146:22da6e220af6 | 109 | */ |
AnnaBridge | 146:22da6e220af6 | 110 | typedef struct |
AnnaBridge | 146:22da6e220af6 | 111 | { |
AnnaBridge | 146:22da6e220af6 | 112 | uint32_t *src; /**< Pointer to the source of data to be copied.*/ |
AnnaBridge | 146:22da6e220af6 | 113 | uint32_t *dst; /**< Pointer to the destination where the content is to be copied.*/ |
AnnaBridge | 146:22da6e220af6 | 114 | uint32_t len; /**< Number of 32 bit words to copy. Must be a multiple of @ref PAGE_SIZE_IN_WORDS words.*/ |
AnnaBridge | 146:22da6e220af6 | 115 | } sd_mbr_command_copy_sd_t; |
AnnaBridge | 146:22da6e220af6 | 116 | |
AnnaBridge | 146:22da6e220af6 | 117 | |
AnnaBridge | 146:22da6e220af6 | 118 | /**@brief This command works like memcmp, but takes the length in words. |
AnnaBridge | 146:22da6e220af6 | 119 | * |
AnnaBridge | 146:22da6e220af6 | 120 | * @retval ::NRF_SUCCESS indicates that the contents of both memory blocks are equal. |
AnnaBridge | 146:22da6e220af6 | 121 | * @retval ::NRF_ERROR_NULL indicates that the contents of the memory blocks are not equal. |
AnnaBridge | 146:22da6e220af6 | 122 | */ |
AnnaBridge | 146:22da6e220af6 | 123 | typedef struct |
AnnaBridge | 146:22da6e220af6 | 124 | { |
AnnaBridge | 146:22da6e220af6 | 125 | uint32_t *ptr1; /**< Pointer to block of memory. */ |
AnnaBridge | 146:22da6e220af6 | 126 | uint32_t *ptr2; /**< Pointer to block of memory. */ |
AnnaBridge | 146:22da6e220af6 | 127 | uint32_t len; /**< Number of 32 bit words to compare.*/ |
AnnaBridge | 146:22da6e220af6 | 128 | } sd_mbr_command_compare_t; |
AnnaBridge | 146:22da6e220af6 | 129 | |
AnnaBridge | 146:22da6e220af6 | 130 | |
AnnaBridge | 146:22da6e220af6 | 131 | /**@brief This command copies a new BootLoader. |
AnnaBridge | 146:22da6e220af6 | 132 | * With this command, destination of BootLoader is always the address written in NRF_UICR->BOOTADDR. |
AnnaBridge | 146:22da6e220af6 | 133 | * |
AnnaBridge | 146:22da6e220af6 | 134 | * Destination is erased by this function. |
AnnaBridge | 146:22da6e220af6 | 135 | * If (destination+bl_len) is in the middle of a flash page, that whole flash page will be erased. |
AnnaBridge | 146:22da6e220af6 | 136 | * |
AnnaBridge | 146:22da6e220af6 | 137 | * This function will use PROTENSET to protect the flash that is not intended to be written. |
AnnaBridge | 146:22da6e220af6 | 138 | * |
AnnaBridge | 146:22da6e220af6 | 139 | * On Success, this function will not return. It will start the new BootLoader from reset-vector as normal. |
AnnaBridge | 146:22da6e220af6 | 140 | * |
AnnaBridge | 146:22da6e220af6 | 141 | * @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen. |
AnnaBridge | 146:22da6e220af6 | 142 | * @retval ::NRF_ERROR_FORBIDDEN if NRF_UICR->BOOTADDR is not set. |
AnnaBridge | 146:22da6e220af6 | 143 | * @retval ::NRF_ERROR_INVALID_LENGTH if parameters attempts to read or write outside flash area. |
AnnaBridge | 146:22da6e220af6 | 144 | */ |
AnnaBridge | 146:22da6e220af6 | 145 | typedef struct |
AnnaBridge | 146:22da6e220af6 | 146 | { |
AnnaBridge | 146:22da6e220af6 | 147 | uint32_t *bl_src; /**< Pointer to the source of the Bootloader to be be copied.*/ |
AnnaBridge | 146:22da6e220af6 | 148 | uint32_t bl_len; /**< Number of 32 bit words to copy for BootLoader. */ |
AnnaBridge | 146:22da6e220af6 | 149 | } sd_mbr_command_copy_bl_t; |
AnnaBridge | 146:22da6e220af6 | 150 | |
AnnaBridge | 146:22da6e220af6 | 151 | /**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the MBR |
AnnaBridge | 146:22da6e220af6 | 152 | * |
AnnaBridge | 146:22da6e220af6 | 153 | * Once this function has been called, this address is where the MBR will start to forward interrupts to after a reset. |
AnnaBridge | 146:22da6e220af6 | 154 | * |
AnnaBridge | 146:22da6e220af6 | 155 | * To restore default forwarding this function should be called with @param address set to 0. |
AnnaBridge | 146:22da6e220af6 | 156 | * The MBR will then start forwarding to interrupts to the address in NFR_UICR->BOOTADDR or to the SoftDevice if the BOOTADDR is not set. |
AnnaBridge | 146:22da6e220af6 | 157 | * |
AnnaBridge | 146:22da6e220af6 | 158 | * @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen. |
AnnaBridge | 146:22da6e220af6 | 159 | * @retval ::NRF_ERROR_INVALID_ADDR if parameter address is outside of the flash size. |
AnnaBridge | 146:22da6e220af6 | 160 | */ |
AnnaBridge | 146:22da6e220af6 | 161 | typedef struct |
AnnaBridge | 146:22da6e220af6 | 162 | { |
AnnaBridge | 146:22da6e220af6 | 163 | uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/ |
AnnaBridge | 146:22da6e220af6 | 164 | } sd_mbr_command_vector_table_base_set_t; |
AnnaBridge | 146:22da6e220af6 | 165 | |
AnnaBridge | 146:22da6e220af6 | 166 | typedef struct |
AnnaBridge | 146:22da6e220af6 | 167 | { |
AnnaBridge | 146:22da6e220af6 | 168 | uint32_t command; /**< type of command to be issued see @ref NRF_MBR_COMMANDS. */ |
AnnaBridge | 146:22da6e220af6 | 169 | union |
AnnaBridge | 146:22da6e220af6 | 170 | { |
AnnaBridge | 146:22da6e220af6 | 171 | sd_mbr_command_copy_sd_t copy_sd; /**< Parameters for copy SoftDevice.*/ |
AnnaBridge | 146:22da6e220af6 | 172 | sd_mbr_command_copy_bl_t copy_bl; /**< Parameters for copy BootLoader.*/ |
AnnaBridge | 146:22da6e220af6 | 173 | sd_mbr_command_compare_t compare; /**< Parameters for verify.*/ |
AnnaBridge | 146:22da6e220af6 | 174 | sd_mbr_command_vector_table_base_set_t base_set; /**< Parameters for vector table base set.*/ |
AnnaBridge | 146:22da6e220af6 | 175 | } params; |
AnnaBridge | 146:22da6e220af6 | 176 | } sd_mbr_command_t; |
AnnaBridge | 146:22da6e220af6 | 177 | |
AnnaBridge | 146:22da6e220af6 | 178 | /** @} */ |
AnnaBridge | 146:22da6e220af6 | 179 | |
AnnaBridge | 146:22da6e220af6 | 180 | /** @addtogroup NRF_MBR_FUNCTIONS Functions |
AnnaBridge | 146:22da6e220af6 | 181 | * @{ */ |
AnnaBridge | 146:22da6e220af6 | 182 | |
AnnaBridge | 146:22da6e220af6 | 183 | /**@brief Issue Master Boot Record commands |
AnnaBridge | 146:22da6e220af6 | 184 | * |
AnnaBridge | 146:22da6e220af6 | 185 | * Commands used when updating a SoftDevice and bootloader. |
AnnaBridge | 146:22da6e220af6 | 186 | * |
AnnaBridge | 146:22da6e220af6 | 187 | * @param[in] param Pointer to a struct describing the command. |
AnnaBridge | 146:22da6e220af6 | 188 | * |
AnnaBridge | 146:22da6e220af6 | 189 | *@note for retvals see ::sd_mbr_command_copy_sd_t ::sd_mbr_command_copy_bl_t ::sd_mbr_command_compare_t |
AnnaBridge | 146:22da6e220af6 | 190 | |
AnnaBridge | 146:22da6e220af6 | 191 | */ |
AnnaBridge | 146:22da6e220af6 | 192 | SVCALL(SD_MBR_COMMAND, uint32_t, sd_mbr_command(sd_mbr_command_t* param)); |
AnnaBridge | 146:22da6e220af6 | 193 | |
AnnaBridge | 146:22da6e220af6 | 194 | /** @} */ |
AnnaBridge | 146:22da6e220af6 | 195 | #ifdef __cplusplus |
AnnaBridge | 146:22da6e220af6 | 196 | } |
AnnaBridge | 146:22da6e220af6 | 197 | #endif |
AnnaBridge | 146:22da6e220af6 | 198 | #endif // NRF_MBR_H__ |
AnnaBridge | 146:22da6e220af6 | 199 | |
AnnaBridge | 146:22da6e220af6 | 200 | /** |
AnnaBridge | 146:22da6e220af6 | 201 | @} |
AnnaBridge | 146:22da6e220af6 | 202 | */ |