You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

144 lines
5.0 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2020 Loci Controls Inc
  4. * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the
  16. * distribution.
  17. *
  18. * Neither the name of Texas Instruments Incorporated nor the names of
  19. * its contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ******************************************************************************/
  35. #ifndef OPENOCD_LOADERS_FLASH_CC2538_FLASHLOADER_H
  36. #define OPENOCD_LOADERS_FLASH_CC2538_FLASHLOADER_H
  37. #include <stdint.h>
  38. #include <stdbool.h>
  39. #include <string.h>
  40. #include "flash.h"
  41. /* Number of elements in an array */
  42. #define NELEMS(a) (sizeof(a) / sizeof(a[0]))
  43. struct __attribute__((__packed__)) flash_params {
  44. uint32_t dest; /* Destination address in flash */
  45. uint32_t len; /* Number of bytes */
  46. uint32_t cmd; /* Command */
  47. uint32_t full; /* Handshake signal. Is buffer ready? */
  48. uint32_t buf_addr; /* Address of data buffer. */
  49. };
  50. typedef enum {
  51. CMD_NO_ACTION = 0, /* No action, default value */
  52. CMD_ERASE_ALL = 1, /* Erase all unprotected sectors */
  53. CMD_PROGRAM = 2, /* Program data */
  54. CMD_ERASE_SECTORS = 3 /* Erase unprotected sectors */
  55. } flash_commands_t;
  56. typedef enum {
  57. BUFFER_EMPTY = 0x0, /* No data in buffer, flags last task complete */
  58. BUFFER_FULL = 0xFFFFFFFF /* Buffer has data, flags next task to start */
  59. } flash_handshake_t;
  60. #define STATUS_FLASHLOADER_STATUS_M 0x0000FFFF
  61. #define STATUS_FLASHLOADER_STATUS_S 0
  62. #define STATUS_ROM_CODE_M 0x00FF0000
  63. #define STATUS_ROM_CODE_S 16
  64. #define STATUS_EXT_INFO_M 0xFF000000
  65. #define STATUS_EXT_INFO_S 24
  66. typedef enum {
  67. STATUS_OK = 0,
  68. STATUS_FAILED_ERASE_ALL = 0x101,
  69. STATUS_FAILED_SECTOR_ERASE = 0x102,
  70. STATUS_FAILED_PROGRAM = 0x103,
  71. STATUS_FAILED_INVALID_ARGUMENTS = 0x104,
  72. STATUS_FAILED_UNKNOWN_COMMAND = 0x105,
  73. } flash_status_t;
  74. /* The buffer size used by the flashloader. The size of 1 flash sector. */
  75. #define BUFFER_LEN FLASH_ERASE_SIZE
  76. /*
  77. * This function initializes the flashloader. The application must
  78. * allocate memory for the two data buffers and the flash_params structures.
  79. *
  80. * params Pointer an flash_params array with 2 elements.
  81. * buf1 Pointer to data buffer 1
  82. * buf2 Pointer to data buffer 2
  83. *
  84. * Returns STATUS_OK
  85. *
  86. */
  87. extern uint32_t flashloader_init(struct flash_params *params, uint8_t *buf1,
  88. uint8_t *buf2);
  89. /*
  90. * Erases all flash sectors (that are not write-protected).
  91. *
  92. * Returns STATUS_OK on success.
  93. *
  94. */
  95. extern uint32_t flashloader_erase_all(void);
  96. /*
  97. * Erases the flash sectors affected by the given range.
  98. *
  99. * This function only erases sectors that are not already erased.
  100. *
  101. * start_addr The first address in the range.
  102. * byte_count The number of bytes in the range.
  103. *
  104. * Returns STATUS_OK on success. Returns a combined status on failure:
  105. * [31:24] The sector that failed.
  106. * [23:16] ROM function status code. 0 means success.
  107. * [16: 0] STATUS_FAILED_SECTOR_ERASE
  108. *
  109. */
  110. extern uint32_t flashloader_erase_sectors(uint32_t start_address,
  111. uint32_t byte_count);
  112. /*
  113. * Program the given range.
  114. *
  115. * This function does not erase anything, it assumes the sectors are ready to
  116. * be programmed.
  117. *
  118. * src Pointer to buffer containing the data.
  119. * address Start address in device flash
  120. * byte_count The number of bytes to program
  121. *
  122. * Returns STATUS_OK on success. Returns a combined status value on failure:
  123. * [31:16] ROM function status code. 0 means success.
  124. * [15:0 ] STATUS_FAILED_PROGRAM
  125. *
  126. */
  127. extern uint32_t flashloader_program(uint8_t *src, uint32_t address,
  128. uint32_t byte_count);
  129. #endif /* #ifndef OPENOCD_LOADERS_FLASH_CC2538_FLASHLOADER_H */