cybtldr_api.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*******************************************************************************
  2. * Copyright 2011-2012, Cypress Semiconductor Corporation. All rights reserved.
  3. * You may use this file only in accordance with the license, terms, conditions,
  4. * disclaimers, and limitations in the end user license agreement accompanying
  5. * the software package with which this file was provided.
  6. ********************************************************************************/
  7. #ifndef __CYBTLDR_API_H__
  8. #define __CYBTLDR_API_H__
  9. #include "cybtldr_utils.h"
  10. /*
  11. * This struct defines all of the items necessary for the bootloader
  12. * host to communicate over an arbitrary communication protocol. The
  13. * caller must provide implementations of these items to use their
  14. * deisred communication protocol.
  15. */
  16. typedef struct
  17. {
  18. /* Function used to open the communications connection */
  19. int (*OpenConnection)(void);
  20. /* Function used to close the communications connection */
  21. int (*CloseConnection)(void);
  22. /* Function used to read data over the communications connection */
  23. int (*ReadData)(unsigned char*, int);
  24. /* Function used to write data over the communications connection */
  25. int (*WriteData)(unsigned char*, int);
  26. /* Value used to specify the maximum number of bytes that can be trasfered at a time */
  27. unsigned int MaxTransferSize;
  28. } CyBtldr_CommunicationsData;
  29. /*******************************************************************************
  30. * Function Name: CyBtldr_TransferData
  31. ********************************************************************************
  32. * Summary:
  33. * This function is responsible for transfering a buffer of data to the target
  34. * device and then reading a response packet back from the device.
  35. *
  36. * Parameters:
  37. * inBuf - The buffer containing data to send to the target device
  38. * inSize - The number of bytes to send to the target device
  39. * outBuf - The buffer to store the data read from the device
  40. * outSize - The number of bytes to read from the target device
  41. *
  42. * Returns:
  43. * CYRET_SUCCESS - The transfer completed successfully
  44. * CYRET_ERR_COMM - There was a communication error talking to the device
  45. *
  46. *******************************************************************************/
  47. int CyBtldr_TransferData(unsigned char* inBuf, int inSize, unsigned char* outBuf, int outSize);
  48. /*******************************************************************************
  49. * Function Name: CyBtldr_ValidateRow
  50. ********************************************************************************
  51. * Summary:
  52. * This function is responsible for verifying that the provided arrayId and
  53. * row number are valid for a bootload operation.
  54. *
  55. * Parameters:
  56. * arrayId - The array to check
  57. * rowNum - The row number within the array to check
  58. *
  59. * Returns:
  60. * CYRET_SUCCESS - The array and row are available for communication
  61. * CYRET_ERR_ARRAY - The array is not valid for communication
  62. * CYRET_ERR_ROW - The array/row number is not valid for communication
  63. *
  64. *******************************************************************************/
  65. int CyBtldr_ValidateRow(unsigned char arrayId, unsigned short rowNum);
  66. /*******************************************************************************
  67. * Function Name: CyBtldr_StartBootloadOperation
  68. ********************************************************************************
  69. * Summary:
  70. * Initiates a new bootload operation. This must be called before any other
  71. * request to send data to the bootloader. A corresponding call to
  72. * CyBtldr_EndBootloadOperation() should be made once all transactions are
  73. * complete.
  74. *
  75. * Parameters:
  76. * comm – Communication struct used for communicating with the target device
  77. * expSiId - The Silicon ID of the device we expect to communicate with
  78. * expSiRev - The Silicon Rev of the device we expect to communicate with
  79. * blVer - The Bootloader version that is running on the device
  80. *
  81. * Returns:
  82. * CYRET_SUCCESS - The start request was sent successfully
  83. * CYRET_ERR_DEVICE - The detected device does not match the desired device
  84. * CYRET_ERR_VERSION - The detected bootloader version is not compatible
  85. * CYRET_ERR_BTLDR - The bootloader experienced an error
  86. * CYRET_ERR_COMM - There was a communication error talking to the device
  87. *
  88. *******************************************************************************/
  89. EXTERN int CyBtldr_StartBootloadOperation(CyBtldr_CommunicationsData* comm, unsigned long expSiId, unsigned char expSiRev, unsigned long* blVer);
  90. /*******************************************************************************
  91. * Function Name: CyBtldr_EndBootloadOperation
  92. ********************************************************************************
  93. * Summary:
  94. * Terminates the current bootload operation. This should be called once all
  95. * bootload commands have been sent and no more communication is desired.
  96. *
  97. * Parameters:
  98. * void.
  99. *
  100. * Returns:
  101. * CYRET_SUCCESS - The end request was sent successfully
  102. * CYRET_ERR_BTLDR - The bootloader experienced an error
  103. * CYRET_ERR_COMM - There was a communication error talking to the device
  104. *
  105. *******************************************************************************/
  106. EXTERN int CyBtldr_EndBootloadOperation(void);
  107. /*******************************************************************************
  108. * Function Name: CyBtldr_GetApplicationStatus
  109. ********************************************************************************
  110. * Summary:
  111. * Gets the status for the provided application id. The status includes whether
  112. * the application is valid and whether it is currently marked as active. This
  113. * should be called immediatly after enter bootloader in order to determine if
  114. * the application is suitable for bootloading.
  115. * NOTE: This is only valid for multi application bootloaders.
  116. *
  117. * Parameters:
  118. * appID - The application ID to get status information for
  119. * isValid - Is the provided application valid to be executed
  120. * isActive - Is the provided application already marked as the active app
  121. *
  122. * Returns:
  123. * CYRET_SUCCESS - The end request was sent successfully
  124. * CYRET_ERR_BTLDR - The bootloader experienced an error
  125. * CYRET_ERR_COMM - There was a communication error talking to the device
  126. * CYRET_ERR_LENGTH- The result packet does not have enough data
  127. * CYRET_ERR_DATA - The result packet does not contain valid data
  128. *
  129. *******************************************************************************/
  130. EXTERN int CyBtldr_GetApplicationStatus(unsigned char appID, unsigned char* isValid, unsigned char* isActive);
  131. /*******************************************************************************
  132. * Function Name: CyBtldr_SetApplicationStatus
  133. ********************************************************************************
  134. * Summary:
  135. * Sets the application that the bootloader will run. This should be called
  136. * after a new application has been programmed in and verified
  137. * NOTE: This is only valid for multi application bootloaders.
  138. *
  139. * Parameters:
  140. * appID - The application ID to set as the active application
  141. *
  142. * Returns:
  143. * CYRET_SUCCESS - The end request was sent successfully
  144. * CYRET_ERR_BTLDR - The bootloader experienced an error
  145. * CYRET_ERR_COMM - There was a communication error talking to the device
  146. * CYRET_ERR_LENGTH- The result packet does not have enough data
  147. * CYRET_ERR_DATA - The result packet does not contain valid data
  148. * CYRET_ERR_APP - The application is not valid and cannot be set as active
  149. *
  150. *******************************************************************************/
  151. EXTERN int CyBtldr_SetApplicationStatus(unsigned char appID);
  152. /*******************************************************************************
  153. * Function Name: CyBtldr_ProgramRow
  154. ********************************************************************************
  155. * Summary:
  156. * Sends a single row of data to the bootloader to be programmed into flash
  157. *
  158. * Parameters:
  159. * arrayID – The flash array that is to be reprogrammed
  160. * rowNum – The row number within the array that is to be reprogrammed
  161. * buf – The buffer of data to program into the devices flash
  162. * size – The number of bytes in data that need to be sent to the bootloader
  163. *
  164. * Returns:
  165. * CYRET_SUCCESS - The row was programmed successfully
  166. * CYRET_ERR_LENGTH - The result packet does not have enough data
  167. * CYRET_ERR_DATA - The result packet does not contain valid data
  168. * CYRET_ERR_ARRAY - The array is not valid for programming
  169. * CYRET_ERR_ROW - The array/row number is not valid for programming
  170. * CYRET_ERR_BTLDR - The bootloader experienced an error
  171. * CYRET_ERR_ACTIVE - The application is currently marked as active
  172. *
  173. *******************************************************************************/
  174. EXTERN int CyBtldr_ProgramRow(unsigned char arrayID, unsigned short rowNum, unsigned char* buf, unsigned short size);
  175. /*******************************************************************************
  176. * Function Name: CyBtldr_EraseRow
  177. ********************************************************************************
  178. * Summary:
  179. * Erases a single row of flash data from the device.
  180. *
  181. * Parameters:
  182. * arrayID – The flash array that is to have a row erased
  183. * rowNum – The row number within the array that is to be erased
  184. *
  185. * Returns:
  186. * CYRET_SUCCESS - The row was erased successfully
  187. * CYRET_ERR_LENGTH - The result packet does not have enough data
  188. * CYRET_ERR_DATA - The result packet does not contain valid data
  189. * CYRET_ERR_ARRAY - The array is not valid for programming
  190. * CYRET_ERR_ROW - The array/row number is not valid for programming
  191. * CYRET_ERR_BTLDR - The bootloader experienced an error
  192. * CYRET_ERR_COMM - There was a communication error talking to the device
  193. * CYRET_ERR_ACTIVE - The application is currently marked as active
  194. *
  195. *******************************************************************************/
  196. EXTERN int CyBtldr_EraseRow(unsigned char arrayID, unsigned short rowNum);
  197. /*******************************************************************************
  198. * Function Name: CyBtldr_VerifyRow
  199. ********************************************************************************
  200. * Summary:
  201. * Verifies that the data contained within the specified flash array and row
  202. * matches the expected value.
  203. *
  204. * Parameters:
  205. * arrayID – The flash array that is to be verified
  206. * rowNum – The row number within the array that is to be verified
  207. * checksum – The expected checksum value for the row
  208. *
  209. * Returns:
  210. * CYRET_SUCCESS - The row was verified successfully
  211. * CYRET_ERR_LENGTH - The result packet does not have enough data
  212. * CYRET_ERR_DATA - The result packet does not contain valid data
  213. * CYRET_ERR_ARRAY - The array is not valid for programming
  214. * CYRET_ERR_ROW - The array/row number is not valid for programming
  215. * CYRET_ERR_CHECKSUM - The checksum does not match the expected value
  216. * CYRET_ERR_BTLDR - The bootloader experienced an error
  217. * CYRET_ERR_COMM - There was a communication error talking to the device
  218. *
  219. *******************************************************************************/
  220. EXTERN int CyBtldr_VerifyRow(unsigned char arrayID, unsigned short rowNum, unsigned char checksum);
  221. /*******************************************************************************
  222. * Function Name: CyBtldr_VerifyApplication
  223. ********************************************************************************
  224. * Summary:
  225. * Verifies that the checksum for the entire bootloadable application matches
  226. * the expected value. This is used to verify that the entire bootloadable
  227. * image is valid and ready to execute.
  228. *
  229. * Parameters:
  230. * void
  231. *
  232. * Returns:
  233. * CYRET_SUCCESS - The application was verified successfully
  234. * CYRET_ERR_LENGTH - The result packet does not have enough data
  235. * CYRET_ERR_DATA - The result packet does not contain valid data
  236. * CYRET_ERR_CHECKSUM - The checksum does not match the expected value
  237. * CYRET_ERR_BTLDR - The bootloader experienced an error
  238. * CYRET_ERR_COMM - There was a communication error talking to the device
  239. *
  240. *******************************************************************************/
  241. EXTERN int CyBtldr_VerifyApplication();
  242. #endif