1 /* SPDX-License-Identifier: BSD-3-Clause */
3 /******************************************************************************
5 * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
7 ******************************************************************************/
9 #ifndef OPENOCD_LOADERS_FLASH_CC26XX_FLASHLOADER_H
10 #define OPENOCD_LOADERS_FLASH_CC26XX_FLASHLOADER_H
17 /* Number of elements in an array */
18 #define NELEMS(a) (sizeof(a) / sizeof(a[0]))
20 struct __attribute__((__packed__)) flash_params {
21 uint32_t dest; /* Destination address in flash */
22 uint32_t len; /* Number of bytes */
23 uint32_t cmd; /* Command */
24 uint32_t full; /* Handshake signal. Is buffer ready? */
25 uint32_t buf_addr; /* Address of data buffer. */
29 CMD_NO_ACTION = 0, /* No action, default value */
30 CMD_ERASE_ALL = 1, /* Erase all unprotected sectors */
31 CMD_PROGRAM = 2, /* Program data */
32 CMD_ERASE_AND_PROGRAM = 3, /* Erase and program data */
33 CMD_ERASE_AND_PROGRAM_WITH_RETAIN = 4, /* Erase and program, but retain */
34 /* sector data outside given range */
35 CMD_ERASE_SECTORS = 5 /* Erase unprotected sectors */
39 BUFFER_EMPTY = 0x0, /* No data in buffer, flags last task complete */
40 BUFFER_FULL = 0xFFFFFFFF /* Buffer has data, flags next task to start */
43 #define STATUS_FLASHLOADER_STATUS_M 0x0000FFFF
44 #define STATUS_FLASHLOADER_STATUS_S 0
45 #define STATUS_ROM_CODE_M 0x00FF0000
46 #define STATUS_ROM_CODE_S 16
47 #define STATUS_EXT_INFO_M 0xFF000000
48 #define STATUS_EXT_INFO_S 24
52 STATUS_FAILED_ERASE_ALL = 0x101,
53 STATUS_FAILED_SECTOR_ERASE = 0x102,
54 STATUS_FAILED_PROGRAM = 0x103,
55 STATUS_FAILED_INVALID_ARGUMENTS = 0x104,
56 STATUS_FAILED_UNKNOWN_COMMAND = 0x105,
59 /* The buffer size used by the flashloader. The size of 1 flash sector. */
60 #define BUFFER_LEN FLASH_ERASE_SIZE
63 * This function initializes the flashloader. The application must
64 * allocate memory for the two data buffers and the flash_params structures.
66 * params Pointer an flash_params array with 2 elements.
67 * buf1 Pointer to data buffer 1
68 * buf2 Pointer to data buffer 2
73 extern uint32_t flashloader_init(struct flash_params *params, uint8_t *buf1,
77 * Erase and program the necessary sectors. Data outside the given
78 * range will be deleted.
80 * src Pointer to buffer containing the data.
81 * address Start address in device flash
82 * byte_count The number of bytes to program
84 * Returns STATUS_OK on success. For status on failure:
85 * See flashloader_program() and flashloader_erase_sectors().
88 extern uint32_t flashloader_erase_and_program(uint8_t *src, uint32_t address,
92 * Erase and program the device sectors. Data outside the given
93 * data range will be kept unchanged.
95 * src Pointer to buffer containing the data.
96 * address Start address in device flash
97 * byte_count The number of bytes to program
99 * Returns STATUS_OK on success. For status on failure:
100 * See flashloader_program() and flashloader_erase_sectors().
103 extern uint32_t flashloader_program_with_retain(uint8_t *src, uint32_t address,
104 uint32_t byte_count);
107 * Erases all flash sectors (that are not write-protected).
109 * Returns STATUS_OK on success.
112 extern uint32_t flashloader_erase_all(void);
115 * Erases the flash sectors affected by the given range.
117 * This function only erases sectors that are not already erased.
119 * start_addr The first address in the range.
120 * byte_count The number of bytes in the range.
122 * Returns STATUS_OK on success. Returns a combined status on failure:
123 * [31:24] The sector that failed.
124 * [23:16] ROM function status code. 0 means success.
125 * [16: 0] STATUS_FAILED_SECTOR_ERASE
128 extern uint32_t flashloader_erase_sectors(uint32_t start_addr,
129 uint32_t byte_count);
132 * Program the given range.
134 * This function does not erase anything, it assumes the sectors are ready to
137 * src Pointer to buffer containing the data.
138 * address Start address in device flash
139 * byte_count The number of bytes to program
141 * Returns STATUS_OK on success. Returns a combined status value on failure:
142 * [31:16] ROM function status code. 0 means success.
143 * [15:0 ] STATUS_FAILED_PROGRAM
146 extern uint32_t flashloader_program(uint8_t *src, uint32_t address,
147 uint32_t byte_count);
150 * Convert the input address into a sector number.
152 * address The address.
154 * Returns the flash sector which the address resides in. The first sector
158 static inline uint32_t flashloader_address_to_sector(uint32_t address)
159 { return (address / FLASH_ERASE_SIZE); };
161 #endif /* #ifndef OPENOCD_LOADERS_FLASH_CC26XX_FLASHLOADER_H */