テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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