nrf_dfu_validation.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. /**@file
  41. *
  42. * @defgroup sdk_nrf_dfu_validation Validation
  43. * @{
  44. * @ingroup nrf_dfu
  45. */
  46. #ifndef __NRF_DFU_VALIDATION_H
  47. #define __NRF_DFU_VALIDATION_H
  48. #include "stdint.h"
  49. #include "sdk_errors.h"
  50. #include "nrf_dfu_handling_error.h"
  51. /**
  52. * @brief Function for module initialization.
  53. *
  54. * Function checks if there is a valid init packet in DFU settings written in flash.
  55. */
  56. void nrf_dfu_validation_init(void);
  57. /**
  58. * @brief Function called on reception of init command creation request.
  59. *
  60. * @param[in] size Size of incoming init packet.
  61. *
  62. * @return Operation result. See @ref nrf_dfu_result_t
  63. */
  64. nrf_dfu_result_t nrf_dfu_validation_init_cmd_create(uint32_t size);
  65. /**
  66. * @brief Function called on reception of fragment of init command.
  67. *
  68. * @param[in] p_data Init command fragment.
  69. * @param[in] length Init command fragment size.
  70. *
  71. * @return Operation result. See @ref nrf_dfu_result_t
  72. */
  73. nrf_dfu_result_t nrf_dfu_validation_init_cmd_append(uint8_t const * p_data, uint32_t length);
  74. /**
  75. * @brief Function for getting init command status.
  76. *
  77. * @param[out] p_offset Current offset.
  78. * @param[out] p_crc Current CRC.
  79. * @param[out] p_max_size Maximum size of init command.
  80. */
  81. void nrf_dfu_validation_init_cmd_status_get(uint32_t * p_offset,
  82. uint32_t * p_crc,
  83. uint32_t * p_max_size);
  84. /**
  85. * @brief Function for inquiring whether a valid init command has been received.
  86. *
  87. * @return true if there is a valid init command. This can be true at boot time
  88. * if the device was reset during a DFU operation.
  89. */
  90. bool nrf_dfu_validation_init_cmd_present(void);
  91. /**
  92. * @brief Function for validating init command.
  93. *
  94. * If init command is successfully validated Bank 1 details are written to out parameters.
  95. *
  96. * Until @ref nrf_dfu_validation_init_cmd_create is called, this function can be called
  97. * again after the first time without side effects to retrieve address and length.
  98. *
  99. * @param[out] p_dst_data_addr Bank 1 start address if validation is successful.
  100. * @param[out] p_data_len Bank 1 length if validation is successful.
  101. *
  102. * @return Operation result. See @ref nrf_dfu_result_t
  103. */
  104. nrf_dfu_result_t nrf_dfu_validation_init_cmd_execute(uint32_t * p_dst_data_addr,
  105. uint32_t * p_data_len);
  106. /**
  107. * @brief Function for postvalidating the update. Function is called once all data is received.
  108. *
  109. * @param[in] dst_data_addr Bank 1 start address.
  110. * @param[in] data_len Bank 1 length.
  111. *
  112. * @return Operation result. See @ref nrf_dfu_result_t
  113. */
  114. nrf_dfu_result_t nrf_dfu_validation_post_data_execute(uint32_t dst_data_addr, uint32_t data_len);
  115. #endif //__NRF_DFU_VALIDATION_H
  116. /** @} */