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