-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcy_app_dmc_fwupdate.h
369 lines (318 loc) · 12.1 KB
/
cy_app_dmc_fwupdate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/***************************************************************************//**
* \file cy_app_dmc_fwupdate.h
* \version 2.0
*
* \brief
* DMC firmware update module
*
********************************************************************************
* \copyright
* Copyright 2024, Cypress Semiconductor Corporation (an Infineon company)
* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
*******************************************************************************/
#ifndef _CY_APP_DMC_FW_UPDATE_H_
#define _CY_APP_DMC_FW_UPDATE_H_
#if (CY_APP_DMC_ENABLE || DOXYGEN)
/*******************************************************************************
* Header files including
******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "cy_usb_dev.h"
#include "cy_app_dmc_common.h"
#include "cy_app_status.h"
/**
* \addtogroup group_pmg_app_common_dmc
* \{
*/
/**
* \addtogroup group_pmg_app_common_dmc_macros
* \{
*/
/*******************************************************************************
* MACRO definition
******************************************************************************/
/** Component ID of DMC. DMC should always be the first component.
* @warning This value should not be changed
*/
#define CY_APP_DMC_COMPONENT_ID (0)
/** Image 1 value is available in the lower nibble. To get image 1 status,
* mask with this value.
* @warning Do not edit this value
*/
#define CY_APP_DMC_IMG1_STATUS_MASK (0x0F)
/** Image 2 value is available in the higher nibble. To get image 2 status,
* mask with this value.
* @warning Do not edit this value
*/
#define CY_APP_DMC_IMG2_STATUS_MASK (0xF0)
/** USB vendor BULK OUT endpoint */
#define CY_APP_DMC_USB_VENDOR_OUT_EP_INDEX (1)
/** USB vendor interrupt IN endpoint. */
#define CY_APP_DMC_USB_VENDOR_INT_EP_INDEX (2)
/**
* @brief Largest packet size supported by the device. This is defined by
* the firmware and should not be modified.
*/
#define CY_APP_DMC_USB_EP_MAX_PKT_SIZE (64)
/** Length of data transferred over INT EP */
#define CY_APP_DMC_INT_EP_STATUS_LEN (3)
/** @cond DOXYGEN_HIDE */
#if (CY_APP_USR_DEFINED_SN_SUPPORT)
/* DMC serial number (SN) bit mask in device_specific parameter */
#define CY_APP_DMC_METADATA_SN_BIT_MASK (0x0E)
#define CY_APP_DMC_METADATA_SN_BIT_POS (0x1u)
/* Serial number configuration in DMC flash */
#define CY_APP_DMC_DMC_SERIAL_NUMBER_ROW_ID (0x3F4)
/* SN byte in the device specific parameter */
#define CY_APP_DMC_DEV_SPECIFIC_BYTE0 (0x0u)
#define CY_APP_DMC_HX3_SN_ROW_SHIFT_NUM (0x7u)
/*! Maximum length of serial number(in bytes) that can be stored in dock metadata */
#define CY_APP_DMC_METADATA_SN_MAX_LENGTH (128)
#endif /* CY_APP_USR_DEFINED_SN_SUPPORT */
/** @endcond */
/** \} group_pmg_app_common_dmc_macros */
/*****************************************************************************
********************************* Data types ********************************
*****************************************************************************/
/**
* \addtogroup group_pmg_app_common_dmc_enums
* \{
*/
/** @cond DOXYGEN_HIDE */
#if (CY_APP_USR_DEFINED_SN_SUPPORT)
/**
* @typedef cy_en_dmc_sn_state_t
* @brief State of serial number for DMC and HX3
* @warning Do not edit this enum value
*/
typedef enum
{
SN_NOT_IMPLEMENTED = 0x00, /**< 0x00 - SN is not implemented */
SN_VALID, /**< 0x01 - SN is valid and updated */
SN_INVALID, /**< 0x02 - SN is invalid, SN update will happen based on this value */
SN_HX3_SECONDARY_IMAGE_INVALID, /**< 0x03 - HX3's secondary image is invalid */
SN_HX3_CONFIG_CHECK_FAILED, /**< 0x04 - HX3 configuration check for SN update is failed */
SN_HX3_NO_ENOUGH_SPACE /**< 0x05 - Not enough space in the string descriptor to update SN */
} cy_en_dmc_sn_state_t;
#endif /* CY_APP_USR_DEFINED_SN_SUPPORT */
/** @endcond */
/** \} group_pmg_app_common_dmc_enums */
/**
* \addtogroup group_pmg_app_common_dmc_functions
* \{
*/
/*****************************************************************************
**************************** Function prototypes ****************************
*****************************************************************************/
/**
* @brief This function is called before initiating a soft reset to DMC.
* The reason for reset is updated in dock metadata as soft reset, so that the USB
* enumeration happens.
*
* @param params Pointer to DMC parameters
*
* @return None
*/
void Cy_App_Dmc_PrepareSoftReset(cy_stc_dmc_params_t *params);
/** @cond DOXYGEN_HIDE */
/**
* @brief Returns current device row number for the device being updated currently
* @return current device row number for the device being updated currently
*/
uint16_t Cy_App_Dmc_GetCurRowId(void);
/**
* @brief Returns current device row size for the device being updated currently
*
* @return current device row size for the device being updated currently
*/
uint16_t Cy_App_Dmc_GetCurRowSize(void);
/**
* @brief Function to check if DMC is in Phase 2
* @return True if DMC is in Phase 2; otherwise false.
*/
bool Cy_App_Dmc_IsPhase2 (void);
/**
* @brief Function to check if factory update is done
* @return True if update is completed; otherwise false.
*/
bool Cy_App_Dmc_IsFactoryUpdateDone (void);
/** @endcond */
/**
* @brief Function to set factory update status
* @param status New status to be set
* @return None
*/
void Cy_App_Dmc_SetFactoryUpdateStatus (uint8_t status);
/**
* @brief Function to read factory update status
* @param params Pointer to DMC Parameters
* @return True if read is successful; otherwise false.
*/
bool Cy_App_Dmc_ReadFactoryUpdateStatus (cy_stc_dmc_params_t *params);
/**
* @brief Returns if the DMC FW update state machine has not started and DMC
* is in idle state.
*
* @returns true if DMC is in idle state; otherwise false.
*/
bool Cy_App_Dmc_IsIdle(void);
/** @cond DOXYGEN_HIDE */
/**
* @brief Returns if the particular image of the particular device, identified
* by the component ID needs to be updated or not based on the FW
* version check.
*
* @param comp_id Unique number for which the device topology requires
*
* @param img_type This is cy_en_dmc_image_type_t enum
*
* @returns true if the image needs to be updated; otherwise false.
*/
bool Cy_App_Dmc_IsImageUpdateNeeded(uint8_t comp_id, cy_en_dmc_image_type_t img_type);
/** @endcond */
/**
* @brief Returns the validity of the image identified by the image type and
* component ID of the device.
*
* @param comp_id Unique number of the device for which the device topology requires
* @param img_type Firmware image type \ref cy_en_dmc_image_type_t
* @param img_update_count_ptr pointer to contain the update attempt count for the image
*
* @returns the validity status of the image- \ref cy_en_dmc_img_status_t
*/
uint8_t Cy_App_Dmc_CheckImageValidity (uint8_t comp_id, cy_en_dmc_image_type_t img_type, uint8_t *img_update_count_ptr);
/** @cond DOXYGEN_HIDE */
/**
* @brief Returns maximum FWCT size supported currently
*
* @return maximum FWCT size supported currently
*/
uint16_t Cy_App_Dmc_GetMaximumFwctSize(void);
/** @endcond */
/**
* @brief Handler for DMC level asynchronous tasks
* This function primarily handles firmware update for the connected
* devices and DMC. This shall be called as part of the main loop.
*
* @param params Pointer to the DMC parameters
*
* @return None
*/
void Cy_App_Dmc_Task(cy_stc_dmc_params_t *params);
/**
* @brief DMC pre initialization
* Initializes the globals
*
* @param device_mode Device mode
* @param ptrCdttCfg Pointer to CDTT structure
* @param ptrSecCfg Pointer to security configuration structure
* @param ptrAppCbk Pointer to application callback
* @param params Pointer to DMC Parameters
* @return None
*/
cy_en_app_status_t Cy_App_Dmc_PreInit(cy_en_dmc_fw_mode_t device_mode, const cdtt_config_t *ptrCdttCfg, const sec_config_t *ptrSecCfg,
const cy_stc_dmc_app_cbk_t *ptrAppCbk, cy_stc_dmc_params_t *params);
/**
* @brief Sets current image type and image status for the particular device
* identified using component ID
*
* @param comp_id ID for the connected device
* @param cur_img_type Firmware image type \ref cy_en_dmc_image_type_t
* @param img_status Firmware image status \ref cy_en_dmc_img_status_t
*
* @return None
*/
void Cy_App_Dmc_SetRamImageStatus(uint8_t comp_id, cy_en_dmc_image_type_t cur_img_type, cy_en_dmc_img_status_t img_status);
/**
* @brief Updates the image type and image status for the particular device
* identified using component ID.
*
* @param comp_id ID for the connected device
* @param img_type Firmware image type \ref cy_en_dmc_image_type_t
* @param img_status Firmware image status \ref cy_en_dmc_img_status_t
*
* @return None.
*/
void Cy_App_Dmc_UpdateRamImageStatus (uint8_t comp_id, cy_en_dmc_image_type_t img_type, cy_en_dmc_img_status_t img_status);
/**
* @brief The firmware version for a given dock device is updated in the RAM Copy of
* the dock metadata
* It contains version information for bootloader, image 1, and image 2.
*
* @param comp_id This is a unique value used to identify the device
* that is connected to the DMC
* @param bl_version Bootloader version for the dock device
* @param fw1_version Firmware 1 version for the dock device
* @param fw2_version Firmware 2 version for the dock device
*
* @return None.
*/
void Cy_App_Dmc_UpdateRamVersions(uint8_t comp_id, uint8_t *bl_version, uint8_t *fw1_version, uint8_t *fw2_version);
/**
* @brief Resets DMC to known state
*
* @param params Pointer to DMC Parameters
*
* @return None
*/
void Cy_App_Dmc_ResetState (cy_stc_dmc_params_t *params);
/**
* @brief Initiates soft reset to the DMC device
*
* @return None
*/
void Cy_App_Dmc_SoftReset(void);
/**
* @brief Gets device topology information from CDTT based on comp_id.
* This function returns the pointer to the dev_topology_t when the comp_id
* is less than total device count connected to the DMC.
*
* @param comp_id Unique number for which the device topology requires
* @return dev_topology_t * When comp_id is less than device count
* @return NULL When comp_id is greater than or equals to
* device count
*/
const dev_topology_t *Cy_App_Dmc_GetDeviceTopology(uint8_t comp_id);
/**
* @brief Fetches the current DMC state
* @return Current DMC state
*/
uint8_t Cy_App_Dmc_GetCurState (void);
/**
* @brief Changes the state of the DMC to the given state
* @param state New DMC state
* @return None
*/
void Cy_App_Dmc_SetCurState (uint8_t state);
/** @cond DOXYGEN_HIDE */
/**
* @brief To know whether DMC supports signed firmware or not
* @return True when signed firmware update is supported; otherwise false.
*/
bool Cy_App_Dmc_SignedFwUpdateSupported(void);
/** @endcond */
/**
* @brief Returns whether DMC version check is enabled or not
* @return True when version check is enabled; otherwise false.
*/
bool Cy_App_Dmc_VersionCheckEnabled(void);
/**
* @brief This function returns pointer to the structure holding function pointers of various device modules
* @return Pointer to the structure holding
* function pointers of various device modules
*/
const cy_stc_app_dmc_update_opern_t** Cy_App_Dmc_GetDevUpdateOpern(void);
/**
* @brief Returns the alternate image metadata row number
* @return uint16_t Alternate image metadata row number
*/
uint16_t Cy_App_Dmc_GetAltImgMdRowNum(void);
/** \} group_pmg_app_common_dmc_functions */
/** \} group_pmg_app_common_dmc */
#endif /* (CY_APP_DMC_ENABLE || DOXYGEN) */
#endif /* _CY_APP_DMC_FW_UPDATE_H_ */
/* [] END OF FILE */