[processor-sdk/pdk.git] / packages / ti / board / utils / uniflash / target / include / flash_programmer.h
1 /*
2 * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
34 #ifndef _FLASH_PROGRAMMER_H_
35 #define _FLASH_PROGRAMMER_H_
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
41 #include <stdint.h>
42 #include <string.h>
44 #if defined(iceAMIC110) || defined(icev2AM335x)
45 #define SPI_FLASH
46 #define MAX_BAUDRATE_SUPPORTED (0x1U)
47 #endif
49 #if defined(evmAM335x)
50 #define SPI_FLASH
51 #define MAX_BAUDRATE_SUPPORTED (0x0U)
52 #endif
54 #if defined(idkAM437x)
55 #define QSPI_FLASH
56 #define MAX_BAUDRATE_SUPPORTED (0x1U)
57 #endif
59 #if defined(idkAM571x) || defined(idkAM572x) || defined(idkAM574x) || defined(iceK2G)
60 #define QSPI_FLASH
61 #define MAX_BAUDRATE_SUPPORTED (0xBU)
62 #endif
64 #if defined(evmK2G)
65 #define QSPI_FLASH
66 #define MAX_BAUDRATE_SUPPORTED (0x0U)
67 #endif
69 #if defined(j721e_evm)
70 #define MAX_BAUDRATE_SUPPORTED (0xEU)
71 #define MAX_BAUDRATE_SUPPORTED_LINUX (0xBU)
73 #define HPF_FLASH
74 #define OSPI_FLASH
75 #define QSPI_FLASH
76 #define EMMC_FLASH
77 #endif
79 #if defined(j7200_evm)
80 #define MAX_BAUDRATE_SUPPORTED (0xEU)
81 #define MAX_BAUDRATE_SUPPORTED_LINUX (0xBU)
83 #define HPF_FLASH
84 #define OSPI_FLASH
85 #define EMMC_FLASH
86 #endif
88 #if defined(am65xx_evm) || defined(am65xx_idk)
89 #define MAX_BAUDRATE_SUPPORTED (0xEU)
90 #define MAX_BAUDRATE_SUPPORTED_LINUX (0xBU)
92 #define OSPI_FLASH
93 #define EMMC_FLASH
94 #endif
96 #if defined(am64x_evm)
97 #define MAX_BAUDRATE_SUPPORTED (0x8U) /* 1500000 */
98 #define MAX_BAUDRATE_SUPPORTED_LINUX (0x8U) /* 1500000 */
100 #define OSPI_FLASH
101 #define EMMC_FLASH
102 #endif
104 #if (defined(tpr12_evm) || defined(tpr12_qt))
105 #define QSPI_FLASH
106 #define MAX_BAUDRATE_SUPPORTED (0x4U)
107 #endif
109 #define FLASH_DEVICE_MAX (6U)
111 #define UFP_FLASH_DEV_NAND (0x0U)
112 #define UFP_FLASH_DEV_SPI (0x1U)
113 #define UFP_FLASH_DEV_QSPI (0x2U)
114 #define UFP_FLASH_DEV_OSPI (0x3U)
115 #define UFP_FLASH_DEV_EMMC (0x4U)
116 #define UFP_FLASH_DEV_HPF (0x5U)
118 #define UFP_IMAGE_FP (0x0U)
119 #define UFP_IMAGE_MLO (0x1U)
120 #define UFP_IMAGE_UBOOT (0x2U)
121 #define UFP_IMAGE_UIMAGE (0x3U)
122 #define UFP_IMAGE_SYSFW (0x4U)
123 #define UFP_IMAGE_CUST (0x5U)
125 #define UFP_SYSFW_SIZE (0x41000U)
127 #define UFP_HEADER_PKT_SIZE (14U)
129 #define UFP_BAUDRATE_LIST_COUNT (15U)
131 #define UFP_BAUDRATE_115200 (115200U)
132 #define UFP_BAUDRATE_230400 (230400U)
133 #define UFP_BAUDRATE_460800 (460800U)
134 #define UFP_BAUDRATE_500000 (500000U)
135 #define UFP_BAUDRATE_576000 (576000U)
136 #define UFP_BAUDRATE_921600 (921600U)
137 #define UFP_BAUDRATE_1000000 (1000000U)
138 #define UFP_BAUDRATE_1152000 (1152000U)
139 #define UFP_BAUDRATE_1500000 (1500000U)
140 #define UFP_BAUDRATE_2000000 (2000000U)
141 #define UFP_BAUDRATE_2500000 (2500000U)
142 #define UFP_BAUDRATE_3000000 (3000000U)
143 #define UFP_BAUDRATE_3500000 (3500000U)
144 #define UFP_BAUDRATE_4000000 (4000000U)
145 #define UFP_BAUDRATE_6000000 (6000000U)
147 #define UFP_CMD_PROGRAM (0x50U)
148 #define UFP_CMD_ERASE (0x45U)
149 #define UFP_CMD_GET_MAX_BAUDRATE (0x47U)
150 #define UFP_CMD_SET_BAUDRATE (0x53U)
153 /*
154 * @brief A function pointer to initialize flash device.
155 */
156 typedef int8_t (*initFxn) (void);
158 /*
159 * @brief A function pointer to erase the data in flash device.
160 */
161 typedef int8_t (*eraseFxn) (uint32_t offset, uint32_t length);
163 /*
164 * @brief A function pointer to flash the image to flash device.
165 */
166 typedef int8_t (*flashFxn) (uint8_t *flashAddr, uint8_t *checkAddr,
167 uint32_t offset, uint32_t size);
169 /*
170 * @brief A function pointer to de-initialize flash device.
171 */
172 typedef int8_t (*CloseFxn) (void);
174 /*
175 * @brief The definition of Flash Programmer function table that contains
176 * the required set of functions to flash/erase the image
177 * on specified flash device.
178 */
179 typedef struct UFP_fxnTable_t {
180 /* Initialize Flash Device */
181 initFxn UFP_flashInit;
183 /* Erase the Content of Flash Device */
184 eraseFxn UFP_flashErase;
186 /* Copy Received image on the Flash Device */
187 flashFxn UFP_flashProgram;
189 /* Close the Initialized Flash Device */
190 CloseFxn UFP_flashClose;
192 } UFP_fxnTable;
194 /*
195 * @brief UFP_flashConfig structure contains function pointer
196 * for all supported flash device.
197 */
198 typedef struct UFP_flashConfig_t {
200 UFP_fxnTable const *UPF_fxnTablePtr;
202 }UFP_flashConfig;
204 /**
205 * \brief Returns maximum baudrate configured by host
206 *
207 */
208 uint32_t UFP_getMaxBaudrate(void);
210 /**
211 * \brief Initializes UART module
212 *
213 */
214 void UFP_uartInit(void);
216 /**
217 * \brief Configures the UART instance with given baudrate
218 *
219 * \return
220 * 0 - in case of success
221 * -1 - in case of failure.
222 *
223 */
224 int8_t UFP_uartConfig(uint32_t baudrate);
226 /**
227 * \brief Closes UART module
228 *
229 */
230 void UFP_uartClose(void);
232 #ifdef __cplusplus
233 }
234 #endif
236 #endif /* _FLASH_PROGRAMMER_H_ */