2 * Copyright (C) 2010 NXP Semiconductors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * =========================================================================== *
22 * \brief Download Mgmt Interface Source for the Firmware Download. *
25 * Project: NFC-FRI-1.1 *
27 * $Date: Tue Jun 28 14:25:44 2011 $ *
28 * $Author: ing04880 $ *
32 * =========================================================================== *
37 ################################################################################
38 ***************************** Header File Inclusion ****************************
39 ################################################################################
43 #include <phNfcConfig.h>
44 #include <phNfcCompId.h>
45 #include <phNfcIoctlCode.h>
46 #include <phDnldNfc.h>
47 #include <phOsalNfc.h>
48 #include <phOsalNfc_Timer.h>
49 #include <phDal4Nfc.h>
50 #include <utils/Log.h>
52 ################################################################################
53 ****************************** Macro Definitions *******************************
54 ################################################################################
61 #if defined (DNLD_SUMMARY) && !defined (DNLD_TRACE)
65 /* #if defined(PHDBG_INFO) && defined (PHDBG_CRITICAL_ERROR) */
66 #if defined(DNLD_TRACE)
67 extern char phOsalNfc_DbgTraceBuffer[];
69 #define MAX_TRACE_BUFFER 0x0410
70 #define Trace_buffer phOsalNfc_DbgTraceBuffer
71 /* #define DNLD_PRINT( str ) phOsalNfc_DbgTrace(str) */
72 #define DNLD_PRINT( str ) phOsalNfc_DbgString(str)
73 #define DNLD_DEBUG(str, arg) \
75 snprintf(Trace_buffer,MAX_TRACE_BUFFER,str,arg); \
76 phOsalNfc_DbgString(Trace_buffer); \
78 #define DNLD_PRINT_BUFFER(msg,buf,len) \
80 snprintf(Trace_buffer,MAX_TRACE_BUFFER,"\n\t %s:",msg); \
81 phOsalNfc_DbgString(Trace_buffer); \
82 phOsalNfc_DbgTrace(buf,len); \
83 phOsalNfc_DbgString("\r"); \
86 #define DNLD_PRINT( str )
87 #define DNLD_DEBUG(str, arg)
88 #define DNLD_PRINT_BUFFER(msg,buf,len)
91 #define DO_DELAY(period) usleep(period)
93 /* delay after SW reset cmd in ms, required on uart for XTAL stability */
94 #define PHDNLD_DNLD_DELAY 5000
95 //#define PHDNLD_MAX_PACKET 0x0200U /* Max Total Packet Size is 512 */
96 #define PHDNLD_MAX_PACKET 32U /* Max Total Packet Size is 512 */
97 #define PHDNLD_DATA_SIZE ((PHDNLD_MAX_PACKET)- 8U) /* 0x01F8U */
98 /* Max Data Size is 504 */
99 #define PHDNLD_MIN_PACKET 0x03U /* Minimum Packet Size is 3*/
101 #define DNLD_DEFAULT_RESPONSE_TIMEOUT 0x4000U
103 #define NXP_FW_MIN_TX_RX_LEN 0x0AU
106 #if defined( NXP_FW_MAX_TX_RX_LEN ) && \
107 ( NXP_FW_MAX_TX_RX_LEN > NXP_FW_MIN_TX_RX_LEN )
109 #define PHDNLD_FW_TX_RX_LEN NXP_FW_MAX_TX_RX_LEN
111 #elif !defined( NXP_FW_MAX_TX_RX_LEN )
113 /* To specify the Maximum TX/RX Len */
114 #define NXP_FW_MAX_TX_RX_LEN 0x200
115 #define PHDNLD_FW_TX_RX_LEN NXP_FW_MAX_TX_RX_LEN
119 #define PHDNLD_FW_TX_RX_LEN NXP_FW_MIN_TX_RX_LEN
123 #define PHDNLD_FRAME_LEN_SIZE 0x02U
124 #define PHDNLD_ADDR_SIZE 0x03U
125 #define PHDNLD_DATA_LEN_SIZE 0x02U
126 #define PHDNLD_FRAME_DATA_OFFSET 0x03U
128 #define DNLD_SM_UNLOCK_MASK 0x01U
129 #define DNLD_TRIM_MASK 0x02U
130 #define DNLD_RESET_MASK 0x04U
131 #define DNLD_VERIFY_MASK 0x08U
132 #define DNLD_CRITICAL_MASK 0x10U
135 #define NXP_NFC_IMAG_FW_MAX 0x05U
137 #define PHDNLD_FW_PATCH_SEC 0x5FU
139 #define PHDNLD_PAGE_SIZE 0x80U /* Page Size Configured for 64 Bytes */
141 #define FW_MAX_SECTION 0x15U /* Max Number of Sections */
143 #define DNLD_CRC16_SIZE 0x02U
145 #define DNLD_CRC32_SIZE 0x04U
147 #define DNLD_CFG_PG_ADDR 0x00008000U
148 #define DNLD_FW_CODE_ADDR 0x00800000U
149 #define DNLD_PATCH_CODE_ADDR 0x00018800U
150 #define DNLD_PATCH_TABLE_ADDR 0x00008200U
153 /* Raw Command to pass the Data in Download Mode */
154 #define PHDNLD_CMD_RAW 0x00U
155 /* Command to Reset the Device in Download Mode */
156 #define PHDNLD_CMD_RESET 0x01U
157 /* Command to Read from the Address specified in Download Mode */
158 #define PHDNLD_CMD_READ 0x07U
159 #define PHDNLD_CMD_READ_LEN 0x0005U
160 /* Command to write to the Address specified in Download Mode */
161 #define PHDNLD_CMD_WRITE 0x08U
162 #define PHDNLD_CMD_SEC_WRITE 0x0CU
163 #define PHDNLD_CMD_WRITE_MIN_LEN 0x0005U
164 #define PHDNLD_CMD_WRITE_MAX_LEN PHDNLD_DATA_SIZE
165 /* Command to verify the data written */
166 #define PHDNLD_CMD_CHECK 0x06U
167 #define PHDNLD_CMD_CHECK_LEN 0x0007U
169 /* Command to Lock the */
170 #define PHDNLD_CMD_LOCK 0x40U
171 #define PHDNLD_CMD_LOCK_LEN 0x0002U
174 /* Command to set the Host Interface properties */
175 #define PHDNLD_CMD_SET_HIF 0x09U
177 /* Command to Activate the Patches Updated */
178 #define PHDNLD_CMD_ACTIVATE_PATCH 0x0AU
180 /* Command to verify the Integrity of the data written */
181 #define PHDNLD_CMD_CHECK_INTEGRITY 0x0BU
183 /* Command to verify the Integrity of the data written */
184 #define PHDNLD_CMD_ENCAPSULATE 0x0DU
186 #define CHECK_INTEGRITY_RESP_CRC16_LEN 0x03U
187 #define CHECK_INTEGRITY_RESP_CRC32_LEN 0x05U
188 #define CHECK_INTEGRITY_RESP_COMP_LEN 0x10U
191 /* Success Response to a Command Sent in the Download Mode */
192 #define PHDNLD_RESP_SUCCESS 0x00U
193 /* Timeout Response to a Command Sent in the Download Mode */
194 #define PHDNLD_RESP_TIMEOUT 0x01U
195 /* CRC Error Response to a Command Sent in the Download Mode */
196 #define PHDNLD_RESP_CRC_ERROR 0x02U
197 /* Access Denied Response to a Command Sent in the Download Mode */
198 #define PHDNLD_RESP_ACCESS_DENIED 0x08U
199 /* PROTOCOL Error Response to a Command Sent in the Download Mode */
200 #define PHDNLD_RESP_PROTOCOL_ERROR 0x0BU
201 /* Invalid parameter Response to a Command Sent in the Download Mode */
202 #define PHDNLD_RESP_INVALID_PARAMETER 0x11U
203 /* Command Not Supported Response to a Command Sent in the Download Mode */
204 #define PHDNLD_RESP_CMD_NOT_SUPPORTED 0x13U
205 /* Length parameter error Response to a Command Sent in the Download Mode */
206 #define PHDNLD_RESP_INVALID_LENGTH 0x18U
207 /* Checksum Error Response to a Command Sent in the Download Mode */
208 #define PHDNLD_RESP_CHKSUM_ERROR 0x19U
209 /* Version already uptodate Response to a Command Sent in the Download Mode */
210 #define PHDNLD_RESP_VERSION_UPTODATE 0x1DU
211 /* Memory operation error during the processing of
212 the Command Frame in the Download Mode */
213 #define PHDNLD_RESP_MEMORY_UPDATE_ERROR 0x20U
214 /* The Chaining of the Command Frame was Successful in the Download Mode */
215 #define PHDNLD_RESP_CHAINING_SUCCESS 0x21U
216 /* The Command is not allowed anymore in the Download Mode */
217 #define PHDNLD_RESP_CMD_NOT_ALLOWED 0xE0U
218 /* The Error during the Chaining the Command Frame in the Download Mode */
219 #define PHDNLD_RESP_CHAINING_ERROR 0xE6U
220 /* Write Error Response to a Command Sent in the Download Mode */
221 #define PHDNLD_RESP_WRITE_ERROR 0x74U
223 #define PNDNLD_WORD_LEN 0x04U
225 #define NXP_MAX_DNLD_RETRY 0x02U
227 #define NXP_MAX_SECTION_WRITE 0x05U
229 #define NXP_PATCH_VER_INDEX 0x05U
233 ################################################################################
234 ******************** Enumeration and Structure Definition **********************
235 ################################################################################
238 typedef enum phDnldNfc_eSeqType{
239 DNLD_SEQ_RESET = 0x00U,
247 } phDnldNfc_eSeqType_t;
249 typedef enum phDnldNfc_eState
251 phDnld_Reset_State = 0x00,
253 phDnld_Upgrade_State,
255 phDnld_Complete_State,
260 typedef enum phDnldNfc_eSeq
262 phDnld_Reset_Seq = 0x00,
263 phDnld_Activate_Patch,
264 phDnld_Deactivate_Patch,
266 phDnld_Update_Patchtable,
268 phDnld_Unlock_System,
269 phDnld_Upgrade_Section,
270 phDnld_Verify_Integrity,
271 phDnld_Verify_Section,
277 typedef enum phDnldNfc_eChkCrc{
278 CHK_INTEGRITY_CONFIG_PAGE_CRC = 0x00U,
279 CHK_INTEGRITY_PATCH_TABLE_CRC = 0x01U,
280 CHK_INTEGRITY_FLASH_CODE_CRC = 0x02U,
281 CHK_INTEGRITY_PATCH_CODE_CRC = 0x03U,
282 CHK_INTEGRITY_COMPLETE_CRC = 0xFFU
283 } phDnldNfc_eChkCrc_t;
287 typedef struct hw_comp_tbl
289 uint8_t hw_version[3];
290 uint8_t compatibility;
294 typedef struct img_data_hdr
296 /* Image Identification */
298 /* Offset of the Data from the header */
299 uint8_t img_data_offset;
300 /* Number of fimware images available in the img_data */
301 uint8_t no_of_fw_img;
302 /* Fimware image Padding in the img_data */
303 uint8_t fw_img_pad[2];
304 /* HW Compatiblity table for the set of the Hardwares */
305 hw_comp_tbl_t comp_tbl;
306 /* This data consists of the firmware images required to download */
310 typedef struct fw_data_hdr
312 /* The data offset from the firmware header.
313 * Just in case if in future we require to
314 * add some more information.
317 /* Total size of all the sections which needs to be updated */
318 uint8_t no_of_sections;
326 /* This data consists all the sections that needs to be downloaded */
327 typedef struct section_hdr
329 uint8_t section_hdr_len;
330 uint8_t section_mem_type;
331 uint8_t section_checksum;
332 uint8_t section_conf;
333 uint32_t section_address;
334 uint32_t section_length;
337 typedef struct section_info
339 section_hdr_t *p_sec_hdr;
340 uint8_t *p_trim_data;
341 /* The section data consist of the Firmware binary required
342 * to be loaded to the particular address.
345 /* The Section checksum to verify the integrity of the section
348 uint8_t *p_sec_chksum;
349 /** \internal Index used to refer and process the
350 * Firmware Section Data */
351 volatile uint32_t section_offset;
353 /** \internal Section Read Sequence */
354 volatile uint8_t section_read;
356 /** \internal Section Write Sequence */
357 volatile uint8_t section_write;
359 /** \internal TRIM Write Sequence */
360 volatile uint8_t trim_write;
362 volatile uint8_t sec_verify_retry;
367 typedef struct phDnldNfc_sParam
369 uint8_t data_addr[PHDNLD_ADDR_SIZE];
370 uint8_t data_len[PHDNLD_DATA_LEN_SIZE];
371 uint8_t data_packet[PHDNLD_DATA_SIZE];
374 typedef struct phDnldNfc_sDataHdr
377 uint8_t frame_length[PHDNLD_FRAME_LEN_SIZE];
378 }phDnldNfc_sData_Hdr_t;
380 typedef struct phDnldNfc_sRawHdr
383 uint8_t frame_length[PHDNLD_FRAME_LEN_SIZE];
384 }phDnldNfc_sRawHdr_t;
386 typedef struct phDnldNfc_sRawDataHdr
388 uint8_t data_addr[PHDNLD_ADDR_SIZE];
389 uint8_t data_len[PHDNLD_DATA_LEN_SIZE];
390 }phDnldNfc_sRawDataHdr_t;
392 typedef struct phDnldNfc_sChkCrc16_Resp
395 uint8_t Chk_Crc16[2];
397 }phDnldNfc_sChkCrc16_Resp_t;
399 typedef struct phDnldNfc_sChkCrc32_Resp
402 uint8_t Chk_Crc32[4];
404 }phDnldNfc_sChkCrc32_Resp_t;
407 typedef struct phDnldNfc_sChkCrcComplete
409 phDnldNfc_sChkCrc16_Resp_t config_page;
410 phDnldNfc_sChkCrc16_Resp_t patch_table;
411 phDnldNfc_sChkCrc32_Resp_t flash_code;
412 phDnldNfc_sChkCrc32_Resp_t patch_code;
413 }phDnldNfc_sChkCrcComplete_t;
415 typedef struct phDnldNfc_sData
418 uint8_t frame_length[PHDNLD_FRAME_LEN_SIZE];
421 phDnldNfc_sParam_t data_param;
422 uint8_t response_data[PHDNLD_MAX_PACKET];
427 #ifdef NXP_NFC_MULTIPLE_FW
429 typedef struct phDnldNfc_sFwImageInfo
431 /** \internal Data Pointer to the Firmware header section of the Firmware */
432 fw_data_hdr_t *p_fw_hdr;
433 /** \internal Buffer pointer to store the Firmware Section Data */
434 section_info_t *p_fw_sec;
435 /** \internal Buffer pointer to store the Firmware Raw Data */
437 }phDnldNfc_sFwImageInfo_t;
439 #endif /* #ifdef NXP_NFC_MULTIPLE_FW */
442 typedef struct phDnldNfc_TxInfo
444 uint8_t *transmit_frame;
448 /** \internal Remaining amount of data to be sent */
453 /** \internal Chain information for the data to be sent */
459 typedef struct phDnldNfc_RxInfo
461 /** \internal Total length of the received buffer */
463 /** \internal Chain information of the received buffer */
465 /** \internal Remaining Data information to be read to complete the
470 /** \internal Buffer to Send the Raw Data Frame */
471 uint8_t raw_buffer_data[PHDNLD_MAX_PACKET
476 typedef struct phDnldNfc_sContext
478 /** \internal Structure to store the lower interface operations */
479 phNfc_sLowerIF_t lower_interface;
481 phNfc_sData_t *p_fw_version;
483 /** \internal Pointer to the Hardware Reference Sturcture */
484 phHal_sHwReference_t *p_hw_ref;
486 /** \internal Pointer to the upper layer notification callback function */
487 pphNfcIF_Notification_CB_t p_upper_notify;
488 /** \internal Pointer to the upper layer context */
489 void *p_upper_context;
491 /** \internal Timer ID for the Download Abort */
493 /** \internal Internal Download for the Download Abort */
494 uint32_t dnld_timeout;
495 /** \internal Data Pointer to the Image header section of the Firmware */
496 img_data_hdr_t *p_img_hdr;
498 #ifdef NXP_NFC_MULTIPLE_FW
499 /** \internal Data Pointer to the Firmware Image Information */
500 phDnldNfc_sFwImageInfo_t *p_img_info;
501 #endif /* #ifdef NXP_NFC_MULTIPLE_FW */
503 /** \internal Data Pointer to the Firmware header section of the Firmware */
504 fw_data_hdr_t *p_fw_hdr;
505 /** \internal Buffer pointer to store the Firmware Data */
506 section_info_t *p_fw_sec;
507 /** \internal Buffer pointer to store the Firmware Raw Data */
510 /** \internal Previous Download Size */
511 uint32_t prev_dnld_size;
513 /** \internal Single Data Block to download the Firmware */
514 uint8_t dnld_data[PHDNLD_MAX_PACKET
516 /** \internal Index used to refer and process the Download Data */
517 volatile uint32_t dnld_index;
519 /** \internal Response Data to process the response */
520 phDnldNfc_sData_t dnld_resp;
522 /** \internal Previously downloaded data stored
523 * to compare the written data */
524 phNfc_sData_t dnld_store;
526 /** \internal Previously downloaded trimmed data stored
527 * to compare the written data */
528 phNfc_sData_t trim_store;
530 uint8_t *p_resp_buffer;
532 phDnldNfc_sChkCrcComplete_t chk_integrity_crc;
534 phDnldNfc_eChkCrc_t chk_integrity_param;
536 #define NXP_FW_SW_VMID_TRIM
537 #ifdef NXP_FW_SW_VMID_TRIM
539 #define NXP_FW_VMID_TRIM_CHK_ADDR 0x0000813DU
540 #define NXP_FW_VMID_CARD_MODE_ADDR 0x00009931U
541 #define NXP_FW_VMID_RD_MODE_ADDR 0x00009981U
543 uint8_t vmid_trim_update;
544 #endif /* #ifdef NXP_FW_SW_VMID_TRIM */
546 uint8_t cur_frame_info;
548 uint8_t raw_mode_upgrade;
550 uint8_t *p_patch_table_crc;
552 uint8_t *p_flash_code_crc;
554 uint8_t *p_patch_code_crc;
556 uint16_t resp_length;
558 /** \internal Current FW Section in Process */
559 volatile uint8_t section_index;
561 /** \internal Previous Command sent */
562 volatile uint8_t prev_cmd;
566 /** \internal Current Download State */
567 volatile uint8_t cur_dnld_state;
568 /** \internal Next Download State */
569 volatile uint8_t next_dnld_state;
571 /** \internal Current step in Download Sequence */
572 volatile uint8_t cur_dnld_seq;
573 /** \internal Next step in Download Sequence */
574 volatile uint8_t next_dnld_seq;
576 /* \internal Data Transmit information */
577 phDnldNfc_TxInfo_t tx_info;
579 /* \internal Data Receive information */
580 phDnldNfc_RxInfo_t rx_info;
583 }phDnldNfc_sContext_t;
587 ################################################################################
588 ******************** Global and Static Variables Definition ********************
589 ################################################################################
592 #ifndef NFC_TIMER_CONTEXT
593 static phDnldNfc_sContext_t *gpphDnldContext = NULL;
596 #ifdef NXP_FW_DNLD_CHECK_PHASE
598 #define NXP_FW_DNLD_COMPLETE_PHASE 0x00U
599 #define NXP_FW_DNLD_SYSTEM_PHASE 0x01U
600 #define NXP_FW_DNLD_CFG_PHASE 0x02U
601 #define NXP_FW_DNLD_DATA_PHASE 0x03U
602 #define NXP_FW_DNLD_RAW_PHASE 0x04U
603 #define NXP_FW_DNLD_INVALID_PHASE 0xFFU
605 static uint8_t gphDnldPhase = NXP_FW_DNLD_COMPLETE_PHASE;
607 #endif /* #ifdef NXP_FW_DNLD_CHECK_PHASE */
612 *************************** Static Function Declaration **************************
617 phDnldNfc_Send_Command(
618 phDnldNfc_sContext_t *psDnldContext,
622 uint16_t param_length
627 phDnldNfc_Process_FW(
628 phDnldNfc_sContext_t *psDnldContext,
629 phHal_sHwReference_t *pHwRef
639 phDnldNfc_Send_Complete (
642 phNfc_sTransactionInfo_t *pInfo
647 phDnldNfc_Receive_Complete (
650 phNfc_sTransactionInfo_t *pInfo
655 phDnldNfc_Process_Response(
656 phDnldNfc_sContext_t *psDnldContext,
666 phDnldNfc_sContext_t *psDnldContext,
674 phDnldNfc_Resume_Write(
675 phDnldNfc_sContext_t *psDnldContext,
681 phDnldNfc_Process_Write(
682 phDnldNfc_sContext_t *psDnldContext,
684 section_info_t *p_sec_info,
685 uint32_t *p_sec_offset
691 phDnldNfc_sContext_t *psDnldContext,
699 phDnldNfc_Upgrade_Sequence(
700 phDnldNfc_sContext_t *psDnldContext,
728 phDnldNfc_sContext_t *psDnldContext,
729 phDnldNfc_eSeqType_t seq_type
735 pphNfcIF_Notification_CB_t p_upper_notify,
736 void *p_upper_context,
744 phDnldNfc_Allocate_Resource (
751 phDnldNfc_Release_Resources (
752 phDnldNfc_sContext_t **ppsDnldContext
757 phDnldNfc_Release_Lower(
758 phDnldNfc_sContext_t *psDnldContext,
766 phDnldNfc_sContext_t *psDnldContext,
768 section_info_t *p_sec_info
775 #ifdef NFC_TIMER_CONTEXT
785 phDnldNfc_UpdateCrc16(
792 phDnldNfc_ComputeCrc16(
799 *************************** Function Definitions **************************
801 #define CRC32_POLYNOMIAL 0xEDB88320L
803 static uint32_t CRC32Table[0x100];
808 uint8_t i = 0, j = 0;
810 for ( i = 0; i <= 0xFF ; i++ )
813 for ( j = 8 ; j> 0; j-- )
817 crc = ( crc>> 1 ) ^ CRC32_POLYNOMIAL;
824 CRC32Table[ i ] = crc;
829 * This routine calculates the CRC for a block of data using the
830 * table lookup method. It accepts an original value for the crc,
831 * and returns the updated value.
834 uint32_t CalculateCRC32( void *buffer , uint32_t count, uint32_t crc )
840 p = (uint8_t *) buffer;
841 while ( count-- != 0 ) {
842 temp1 = ( crc>> 8 ) & 0x00FFFFFFL;
843 temp2 = CRC32Table[ ( (int) crc ^ *p++ ) & 0xff ];
852 phDnldNfc_UpdateCrc16(
857 crcByte = (crcByte ^ (uint8_t)((*pCrc) & 0x00FF));
858 crcByte = (crcByte ^ (uint8_t)(crcByte << 4));
859 *pCrc = (*pCrc >> 8) ^ ((uint16_t)crcByte << 8) ^
860 ((uint16_t)crcByte << 3) ^
861 ((uint16_t)crcByte >> 4);
867 phDnldNfc_ComputeCrc16(
872 uint8_t crc_byte = 0;
877 crc = 0x6363; /* ITU-V.41 */
879 crc = 0xFFFF; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
880 #endif /* #ifdef CRC_A */
884 crc_byte = pData[index];
885 phDnldNfc_UpdateCrc16(crc_byte, &crc);
887 } while (index < length);
890 crc = ~crc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
891 #endif /* #ifndef INVERT_CRC */
893 /* *pCrc1 = (uint8_t) (crc & BYTE_MASK);
894 *pCrc2 = (uint8_t) ((crc >> 8) & BYTE_MASK); */
898 #endif /* #ifdef DNLD_CRC_CALC */
902 * \brief Allocation of the Download Interface resources.
904 * This function releases and frees all the resources used by Download Mode
910 phDnldNfc_Allocate_Resource (
915 NFCSTATUS status = NFCSTATUS_SUCCESS;
917 *ppBuffer = (void *) phOsalNfc_GetMemory(size);
918 if( *ppBuffer != NULL )
920 (void )memset(((void *)*ppBuffer), 0,
926 status = PHNFCSTVAL(CID_NFC_DNLD,
927 NFCSTATUS_INSUFFICIENT_RESOURCES);
934 * \brief Release of the Download Interface resources.
936 * This function releases and frees all the resources used by Download layer.
941 phDnldNfc_Release_Resources (
942 phDnldNfc_sContext_t **ppsDnldContext
946 if(NULL != (*ppsDnldContext)->p_resp_buffer)
948 phOsalNfc_FreeMemory((*ppsDnldContext)->p_resp_buffer);
949 (*ppsDnldContext)->p_resp_buffer = NULL;
951 if(NULL != (*ppsDnldContext)->dnld_store.buffer)
953 phOsalNfc_FreeMemory((*ppsDnldContext)->dnld_store.buffer);
954 (*ppsDnldContext)->dnld_store.buffer = NULL;
955 (*ppsDnldContext)->dnld_store.length = 0;
957 if(NULL != (*ppsDnldContext)->trim_store.buffer)
959 phOsalNfc_FreeMemory((*ppsDnldContext)->trim_store.buffer);
960 (*ppsDnldContext)->trim_store.buffer = NULL;
961 (*ppsDnldContext)->trim_store.length = 0;
963 if(NULL != (*ppsDnldContext)->p_fw_sec)
965 phOsalNfc_FreeMemory((*ppsDnldContext)->p_fw_sec);
966 (*ppsDnldContext)->p_fw_sec = NULL;
968 if ( NXP_INVALID_TIMER_ID != (*ppsDnldContext)->timer_id )
970 phOsalNfc_Timer_Stop((*ppsDnldContext)->timer_id );
971 phOsalNfc_Timer_Delete((*ppsDnldContext)->timer_id );
972 (*ppsDnldContext)->timer_id = NXP_INVALID_TIMER_ID;
975 phOsalNfc_FreeMemory((*ppsDnldContext));
976 (*ppsDnldContext) = NULL;
984 phDnldNfc_Release_Lower(
985 phDnldNfc_sContext_t *psDnldContext,
989 phNfc_sLowerIF_t *plower_if =
990 &(psDnldContext->lower_interface);
991 NFCSTATUS status = NFCSTATUS_SUCCESS;
993 PHNFC_UNUSED_VARIABLE(status);
995 if(NULL != plower_if->release)
997 #ifdef DNLD_LOWER_RELEASE
998 status = plower_if->release((void *)plower_if->pcontext,
1001 PHNFC_UNUSED_VARIABLE(pHwRef);
1004 (void)memset((void *)plower_if,
1005 0, sizeof(phNfc_sLowerIF_t));
1006 DNLD_DEBUG(" FW_DNLD: Releasing the Lower Layer Resources: Status = %02X\n"
1018 pphNfcIF_Notification_CB_t p_upper_notify,
1019 void *p_upper_context,
1025 if( ( NULL != p_upper_notify) )
1027 /* Notify the to the Upper Layer */
1028 (p_upper_notify)(p_upper_context, pHwRef, type, pInfo);
1036 phDnldNfc_sContext_t *psDnldContext,
1037 phDnldNfc_eSeqType_t seq_type
1040 NFCSTATUS status = NFCSTATUS_SUCCESS;
1041 static uint8_t prev_temp_state = 0;
1042 static uint8_t prev_temp_seq =
1043 (uint8_t) phDnld_Activate_Patch;
1047 case DNLD_SEQ_RESET:
1050 psDnldContext->cur_dnld_state =
1051 (uint8_t) phDnld_Reset_State;
1052 psDnldContext->next_dnld_state =
1053 (uint8_t)phDnld_Upgrade_State;
1054 psDnldContext->cur_dnld_seq =
1055 (uint8_t)phDnld_Upgrade_Section;
1056 psDnldContext->next_dnld_seq =
1057 psDnldContext->cur_dnld_seq;
1062 psDnldContext->cur_dnld_state =
1063 (uint8_t) phDnld_Reset_State;
1064 psDnldContext->next_dnld_state =
1065 (uint8_t)phDnld_Upgrade_State;
1066 psDnldContext->cur_dnld_seq =
1067 (uint8_t)phDnld_Raw_Upgrade;
1068 psDnldContext->next_dnld_seq =
1069 psDnldContext->cur_dnld_seq;
1072 case DNLD_SEQ_UNLOCK:
1074 psDnldContext->cur_dnld_state =
1075 (uint8_t) phDnld_Reset_State;
1077 #ifdef NXP_FW_DNLD_CHECK_PHASE
1078 if( NXP_FW_DNLD_SYSTEM_PHASE < gphDnldPhase )
1080 psDnldContext->next_dnld_state =
1081 (uint8_t)phDnld_Upgrade_State;
1082 psDnldContext->cur_dnld_seq =
1083 (uint8_t)phDnld_Upgrade_Section;
1086 #endif /* NXP_FW_DNLD_CHECK_PHASE */
1088 psDnldContext->next_dnld_state =
1089 (uint8_t) phDnld_Unlock_State;
1090 psDnldContext->cur_dnld_seq =
1091 (uint8_t) phDnld_Activate_Patch;
1093 psDnldContext->next_dnld_seq =
1094 psDnldContext->cur_dnld_seq;
1099 psDnldContext->cur_dnld_state =
1100 (uint8_t) phDnld_Reset_State;
1101 psDnldContext->next_dnld_state =
1102 (uint8_t) phDnld_Reset_State;
1103 psDnldContext->cur_dnld_seq =
1104 (uint8_t) phDnld_Lock_System;
1105 psDnldContext->next_dnld_seq =
1106 psDnldContext->cur_dnld_seq;
1109 case DNLD_SEQ_UPDATE:
1111 prev_temp_state = (uint8_t) psDnldContext->cur_dnld_state;
1112 psDnldContext->cur_dnld_state =
1113 psDnldContext->next_dnld_state;
1114 /* psDnldContext->next_dnld_state =
1115 (uint8_t)phDnld_Invalid_State ; */
1116 prev_temp_seq = (uint8_t) psDnldContext->cur_dnld_seq;
1117 psDnldContext->cur_dnld_seq =
1118 psDnldContext->next_dnld_seq;
1121 case DNLD_SEQ_ROLLBACK:
1123 psDnldContext->cur_dnld_seq = (uint8_t) prev_temp_seq;
1124 psDnldContext->next_dnld_seq =
1125 (uint8_t)phDnld_Invalid_Seq ;
1128 psDnldContext->cur_dnld_state = (uint8_t) prev_temp_state;
1129 /* psDnldContext->next_dnld_state =
1130 (uint8_t)phDnld_Invalid_State ; */
1131 prev_temp_state = 0;
1134 case DNLD_SEQ_COMPLETE:
1136 psDnldContext->cur_dnld_state =
1137 (uint8_t) phDnld_Reset_State;
1138 psDnldContext->next_dnld_state =
1139 (uint8_t) phDnld_Verify_State;
1140 psDnldContext->cur_dnld_seq =
1141 (uint8_t) phDnld_Verify_Integrity;
1142 psDnldContext->next_dnld_seq =
1143 psDnldContext->cur_dnld_seq ;
1158 * \brief Sends the data the corresponding peripheral device.
1160 * This function sends the Download data to the connected NFC Pheripheral device
1173 phDnldNfc_sContext_t *psDnldContext= (phDnldNfc_sContext_t *)psContext;
1174 NFCSTATUS status = NFCSTATUS_SUCCESS;
1176 phNfc_sLowerIF_t *plower_if = &(psDnldContext->lower_interface);
1178 if( (NULL != plower_if)
1179 && (NULL != plower_if->send)
1182 #ifndef DNLD_SUMMARY
1183 DNLD_PRINT_BUFFER("Send Buffer",pdata,length);
1185 status = plower_if->send((void *)plower_if->pcontext,
1186 (void *)pHwRef, pdata, length);
1188 #if defined(FW_DOWNLOAD_TIMER) && \
1189 (FW_DOWNLOAD_TIMER == 2)
1191 (NFCSTATUS_PENDING == status)
1192 && ( NXP_INVALID_TIMER_ID != psDnldContext->timer_id )
1195 psDnldContext->dnld_timeout = NXP_DNLD_COMPLETE_TIMEOUT;
1197 if ( psDnldContext->dnld_timeout
1198 < DNLD_DEFAULT_RESPONSE_TIMEOUT)
1200 psDnldContext->dnld_timeout
1201 = DNLD_DEFAULT_RESPONSE_TIMEOUT;
1203 /* Start the Download Timer */
1204 phOsalNfc_Timer_Start( psDnldContext->timer_id,
1205 psDnldContext->dnld_timeout,
1206 (ppCallBck_t) phDnldNfc_Abort
1207 #ifdef NFC_TIMER_CONTEXT
1208 , (void *) psDnldContext
1212 DNLD_DEBUG(" DNLD : Timer %X Started ", psDnldContext->timer_id);
1213 DNLD_DEBUG(" \t\t With %U Timeout \n", psDnldContext->dnld_timeout);
1216 #endif /* (NXP_NFC_DNLD_TIMER == 1) */
1224 * \brief Receives the Download Mode Response from the corresponding peripheral device.
1226 * This function receives the Download Command Response to the connected NFC
1227 * Pheripheral device.
1239 phDnldNfc_sContext_t *psDnldContext= (phDnldNfc_sContext_t *)psContext;
1240 phNfc_sLowerIF_t *plower_if = NULL ;
1241 NFCSTATUS status = NFCSTATUS_SUCCESS;
1243 if(NULL == psDnldContext )
1245 status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
1249 plower_if = &(psDnldContext->lower_interface);
1251 if( (NULL != plower_if)
1252 && (NULL != plower_if->receive)
1255 status = plower_if->receive((void *)plower_if->pcontext,
1256 (void *)pHwRef, pdata, length);
1266 phDnldNfc_sContext_t *psDnldContext,
1268 section_info_t *p_sec_info
1271 NFCSTATUS status = NFCSTATUS_SUCCESS;
1272 phDnldNfc_sData_t *p_dnld_data =
1273 (phDnldNfc_sData_t *)psDnldContext->dnld_data;
1274 phDnldNfc_sParam_t *p_data_param =
1275 &p_dnld_data->param_info.data_param;
1276 uint32_t read_addr = (p_sec_info->p_sec_hdr->section_address
1277 + p_sec_info->section_offset);
1278 static unsigned sec_type = 0;
1280 uint16_t read_size = 0 ;
1282 sec_type = (unsigned int)p_sec_info->p_sec_hdr->section_mem_type;
1284 if( ( FALSE == p_sec_info->section_read )
1285 && ((sec_type & DNLD_TRIM_MASK))
1286 && (FALSE == p_sec_info->trim_write) )
1288 read_size = (uint16_t) p_sec_info->p_sec_hdr->section_length;
1289 DNLD_DEBUG(" FW_DNLD: Section Read = %X \n", read_size);
1293 if (( FALSE == p_sec_info->section_read )
1294 && ((sec_type & DNLD_VERIFY_MASK))
1297 read_size = (uint16_t)(psDnldContext->prev_dnld_size );
1298 DNLD_DEBUG(" FW_DNLD: Section Read = %X \n", read_size);
1300 else if( ( TRUE == p_sec_info->section_read )
1301 && ( TRUE == p_sec_info->section_write )
1304 /*Already Read the Data Hence Ignore the Read */
1305 DNLD_DEBUG(" FW_DNLD: Already Read, Read Ignored, read_size = %X \n", read_size);
1309 /* Ignore the Read */
1310 DNLD_DEBUG(" FW_DNLD: Section Read Status = %X \n", p_sec_info->section_read);
1311 DNLD_DEBUG(" FW_DNLD: Section Write Status = %X \n", p_sec_info->section_write);
1312 DNLD_DEBUG(" FW_DNLD: No Read Required, Read_size = %X \n", read_size);
1319 read_size = (uint16_t)((PHDNLD_DATA_SIZE >= read_size)?
1320 read_size: PHDNLD_DATA_SIZE);
1322 p_dnld_data->frame_length[i] = (uint8_t)0;
1323 /* Update the LSB of the Data and the Address Parameter*/
1324 p_data_param->data_addr[i] = (uint8_t)((read_addr >>
1325 (BYTE_SIZE + BYTE_SIZE)) & BYTE_MASK);
1326 p_data_param->data_len[i] = (uint8_t)((read_size >>
1327 BYTE_SIZE) & BYTE_MASK);
1330 p_dnld_data->frame_length[i] = (uint8_t)
1331 ( PHDNLD_CMD_READ_LEN & BYTE_MASK);
1332 /* Update the 2nd byte of the Data and the Address Parameter*/
1333 p_data_param->data_addr[i] = (uint8_t)((read_addr >>
1334 BYTE_SIZE) & BYTE_MASK);
1335 p_data_param->data_len[i] = (uint8_t) (read_size & BYTE_MASK);
1338 /* Update the 3rd byte of the the Address Parameter*/
1339 p_data_param->data_addr[i] = (uint8_t)(read_addr & BYTE_MASK);
1341 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
1342 PHDNLD_CMD_READ, NULL , 0 );
1344 if ( NFCSTATUS_PENDING == status )
1346 p_sec_info->section_read = TRUE ;
1347 psDnldContext->next_dnld_state = phDnld_Upgrade_State;
1348 DNLD_DEBUG(" FW_DNLD: Memory Read at Address %X : ", read_addr);
1349 DNLD_DEBUG(" of Size %X \n", read_size);
1360 phDnldNfc_Process_Write(
1361 phDnldNfc_sContext_t *psDnldContext,
1363 section_info_t *p_sec_info,
1364 uint32_t *p_sec_offset
1367 NFCSTATUS status = NFCSTATUS_SUCCESS;
1368 phDnldNfc_sData_t *p_dnld_data =
1369 (phDnldNfc_sData_t *)psDnldContext->dnld_data;
1370 phDnldNfc_sParam_t *dnld_data =
1371 &p_dnld_data->param_info.data_param;
1372 uint8_t *p_sm_trim_data = (uint8_t *)psDnldContext->
1373 dnld_resp.param_info.response_data;
1374 uint32_t dnld_addr = 0;
1375 #ifdef NXP_FW_SW_VMID_TRIM
1376 uint32_t trim_addr = 0;
1377 #endif /* #ifdef NXP_FW_SW_VMID_TRIM */
1378 static unsigned sec_type = 0;
1380 uint16_t dnld_size = 0;
1384 sec_type = (unsigned int)p_sec_info->p_sec_hdr->section_mem_type;
1386 status = phDnldNfc_Read(psDnldContext, pHwRef, p_sec_info);
1387 if( NFCSTATUS_PENDING != status )
1389 if( (TRUE == p_sec_info->trim_write)
1390 && (TRUE == p_sec_info->section_read)
1391 && ((sec_type & DNLD_VERIFY_MASK))
1394 if(NULL != psDnldContext->trim_store.buffer)
1396 uint32_t trim_cmp_size = psDnldContext->prev_dnld_size;
1398 if( p_sec_info->p_sec_hdr->section_address
1399 < (DNLD_CFG_PG_ADDR + PHDNLD_PAGE_SIZE) )
1401 trim_cmp_size = trim_cmp_size - 2;
1404 /* Below Comparison fails due to the checksum */
1405 cmp_val = phOsalNfc_MemCompare(
1406 psDnldContext->trim_store.buffer,
1407 &psDnldContext->dnld_resp.
1408 param_info.response_data[0]
1410 DNLD_DEBUG(" FW_DNLD: %X Bytes Trim Write Complete ",
1411 psDnldContext->prev_dnld_size);
1412 DNLD_DEBUG(" Comparison Status %X\n", cmp_val);
1414 p_sec_info->trim_write = FALSE;
1415 DNLD_DEBUG(" FW_DNLD: TRIMMED %X Bytes Write Complete\n", psDnldContext->prev_dnld_size);
1419 if((NULL != psDnldContext->dnld_store.buffer)
1420 && ((sec_type & DNLD_VERIFY_MASK))
1421 && (TRUE == p_sec_info->section_write)
1422 && (TRUE == p_sec_info->section_read)
1425 cmp_val = phOsalNfc_MemCompare(
1426 psDnldContext->dnld_store.buffer,
1427 &psDnldContext->dnld_resp.
1428 param_info.response_data[0]
1429 ,psDnldContext->dnld_store.length);
1430 p_sec_info->section_read = FALSE;
1431 p_sec_info->section_write = FALSE;
1432 DNLD_DEBUG(" FW_DNLD: %X Bytes Write Complete ",
1433 psDnldContext->dnld_store.length);
1434 DNLD_DEBUG(" Comparison Status %X\n", cmp_val);
1438 if(( TRUE == p_sec_info->section_write)
1439 && ( FALSE == p_sec_info->section_read)
1442 p_sec_info->section_write = FALSE;
1445 /* p_sec_info->section_read = FALSE; */
1448 if (( 0 == psDnldContext->dnld_retry )
1452 p_sec_info->sec_verify_retry = 0;
1453 p_sec_info->section_offset = p_sec_info->section_offset +
1454 psDnldContext->prev_dnld_size;
1455 psDnldContext->prev_dnld_size = 0;
1456 DNLD_DEBUG(" FW_DNLD: Memory Write Retry - %X \n",
1457 psDnldContext->dnld_retry);
1461 p_sec_info->sec_verify_retry++;
1462 DNLD_DEBUG(" FW_DNLD: Memory Verification Failed, Retry = %X \n",
1463 p_sec_info->sec_verify_retry);
1466 if( p_sec_info->sec_verify_retry < NXP_MAX_SECTION_WRITE )
1469 dnld_addr = (p_sec_info->p_sec_hdr->section_address + *p_sec_offset);
1470 dnld_size = (uint16_t)(p_sec_info->p_sec_hdr->section_length
1475 status = NFCSTATUS_FAILED;
1476 DNLD_DEBUG(" FW_DNLD: Memory Verification - Maximum Limit, Retry = %X \n",
1477 p_sec_info->sec_verify_retry);
1485 dnld_size = (uint16_t)((PHDNLD_DATA_SIZE >= dnld_size)?
1486 dnld_size: PHDNLD_DATA_SIZE);
1488 /* Update the LSB of the Data and the Address Parameter*/
1489 dnld_data->data_addr[i] = (uint8_t)((dnld_addr >>
1490 (BYTE_SIZE + BYTE_SIZE)) & BYTE_MASK);
1491 dnld_data->data_len[i] = (uint8_t)((dnld_size >> BYTE_SIZE)
1493 p_dnld_data->frame_length[i] = (uint8_t)
1494 (((dnld_size + PHDNLD_CMD_WRITE_MIN_LEN) >> BYTE_SIZE)
1497 /* Update the 2nd byte of the Data and the Address Parameter*/
1498 dnld_data->data_addr[i] = (uint8_t)((dnld_addr >> BYTE_SIZE)
1500 dnld_data->data_len[i] = (uint8_t) (dnld_size & BYTE_MASK);
1501 p_dnld_data->frame_length[i] = (uint8_t) ((dnld_size +
1502 PHDNLD_CMD_WRITE_MIN_LEN) & BYTE_MASK);
1504 /* Update the 3rd byte of the the Address Parameter*/
1505 dnld_data->data_addr[i] = (uint8_t)(dnld_addr & BYTE_MASK);
1507 (void)memcpy( dnld_data->data_packet,
1508 (p_sec_info->p_sec_data + *p_sec_offset), dnld_size );
1510 if( ((sec_type & DNLD_TRIM_MASK))
1511 && (p_sec_info->sec_verify_retry != 0)
1512 && (NULL != psDnldContext->trim_store.buffer)
1515 (void)memcpy( dnld_data->data_packet,
1516 psDnldContext->trim_store.buffer, dnld_size );
1518 else if(((sec_type & DNLD_TRIM_MASK))
1519 && ( TRUE == p_sec_info->section_read )
1522 for(i = 0; i < *(p_sec_info->p_trim_data);i++)
1525 #ifdef NXP_FW_SW_VMID_TRIM
1528 if(bit 0 of 0x813D is equal to 1) then
1530 Do not overwrite 0x9931 / 0x9981 during download
1534 @0x9931 = 0x79 // card Mode
1535 @0x9981 = 0x79 // Reader Mode
1537 trim_addr = p_sec_info->p_sec_hdr->section_address
1538 + p_sec_info->p_trim_data[i+1];
1539 if (NXP_FW_VMID_TRIM_CHK_ADDR == trim_addr)
1541 psDnldContext->vmid_trim_update =
1542 p_sm_trim_data[p_sec_info->p_trim_data[i+1]] ;
1545 if((NXP_FW_VMID_CARD_MODE_ADDR == trim_addr)
1546 || (NXP_FW_VMID_RD_MODE_ADDR == trim_addr))
1548 if (TRUE == psDnldContext->vmid_trim_update)
1550 dnld_data->data_packet[p_sec_info->p_trim_data[i+1]] =
1551 p_sm_trim_data[p_sec_info->p_trim_data[i+1]] ;
1558 dnld_data->data_packet[p_sec_info->p_trim_data[i+1]] =
1559 p_sm_trim_data[p_sec_info->p_trim_data[i+1]] ;
1562 if(NULL != psDnldContext->trim_store.buffer)
1564 phOsalNfc_FreeMemory(psDnldContext->trim_store.buffer);
1565 psDnldContext->trim_store.buffer = NULL;
1566 psDnldContext->trim_store.length = 0;
1570 phDnldNfc_Allocate_Resource((void **)
1571 &(psDnldContext->trim_store.buffer),dnld_size);
1573 psDnldContext->trim_store.buffer =
1574 (uint8_t *) phOsalNfc_GetMemory(dnld_size);
1577 if(NULL != psDnldContext->trim_store.buffer)
1579 (void )memset((void *)psDnldContext->trim_store.buffer,0,
1581 (void)memcpy( psDnldContext->trim_store.buffer,
1582 dnld_data->data_packet, dnld_size );
1583 psDnldContext->trim_store.length = dnld_size;
1584 DNLD_DEBUG(" FW_DNLD: Write with Trimming at Address %X ", dnld_addr );
1585 DNLD_DEBUG(" of Size %X and ", dnld_size );
1586 DNLD_DEBUG(" with %X Trimming Values \n", *(p_sec_info->p_trim_data) );
1592 if(NULL != psDnldContext->dnld_store.buffer)
1594 phOsalNfc_FreeMemory(psDnldContext->dnld_store.buffer);
1595 psDnldContext->dnld_store.buffer = NULL;
1596 psDnldContext->dnld_store.length = 0;
1600 phDnldNfc_Allocate_Resource((void **)
1601 &(psDnldContext->dnld_store.buffer),dnld_size);
1603 psDnldContext->dnld_store.buffer =
1604 (uint8_t *) phOsalNfc_GetMemory(dnld_size);
1606 if(NULL != psDnldContext->dnld_store.buffer)
1608 (void )memset((void *)psDnldContext->dnld_store.buffer,0,
1610 (void)memcpy( psDnldContext->dnld_store.buffer,
1611 dnld_data->data_packet, dnld_size );
1612 psDnldContext->dnld_store.length = dnld_size;
1613 DNLD_DEBUG(" FW_DNLD: Memory Write at Address %X ", dnld_addr );
1614 DNLD_DEBUG(" of Size %X ", dnld_size );
1618 if(PHDNLD_FW_PATCH_SEC != psDnldContext->p_fw_hdr->fw_patch)
1620 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
1621 PHDNLD_CMD_WRITE, NULL , 0 );
1625 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
1626 PHDNLD_CMD_SEC_WRITE, NULL , 0 );
1629 DNLD_DEBUG(" FW_DNLD: Memory Write Status = %X \n", status);
1630 if ( NFCSTATUS_PENDING == status )
1632 psDnldContext->prev_dnld_size = dnld_size;
1634 if((sec_type & DNLD_TRIM_MASK))
1636 p_sec_info->trim_write = TRUE;
1637 DNLD_DEBUG(" FW_DNLD: Bytes Downloaded (Trimming Values) = %X Bytes \n",
1642 p_sec_info->section_write = TRUE;
1643 DNLD_DEBUG(" FW_DNLD: Bytes Downloaded = %X : ",
1644 (*p_sec_offset + dnld_size));
1645 DNLD_DEBUG(" Bytes Remaining = %X \n",
1646 (p_sec_info->p_sec_hdr->section_length -
1647 (*p_sec_offset + dnld_size)));
1650 p_sec_info->section_read = FALSE;
1660 phDnldNfc_Resume_Write(
1661 phDnldNfc_sContext_t *psDnldContext,
1665 NFCSTATUS status = NFCSTATUS_SUCCESS;
1666 uint8_t sec_index = psDnldContext->section_index;
1667 section_info_t *p_sec_info = (psDnldContext->p_fw_sec + sec_index);
1669 while((sec_index < psDnldContext->p_fw_hdr->no_of_sections)
1670 && (NFCSTATUS_SUCCESS == status )
1674 status = phDnldNfc_Process_Write(psDnldContext, pHwRef,
1675 p_sec_info, (uint32_t *)&(p_sec_info->section_offset));
1676 if (NFCSTATUS_SUCCESS == status)
1678 unsigned sec_type = 0;
1679 sec_type = (unsigned int)p_sec_info->p_sec_hdr->section_mem_type;
1681 p_sec_info->section_offset = 0;
1682 p_sec_info->section_read = FALSE;
1683 p_sec_info->section_write = FALSE;
1684 p_sec_info->trim_write = FALSE;
1686 DNLD_DEBUG(" FW_DNLD: Section %02X Download Complete\n", sec_index);
1687 if((sec_type & DNLD_RESET_MASK))
1689 DNLD_DEBUG(" FW_DNLD: Reset After Section %02X Download \n", sec_index);
1690 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
1691 PHDNLD_CMD_RESET , NULL, 0 );
1693 DNLD_PRINT("*******************************************\n\n");
1697 #ifdef NXP_FW_DNLD_CHECK_PHASE
1698 if( p_sec_info->p_sec_hdr->section_address
1699 < (DNLD_CFG_PG_ADDR + PHDNLD_PAGE_SIZE) )
1701 gphDnldPhase = NXP_FW_DNLD_DATA_PHASE;
1705 p_sec_info = (psDnldContext->p_fw_sec + sec_index);
1707 if( (sec_index < psDnldContext->p_fw_hdr->no_of_sections)
1708 && ( p_sec_info->p_sec_hdr->section_address
1709 < (DNLD_CFG_PG_ADDR + PHDNLD_PAGE_SIZE) )
1712 if( NXP_FW_DNLD_CFG_PHASE >= gphDnldPhase )
1714 gphDnldPhase = NXP_FW_DNLD_CFG_PHASE;
1719 p_sec_info = (psDnldContext->p_fw_sec + sec_index);
1723 p_sec_info = (psDnldContext->p_fw_sec + sec_index);
1724 #endif /* #ifdef NXP_FW_DNLD_CHECK_PHASE */
1726 psDnldContext->section_index = sec_index;
1727 /* psDnldContext->next_dnld_state = (uint8_t) phDnld_Upgrade_State; */
1730 if (NFCSTATUS_PENDING == status)
1732 psDnldContext->next_dnld_state = (uint8_t) phDnld_Upgrade_State;
1734 else if (NFCSTATUS_SUCCESS == status)
1736 /* Reset the PN544 Device */
1737 psDnldContext->next_dnld_state = (uint8_t) phDnld_Complete_State;
1747 #define NXP_DNLD_SM_UNLOCK_ADDR 0x008002U
1749 #if !defined (ES_HW_VER)
1750 #define ES_HW_VER 32
1753 #if (ES_HW_VER <= 30)
1754 #define NXP_DNLD_PATCH_ADDR 0x01AFFFU
1756 #define NXP_DNLD_PATCH_ADDR 0x01A1E0U
1759 #if (ES_HW_VER <= 30)
1760 #define NXP_DNLD_PATCH_TABLE_ADDR 0x008107U
1762 #define NXP_DNLD_PATCH_TABLE_ADDR 0x00825AU
1769 phDnldNfc_sContext_t *psDnldContext,
1775 NFCSTATUS status = NFCSTATUS_SUCCESS;
1776 uint32_t dnld_addr = 0;
1777 phDnldNfc_sData_t *p_dnld_data =
1778 (phDnldNfc_sData_t *)psDnldContext->dnld_data;
1779 phDnldNfc_sParam_t *p_data_param =
1780 & p_dnld_data->param_info.data_param;
1781 uint8_t *p_data = NULL;
1782 static uint32_t patch_size = 0;
1784 #if (ES_HW_VER == 32)
1786 static uint8_t patch_table[] = {0xA0, 0xA1, 0xE0, 0x80, 0xA9, 0x6C };
1787 static uint8_t patch_data[] = {0xA5, 0xD0, 0xFE, 0xA5, 0xD0, 0xFD, 0xA5,
1788 0xD0, 0xFC, 0xA5, 0x02, 0x80, 0xA9, 0x75};
1790 #elif (ES_HW_VER == 31)
1792 static uint8_t patch_table[] = {0xA0, 0xAF, 0xE0, 0x80, 0x78, 0x84 };
1793 static uint8_t patch_data[] = {0xA5, 0xD0, 0xFE, 0xA5, 0xD0, 0xFD, 0xA5,
1794 0xD0, 0xFC, 0xD0, 0xE0, 0xA5, 0x02, 0x80, 0x78, 0x8D};
1796 #elif (ES_HW_VER == 30)
1798 static uint8_t patch_table[] = {0x80, 0x91, 0x51, 0xA0, 0xAF,
1799 0xFF, 0x80, 0x91, 0x5A};
1800 static uint8_t patch_data[] = {0x22};
1804 static uint8_t unlock_data[] = {0x00, 0x00};
1805 static uint8_t lock_data[] = {0x0C, 0x00};
1809 PHNFC_UNUSED_VARIABLE(pdata);
1810 PHNFC_UNUSED_VARIABLE(length);
1811 switch(psDnldContext->cur_dnld_seq)
1813 case phDnld_Reset_Seq:
1815 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
1816 PHDNLD_CMD_RESET , NULL , 0 );
1817 /* status = (NFCSTATUS_PENDING == status)? NFCSTATUS_SUCCESS:
1819 DNLD_DEBUG(" FW_DNLD: Reset Seq.. Status = %X \n", status);
1823 case phDnld_Activate_Patch:
1825 uint8_t patch_activate = 0x01;
1826 psDnldContext->next_dnld_seq =
1827 (uint8_t)phDnld_Update_Patch;
1828 #ifdef NXP_FW_DNLD_CHECK_PHASE
1829 gphDnldPhase = NXP_FW_DNLD_SYSTEM_PHASE;
1830 #endif /* NXP_FW_DNLD_CHECK_PHASE */
1832 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
1833 PHDNLD_CMD_ACTIVATE_PATCH , &patch_activate, sizeof(patch_activate) );
1834 DNLD_PRINT(" FW_DNLD: Activate the Patch Update .... \n");
1837 case phDnld_Deactivate_Patch:
1839 uint8_t patch_activate = 0x00;
1841 psDnldContext->next_dnld_state =
1842 (uint8_t)phDnld_Reset_State;
1844 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
1845 PHDNLD_CMD_ACTIVATE_PATCH , &patch_activate, sizeof(patch_activate) );
1846 DNLD_PRINT(" FW_DNLD: Deactivate the Patch Update .... \n");
1849 case phDnld_Update_Patch:
1851 dnld_addr = NXP_DNLD_PATCH_ADDR;
1852 patch_size = sizeof(patch_data) ;
1853 p_data = patch_data;
1854 psDnldContext->next_dnld_seq =
1855 (uint8_t)phDnld_Update_Patchtable;
1856 DNLD_PRINT(" FW_DNLD: Patch Update Seq.... \n");
1859 case phDnld_Update_Patchtable:
1861 dnld_addr = NXP_DNLD_PATCH_TABLE_ADDR;
1862 patch_size = sizeof(patch_table) ;
1863 p_data = patch_table;
1865 psDnldContext->next_dnld_state =
1866 (uint8_t)phDnld_Reset_State;
1868 DNLD_PRINT(" FW_DNLD: Patch Table Update Seq.... \n");
1871 case phDnld_Unlock_System:
1873 dnld_addr = NXP_DNLD_SM_UNLOCK_ADDR;
1874 patch_size = sizeof(unlock_data) ;
1875 p_data = unlock_data;
1876 #define NXP_FW_PATCH_DISABLE
1877 #ifdef NXP_FW_PATCH_DISABLE
1878 psDnldContext->next_dnld_seq =
1879 (uint8_t)phDnld_Deactivate_Patch;
1881 psDnldContext->next_dnld_state =
1882 (uint8_t)phDnld_Reset_State;
1885 DNLD_PRINT(" FW_DNLD: System Memory Unlock Seq.... \n");
1888 case phDnld_Lock_System:
1890 dnld_addr = NXP_DNLD_SM_UNLOCK_ADDR;
1891 patch_size = sizeof(lock_data) ;
1893 psDnldContext->next_dnld_state =
1894 (uint8_t) phDnld_Reset_State;
1896 DNLD_PRINT(" FW_DNLD: System Memory Lock Seq.... \n");
1899 case phDnld_Upgrade_Section:
1901 status = phDnldNfc_Resume_Write(
1902 psDnldContext, pHwRef );
1905 case phDnld_Verify_Integrity:
1907 psDnldContext->next_dnld_state =
1908 (uint8_t) phDnld_Reset_State;
1910 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
1911 PHDNLD_CMD_CHECK_INTEGRITY , NULL, 0 );
1912 DNLD_PRINT(" FW_DNLD: System Memory Integrity Check Sequence.... \n");
1915 case phDnld_Verify_Section:
1925 if( NFCSTATUS_SUCCESS == status)
1928 /* Update the LSB of the Data and the Address Parameter*/
1929 p_data_param->data_addr[i] = (uint8_t)((dnld_addr >>
1930 (BYTE_SIZE + BYTE_SIZE))
1932 p_data_param->data_len[i] = (uint8_t)((patch_size >> BYTE_SIZE)
1934 p_dnld_data->frame_length[i] = (uint8_t)
1935 (((patch_size + PHDNLD_CMD_WRITE_MIN_LEN) >> BYTE_SIZE)
1938 /* Update the 2nd byte of the Data and the Address Parameter*/
1939 p_data_param->data_addr[i] = (uint8_t)((dnld_addr >> BYTE_SIZE)
1941 p_data_param->data_len[i] = (uint8_t) (patch_size & BYTE_MASK);
1942 p_dnld_data->frame_length[i] = (uint8_t)
1943 ((patch_size + PHDNLD_CMD_WRITE_MIN_LEN)
1946 /* Update the 3rd byte of the the Address Parameter*/
1947 p_data_param->data_addr[i] = (uint8_t)(dnld_addr & BYTE_MASK);
1949 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
1950 PHDNLD_CMD_WRITE,(void *)p_data , (uint8_t)patch_size );
1952 if (NFCSTATUS_PENDING != status)
1954 status = phDnldNfc_Set_Seq(psDnldContext,
1961 #define FRAME_HEADER_LEN 0x03U
1966 phDnldNfc_Tx_Reset(phDnldNfc_sContext_t *psDnldContext)
1968 psDnldContext->tx_info.transmit_frame = NULL;
1969 psDnldContext->tx_info.tx_total = 0x00;
1970 psDnldContext->tx_info.tx_offset = 0x00;
1971 psDnldContext->tx_info.tx_len = 0x00;
1972 psDnldContext->tx_info.tx_chain = FALSE;
1977 phDnldNfc_Extract_Chunks(
1978 uint8_t *frame_data,
1979 uint16_t frame_offset,
1980 uint16_t frame_length,
1981 uint16_t max_frame ,
1982 uint16_t *chunk_length
1988 phDnldNfc_Extract_Chunks(
1989 uint8_t *frame_data,
1990 uint16_t frame_offset,
1991 uint16_t frame_length,
1992 uint16_t max_frame ,
1993 uint16_t *chunk_length
1996 bool_t chunk_present = FALSE;
1998 if( 0 == frame_offset)
2000 if( max_frame >= (frame_length
2003 *chunk_length = (frame_length - frame_offset);
2007 *chunk_length = max_frame
2009 chunk_present = TRUE;
2014 if( max_frame >= (frame_length
2017 *chunk_length = (frame_length - frame_offset);
2021 *chunk_length = max_frame
2023 chunk_present = TRUE;
2027 return chunk_present;
2034 phDnldNfc_sContext_t *psDnldContext,
2037 uint16_t frame_offset,
2038 uint16_t frame_length
2041 NFCSTATUS status = NFCSTATUS_SUCCESS;
2042 phDnldNfc_sRawHdr_t *raw_frame_hdr = ( phDnldNfc_sRawHdr_t * ) raw_frame;
2044 switch(raw_frame_hdr->frame_type)
2046 case PHDNLD_CMD_RESET:
2050 case PHDNLD_CMD_READ:
2052 /* TODO: To Update the length and the buffer to receive data */
2055 case PHDNLD_CMD_WRITE:
2057 phDnldNfc_sRawDataHdr_t *raw_data_hdr =
2058 ( phDnldNfc_sRawDataHdr_t * ) (raw_frame + FRAME_HEADER_LEN);
2060 psDnldContext->resp_length = PHDNLD_MIN_PACKET;
2064 case PHDNLD_CMD_SEC_WRITE:
2066 uint16_t tx_length = 0x00;
2067 uint16_t frame_offset =
2068 psDnldContext->tx_info.tx_offset;
2070 psDnldContext->tx_info.tx_chain;
2073 phDnldNfc_Extract_Chunks(
2077 PHDNLD_FW_TX_RX_LEN,
2083 status = phDnldNfc_Send_Command( psDnldContext,
2084 pHwRef, PHDNLD_CMD_ENCAPSULATE,
2085 (raw_frame + frame_offset),
2087 if(NFCSTATUS_PENDING == status)
2089 psDnldContext->prev_cmd = raw_frame_hdr->frame_type;
2090 /* TODO: Update for the Chaining */
2091 psDnldContext->tx_info.tx_offset += tx_length;
2092 psDnldContext->tx_info.tx_chain = chain;
2095 else if (0 != frame_offset)
2097 status = phDnldNfc_Send_Command( psDnldContext,
2098 pHwRef, PHDNLD_CMD_ENCAPSULATE,
2099 (raw_frame + frame_offset),
2101 if(NFCSTATUS_PENDING == status)
2103 psDnldContext->prev_cmd = raw_frame_hdr->frame_type;
2104 /* TODO: Update for the Chaining */
2105 psDnldContext->prev_dnld_size = frame_length;
2106 phDnldNfc_Tx_Reset(psDnldContext);
2111 phDnldNfc_sRawDataHdr_t *raw_data_hdr =
2112 ( phDnldNfc_sRawDataHdr_t * ) (raw_frame + FRAME_HEADER_LEN);
2113 psDnldContext->resp_length = PHDNLD_MIN_PACKET;
2118 case PHDNLD_CMD_CHECK:
2120 psDnldContext->resp_length = PHDNLD_MIN_PACKET;
2123 case PHDNLD_CMD_SET_HIF:
2125 psDnldContext->resp_length = PHDNLD_MIN_PACKET;
2128 case PHDNLD_CMD_ACTIVATE_PATCH:
2130 psDnldContext->resp_length = PHDNLD_MIN_PACKET;
2133 case PHDNLD_CMD_CHECK_INTEGRITY:
2135 uint8_t integrity_param =
2136 *(raw_frame + FRAME_HEADER_LEN);
2137 switch(integrity_param)
2139 case CHK_INTEGRITY_CONFIG_PAGE_CRC:
2140 case CHK_INTEGRITY_PATCH_TABLE_CRC:
2142 psDnldContext->resp_length = PHDNLD_MIN_PACKET
2143 + CHECK_INTEGRITY_RESP_CRC16_LEN;
2146 case CHK_INTEGRITY_FLASH_CODE_CRC:
2147 case CHK_INTEGRITY_PATCH_CODE_CRC:
2149 psDnldContext->resp_length = PHDNLD_MIN_PACKET
2150 + CHECK_INTEGRITY_RESP_CRC32_LEN;
2153 case CHK_INTEGRITY_COMPLETE_CRC:
2156 psDnldContext->resp_length = PHDNLD_MIN_PACKET
2157 + CHECK_INTEGRITY_RESP_COMP_LEN;
2165 status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_FEATURE_NOT_SUPPORTED);
2170 if (NFCSTATUS_SUCCESS == status)
2172 status = phDnldNfc_Send( psDnldContext, pHwRef ,
2173 raw_frame, frame_length);
2175 if(NFCSTATUS_PENDING == status)
2177 psDnldContext->prev_cmd = raw_frame_hdr->frame_type;
2178 /* TODO: Update for the Chaining */
2179 psDnldContext->prev_dnld_size = frame_length;
2189 phDnldNfc_Frame_Complete(phDnldNfc_sContext_t *psDnldContext)
2191 NFCSTATUS status = NFCSTATUS_SUCCESS;
2192 phDnldNfc_sData_Hdr_t *p_dnld_raw = NULL;
2193 uint32_t dnld_index = psDnldContext->dnld_index;
2194 uint8_t *p_raw_sec_hdr = NULL;
2195 uint16_t tx_length = 0x00;
2197 dnld_index = dnld_index + psDnldContext->prev_dnld_size;
2198 p_raw_sec_hdr = psDnldContext->p_fw_raw + dnld_index;
2199 dnld_index = dnld_index + *p_raw_sec_hdr;
2201 p_dnld_raw = (phDnldNfc_sData_Hdr_t *) (psDnldContext->p_fw_raw +
2202 psDnldContext->dnld_index);
2204 tx_length = ((p_dnld_raw->frame_length[0] << BYTE_SIZE) |
2205 p_dnld_raw->frame_length[1]);
2207 tx_length = tx_length + PHDNLD_MIN_PACKET;
2215 phDnldNfc_Raw_Write(
2216 phDnldNfc_sContext_t *psDnldContext,
2220 NFCSTATUS status = NFCSTATUS_SUCCESS;
2221 uint32_t dnld_index = psDnldContext->dnld_index;
2222 uint32_t tx_length = 0;
2223 uint8_t *p_raw_sec_hdr = NULL;
2224 uint8_t dnld_flag = FALSE;
2225 uint8_t skip_frame = FALSE;
2227 if(NULL != psDnldContext->p_fw_raw)
2230 if( (TRUE != psDnldContext->tx_info.tx_chain)
2231 && (0x00 == psDnldContext->dnld_retry)
2234 dnld_index = dnld_index + psDnldContext->prev_dnld_size;
2235 p_raw_sec_hdr = psDnldContext->p_fw_raw + dnld_index;
2236 dnld_index = dnld_index + *p_raw_sec_hdr;
2240 phDnldNfc_sData_Hdr_t *p_dnld_raw = (phDnldNfc_sData_Hdr_t *)
2241 (psDnldContext->p_fw_raw +
2242 psDnldContext->dnld_index);
2244 tx_length = ((p_dnld_raw->frame_length[0] << BYTE_SIZE) |
2245 p_dnld_raw->frame_length[1]);
2247 tx_length = tx_length + PHDNLD_MIN_PACKET;
2249 status = phDnldNfc_Send_Raw( psDnldContext, pHwRef,
2250 (uint8_t *)(p_dnld_raw),
2251 psDnldContext->tx_info.tx_offset,
2252 (uint16_t)tx_length);
2256 #define PHDNLD_MAJOR_OFFSET 0x04U
2257 #define PHDNLD_MINOR_OFFSET 0x05U
2258 #define PHDNLD_PHASE_OFFSET 0x06U
2259 #define PHDNLD_FRAMETYPE_OFFSET 0x07U
2261 #define PHDNLD_NO_OPERATION 0x00U
2262 #define PHDNLD_NORMAL_OPERATION 0x10U
2263 #define PHDNLD_ADVANCED_OPERATION 0x20U
2264 #define PHDNLD_SETUP_OPERATION 0x40U
2265 #define PHDNLD_RECOVER_OPERATION 0x80U
2266 #define PHDNLD_COMPLETE_OPERATION 0xF0U
2268 #define PHDNLD_TERMINATE_TYPE 0x0EU
2270 #define PHDNLD_MARKER_MASK 0x0FU
2272 while((NFCSTATUS_SUCCESS == status )
2273 && (FALSE == dnld_flag)
2276 phDnldNfc_sData_Hdr_t *p_dnld_raw = (phDnldNfc_sData_Hdr_t *)
2277 (psDnldContext->p_fw_raw + dnld_index);
2278 uint8_t frame_type = *(p_raw_sec_hdr + PHDNLD_FRAMETYPE_OFFSET);
2280 tx_length = ((p_dnld_raw->frame_length[0] << BYTE_SIZE) |
2281 p_dnld_raw->frame_length[1]);
2283 tx_length = tx_length + PHDNLD_MIN_PACKET;
2287 if( (0x00 == *(p_raw_sec_hdr + PHDNLD_PHASE_OFFSET))
2288 || (0xFF == *(p_raw_sec_hdr + PHDNLD_PHASE_OFFSET))
2289 || !( psDnldContext->raw_mode_upgrade
2290 & (frame_type & (~PHDNLD_MARKER_MASK)) )
2293 dnld_index = dnld_index + tx_length;
2294 p_raw_sec_hdr = psDnldContext->p_fw_raw + dnld_index;
2295 dnld_index = dnld_index + *p_raw_sec_hdr;
2298 if (PHDNLD_TERMINATE_TYPE ==
2299 (frame_type & PHDNLD_MARKER_MASK))
2301 if(TRUE != skip_frame)
2303 psDnldContext->raw_mode_upgrade =
2304 (psDnldContext->raw_mode_upgrade &
2305 ~(frame_type & ~PHDNLD_MARKER_MASK));
2308 if(PHDNLD_NO_OPERATION ==
2309 psDnldContext->raw_mode_upgrade)
2319 if((FALSE == skip_frame)
2320 && (FALSE == dnld_flag)
2323 status = phDnldNfc_Send_Raw( psDnldContext, pHwRef,
2324 (uint8_t *)(p_dnld_raw),
2325 psDnldContext->tx_info.tx_offset,
2326 (uint16_t)tx_length);
2329 if( NFCSTATUS_PENDING == status )
2331 psDnldContext->dnld_index = dnld_index;
2332 psDnldContext->cur_frame_info= frame_type;
2342 phDnldNfc_Upgrade_Sequence(
2343 phDnldNfc_sContext_t *psDnldContext,
2349 NFCSTATUS status = NFCSTATUS_SUCCESS;
2351 PHNFC_UNUSED_VARIABLE(pdata);
2352 PHNFC_UNUSED_VARIABLE(length);
2354 if(phDnld_Raw_Upgrade == psDnldContext->cur_dnld_seq)
2356 status = phDnldNfc_Raw_Write( psDnldContext, pHwRef );
2360 status = phDnldNfc_Resume_Write( psDnldContext, pHwRef );
2371 phDnldNfc_sContext_t *psDnldContext,
2377 NFCSTATUS status = NFCSTATUS_SUCCESS;
2378 phDnldNfc_eState_t dnld_next_state = (phDnldNfc_eState_t)
2379 psDnldContext->cur_dnld_state;
2380 phNfc_sCompletionInfo_t comp_info = {0,0,0};
2382 switch( dnld_next_state )
2384 case phDnld_Reset_State:
2386 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
2387 PHDNLD_CMD_RESET , NULL, 0 );
2388 switch( psDnldContext->cur_dnld_seq )
2390 case phDnld_Update_Patchtable:
2392 psDnldContext->next_dnld_state =
2393 (uint8_t)phDnld_Unlock_State;
2394 psDnldContext->next_dnld_seq =
2395 (uint8_t)phDnld_Unlock_System;
2398 #ifdef NXP_FW_PATCH_DISABLE
2399 case phDnld_Deactivate_Patch:
2401 case phDnld_Unlock_System:
2404 psDnldContext->next_dnld_state =
2405 (uint8_t)phDnld_Upgrade_State;
2406 psDnldContext->next_dnld_seq =
2407 (uint8_t)phDnld_Upgrade_Section;
2408 #ifdef NXP_FW_DNLD_CHECK_PHASE
2409 gphDnldPhase = NXP_FW_DNLD_CFG_PHASE;
2410 #endif /* NXP_FW_DNLD_CHECK_PHASE */
2413 case phDnld_Lock_System:
2415 #if (NXP_FW_INTEGRITY_CHK >= 0x01)
2416 psDnldContext->next_dnld_state =
2417 (uint8_t)phDnld_Verify_State;
2418 psDnldContext->next_dnld_seq =
2419 (uint8_t)phDnld_Verify_Integrity;
2421 /* (void ) memset( (void *) &psDnldContext->chk_integrity_crc,
2422 0, sizeof(psDnldContext->chk_integrity_crc)); */
2423 psDnldContext->next_dnld_state =
2424 (uint8_t) phDnld_Complete_State;
2425 #endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
2428 case phDnld_Verify_Integrity:
2430 psDnldContext->next_dnld_state =
2431 (uint8_t) phDnld_Complete_State;
2436 status = (NFCSTATUS_PENDING == status)?
2437 NFCSTATUS_SUCCESS: status;
2443 case phDnld_Unlock_State:
2446 status = phDnldNfc_Sequence( psDnldContext, pHwRef,
2450 case phDnld_Upgrade_State:
2452 status = phDnldNfc_Upgrade_Sequence( psDnldContext, pHwRef,
2454 if ((NFCSTATUS_SUCCESS == status )
2455 && (phDnld_Complete_State == psDnldContext->next_dnld_state))
2458 psDnldContext->cur_dnld_seq =
2459 (uint8_t)phDnld_Lock_System;
2460 psDnldContext->next_dnld_seq =
2461 psDnldContext->cur_dnld_seq;
2463 #if (NXP_FW_INTEGRITY_CHK >= 0x01)
2464 psDnldContext->next_dnld_state =
2465 (uint8_t)phDnld_Verify_State;
2466 psDnldContext->next_dnld_seq =
2467 (uint8_t)phDnld_Verify_Integrity;
2468 psDnldContext->cur_dnld_seq =
2469 psDnldContext->next_dnld_seq;
2470 status = phDnldNfc_Sequence( psDnldContext,
2471 pHwRef, pdata, length);
2473 /* (void ) memset( (void *) &psDnldContext->chk_integrity_crc,
2474 0, sizeof(psDnldContext->chk_integrity_crc)); */
2475 psDnldContext->next_dnld_state =
2476 (uint8_t) phDnld_Complete_State;
2477 #endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
2481 case phDnld_Verify_State:
2483 status = phDnldNfc_Sequence( psDnldContext,
2484 pHwRef, pdata, length);
2487 case phDnld_Complete_State:
2489 uint8_t integrity_chk = 0xA5;
2491 #if (NXP_FW_INTEGRITY_CHK >= 0x01)
2492 uint8_t verify_crc = 0x96;
2494 if ( (NULL != psDnldContext->p_flash_code_crc)
2495 && (NULL != psDnldContext->p_patch_code_crc)
2496 && (NULL != psDnldContext->p_patch_table_crc)
2500 uint16_t patch_table_crc = 0;
2501 uint32_t flash_code_crc = 0;
2502 uint32_t patch_code_crc = 0;
2504 for (crc_i = 0; crc_i < DNLD_CRC32_SIZE; crc_i++ )
2506 if (crc_i < DNLD_CRC16_SIZE )
2508 patch_table_crc = patch_table_crc
2509 | psDnldContext->chk_integrity_crc.patch_table.Chk_Crc16[crc_i]
2510 << (crc_i * BYTE_SIZE) ;
2512 flash_code_crc = flash_code_crc
2513 | psDnldContext->chk_integrity_crc.flash_code.Chk_Crc32[crc_i]
2514 << (crc_i * BYTE_SIZE) ;
2515 patch_code_crc = patch_code_crc
2516 | psDnldContext->chk_integrity_crc.patch_code.Chk_Crc32[crc_i]
2517 << (crc_i * BYTE_SIZE) ;
2519 verify_crc =(uint8_t)( (*((uint32_t *) psDnldContext->p_flash_code_crc)) !=
2521 verify_crc |=(uint8_t)( (*((uint32_t *) psDnldContext->p_patch_code_crc)) !=
2523 verify_crc |=(uint8_t)( (*((uint16_t *) psDnldContext->p_patch_table_crc)) !=
2528 DNLD_PRINT(" FW_DNLD: Flash, Patch code and Patch Table CRC ");
2529 DNLD_PRINT(" Not Available in the Firmware \n");
2532 #endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
2534 integrity_chk = psDnldContext->chk_integrity_crc.config_page.Chk_status +
2535 psDnldContext->chk_integrity_crc.patch_table.Chk_status +
2536 psDnldContext->chk_integrity_crc.flash_code.Chk_status +
2537 psDnldContext->chk_integrity_crc.patch_code.Chk_status;
2539 if ( ( 0 != integrity_chk )
2540 #if (NXP_FW_INTEGRITY_CHK >= 0x01)
2541 || ( 0 != verify_crc )
2542 #endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
2545 status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_FAILED);
2551 status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_FAILED);
2556 if (NFCSTATUS_PENDING == status)
2558 /* Write/Receive is still pending */
2562 pphNfcIF_Notification_CB_t p_upper_notify =
2563 psDnldContext->p_upper_notify;
2564 void *p_upper_context =
2565 psDnldContext->p_upper_context;
2567 DNLD_DEBUG(" FW_DNLD: Resume Termination Status = %X \n", status);
2569 comp_info.status = status;
2571 (void) phDal4Nfc_Unregister(
2572 psDnldContext->lower_interface.pcontext, pHwRef);
2573 phDnldNfc_Release_Lower(psDnldContext, pHwRef);
2574 phDnldNfc_Release_Resources(&psDnldContext);
2575 #ifndef NFC_TIMER_CONTEXT
2576 gpphDnldContext = psDnldContext;
2578 /* Notify the Error/Success Scenario to the upper layer */
2579 phDnldNfc_Notify( p_upper_notify, p_upper_context, pHwRef, (uint8_t)
2580 ((NFCSTATUS_SUCCESS == comp_info.status )? NFC_IO_SUCCESS: NFC_IO_ERROR),
2588 phDnldNfc_Process_Response(
2589 phDnldNfc_sContext_t *psDnldContext,
2595 NFCSTATUS status = NFCSTATUS_SUCCESS;
2596 phDnldNfc_sData_Hdr_t *resp_data =
2597 (phDnldNfc_sData_Hdr_t *) pdata;
2599 PHNFC_UNUSED_VARIABLE(pHwRef);
2600 DNLD_DEBUG(" FW_DNLD: Receive Length = %X \n", length );
2601 if(( psDnldContext->rx_info.rx_total == 0 )
2602 && (PHDNLD_MIN_PACKET <= length)
2605 psDnldContext->rx_info.rx_total =
2606 ((uint16_t)resp_data->frame_length[0] << BYTE_SIZE)|
2607 resp_data->frame_length[1];
2608 if( psDnldContext->rx_info.rx_total + PHDNLD_MIN_PACKET == length )
2611 DNLD_DEBUG(" FW_DNLD: Success Memory Read = %X \n",
2612 psDnldContext->rx_info.rx_total);
2613 #ifndef DNLD_SUMMARY
2614 /* DNLD_PRINT_BUFFER("Receive Buffer",pdata,length); */
2620 /* status = phDnldNfc_Receive( psDnldContext, pHwRef,
2621 psDnldContext->p_resp_buffer,
2622 (uint8_t)((psDnldContext->rx_info.rx_total <= PHDNLD_MAX_PACKET)?
2623 psDnldContext->rx_info.rx_total: PHDNLD_MAX_PACKET) ); */
2624 DNLD_PRINT(" FW_DNLD: Invalid Receive length ");
2625 DNLD_DEBUG(": Length Expected = %X \n",
2626 (psDnldContext->rx_info.rx_total + PHDNLD_MIN_PACKET));
2627 status = PHNFCSTVAL( CID_NFC_DNLD,
2628 NFCSTATUS_INVALID_RECEIVE_LENGTH );
2634 psDnldContext->rx_info.rx_total = 0 ;
2635 status = PHNFCSTVAL( CID_NFC_DNLD,
2636 NFCSTATUS_INVALID_RECEIVE_LENGTH );
2646 phDnldNfc_Receive_Complete (
2649 phNfc_sTransactionInfo_t *pInfo
2652 NFCSTATUS status = NFCSTATUS_SUCCESS ;
2653 void *pdata = NULL ;
2654 phDnldNfc_sData_Hdr_t *resp_data = NULL;
2655 uint16_t length = 0 ;
2656 phNfc_sCompletionInfo_t comp_info = {0,0,0};
2658 DNLD_PRINT("\n FW_DNLD: Receive Response .... ");
2659 if ( (NULL != psContext)
2664 phDnldNfc_sContext_t *psDnldContext =
2665 (phDnldNfc_sContext_t *)psContext;
2666 status = pInfo->status ;
2667 length = pInfo->length ;
2668 pdata = pInfo->buffer;
2670 if(status != NFCSTATUS_SUCCESS)
2672 DNLD_DEBUG(" Failed. Status = %02X\n",status);
2673 /* Handle the Error Scenario */
2675 else if (NULL == pdata)
2677 DNLD_DEBUG(" Failed. No data received. pdata = %02X\n",pdata);
2678 /* Handle the Error Scenario */
2679 status = PHNFCSTVAL( CID_NFC_DNLD, NFCSTATUS_FAILED );
2681 else if ((0 == length)
2682 || (PHDNLD_MIN_PACKET > length ))
2684 DNLD_DEBUG(" Receive Response Length = %u .... \n",length);
2685 /* Handle the Error Scenario */
2686 #ifndef HAL_SW_DNLD_RLEN
2687 status = PHNFCSTVAL( CID_NFC_DNLD,
2688 NFCSTATUS_INVALID_RECEIVE_LENGTH );
2694 #if defined(FW_DOWNLOAD_TIMER) && \
2695 (FW_DOWNLOAD_TIMER == 2)
2696 if ( NXP_INVALID_TIMER_ID != psDnldContext->timer_id )
2698 phOsalNfc_Timer_Stop( psDnldContext->timer_id );
2703 #ifndef DNLD_SUMMARY
2704 DNLD_PRINT_BUFFER("Receive Buffer",pdata,length);
2706 DNLD_DEBUG(" Receive Response Length = %X. \n", length);
2708 resp_data = (phDnldNfc_sData_Hdr_t *) pdata;
2710 switch(resp_data->frame_type)
2712 case PHDNLD_RESP_SUCCESS:
2714 uint16_t resp_length =
2715 ((uint16_t)resp_data->frame_length[0] << BYTE_SIZE)|
2716 resp_data->frame_length[1];
2717 switch ( psDnldContext->prev_cmd )
2719 case PHDNLD_CMD_READ :
2721 if( PHDNLD_NO_OPERATION
2722 == psDnldContext->raw_mode_upgrade)
2724 status = phDnldNfc_Process_Response(
2725 psDnldContext, pHwRef, pdata , length);
2727 if (NFCSTATUS_SUCCESS != status)
2729 /* psDnldContext->dnld_retry++; */
2730 psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
2731 /* psDnldContext->dnld_retry < NXP_MAX_DNLD_RETRY */
2740 case PHDNLD_CMD_CHECK_INTEGRITY :
2742 if( PHDNLD_NO_OPERATION
2743 == psDnldContext->raw_mode_upgrade)
2745 #if (NXP_FW_INTEGRITY_CHK >= 0x01)
2746 phDnldNfc_sChkCrcComplete_t *p_dnld_crc_all =
2747 &psDnldContext->chk_integrity_crc;
2748 switch(psDnldContext->chk_integrity_param)
2750 case CHK_INTEGRITY_CONFIG_PAGE_CRC:
2752 (void)memcpy(&p_dnld_crc_all->config_page,
2753 (((uint8_t *)pdata) + PHDNLD_MIN_PACKET), resp_length);
2756 case CHK_INTEGRITY_PATCH_TABLE_CRC:
2758 (void)memcpy(&p_dnld_crc_all->patch_table,
2759 (((uint8_t *)pdata) + PHDNLD_MIN_PACKET), resp_length);
2762 case CHK_INTEGRITY_FLASH_CODE_CRC:
2764 (void)memcpy(&p_dnld_crc_all->flash_code,
2765 (((uint8_t *)pdata) + PHDNLD_MIN_PACKET), resp_length);
2768 case CHK_INTEGRITY_PATCH_CODE_CRC:
2770 (void)memcpy(&p_dnld_crc_all->patch_code,
2771 (((uint8_t *)pdata) + PHDNLD_MIN_PACKET), resp_length);
2774 case CHK_INTEGRITY_COMPLETE_CRC:
2776 (void)memcpy(p_dnld_crc_all,
2777 (((uint8_t *)pdata) + PHDNLD_MIN_PACKET), resp_length);
2778 DNLD_DEBUG(" FW_DNLD: Check Integrity Complete Structure Size = %X \n",
2779 sizeof(psDnldContext->chk_integrity_crc));
2784 status = PHNFCSTVAL(CID_NFC_DNLD,
2785 NFCSTATUS_FEATURE_NOT_SUPPORTED);
2789 #endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
2793 psDnldContext->raw_mode_upgrade =
2794 (PHDNLD_SETUP_OPERATION | PHDNLD_ADVANCED_OPERATION);
2795 /* psDnldContext->raw_mode_upgrade =
2796 (psDnldContext->raw_mode_upgrade &
2797 ( psDnldContext->cur_frame_info & ~PHDNLD_MARKER_MASK )); */
2801 case PHDNLD_CMD_WRITE:
2803 psDnldContext->dnld_retry = 0;
2806 case PHDNLD_CMD_SEC_WRITE:
2808 psDnldContext->dnld_retry = 0;
2811 case PHDNLD_CMD_ACTIVATE_PATCH:
2812 case PHDNLD_CMD_CHECK:
2815 if( PHDNLD_NO_OPERATION
2816 == psDnldContext->raw_mode_upgrade)
2818 if( ( (PHDNLD_MIN_PACKET > length)
2819 || ( 0 != resp_length) )
2822 psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
2823 status = PHNFCSTVAL( CID_NFC_DNLD,
2824 NFCSTATUS_INVALID_RECEIVE_LENGTH );
2828 psDnldContext->dnld_retry = 0;
2833 psDnldContext->raw_mode_upgrade =
2834 (psDnldContext->raw_mode_upgrade & ~PHDNLD_RECOVER_OPERATION);
2838 } /* End of the Previous Command Switch Case */
2840 }/* Case PHDNLD_RESP_SUCCESS*/
2841 case PHDNLD_RESP_TIMEOUT:
2842 case PHDNLD_RESP_CRC_ERROR:
2843 case PHDNLD_RESP_WRITE_ERROR:
2845 if(psDnldContext->dnld_retry < NXP_MAX_DNLD_RETRY )
2847 psDnldContext->dnld_retry++;
2849 status = PHNFCSTVAL(CID_NFC_DNLD,
2850 resp_data->frame_type);
2854 case PHDNLD_RESP_ACCESS_DENIED:
2855 case PHDNLD_RESP_INVALID_PARAMETER:
2856 case PHDNLD_RESP_INVALID_LENGTH:
2857 /* Initial Frame Checksum */
2858 case PHDNLD_RESP_CHKSUM_ERROR:
2859 case PHDNLD_RESP_MEMORY_UPDATE_ERROR:
2861 psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
2862 status = PHNFCSTVAL(CID_NFC_DNLD,
2863 resp_data->frame_type);
2866 case PHDNLD_RESP_PROTOCOL_ERROR:
2868 if(( PHDNLD_NO_OPERATION
2869 == psDnldContext->raw_mode_upgrade)
2870 || ( PHDNLD_ADVANCED_OPERATION
2871 == psDnldContext->raw_mode_upgrade)
2874 psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
2875 status = PHNFCSTVAL(CID_NFC_DNLD,
2876 NFCSTATUS_INVALID_FORMAT);
2878 else if( (PHDNLD_NORMAL_OPERATION
2879 & psDnldContext->raw_mode_upgrade)
2882 psDnldContext->raw_mode_upgrade =
2883 (psDnldContext->raw_mode_upgrade & ~PHDNLD_NORMAL_OPERATION);
2885 else if ( PHDNLD_RECOVER_OPERATION
2886 & psDnldContext->raw_mode_upgrade )
2888 psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
2889 status = PHNFCSTVAL(CID_NFC_DNLD,
2890 NFCSTATUS_INVALID_FORMAT);
2894 psDnldContext->raw_mode_upgrade =
2895 (psDnldContext->raw_mode_upgrade &
2896 ~( psDnldContext->cur_frame_info & ~PHDNLD_MARKER_MASK ));
2900 case PHDNLD_RESP_VERSION_UPTODATE:
2902 /* TODO: to make sure that the Advance Frames are sent to get
2903 * the updated status */
2904 if ( PHDNLD_ADVANCED_OPERATION
2905 == psDnldContext->raw_mode_upgrade)
2907 status = ( CID_NFC_DNLD << BYTE_SIZE ) ;
2909 else if ( PHDNLD_NO_OPERATION
2910 != psDnldContext->raw_mode_upgrade)
2913 psDnldContext->raw_mode_upgrade =
2914 (psDnldContext->raw_mode_upgrade &
2915 ~( psDnldContext->cur_frame_info & ~PHDNLD_MARKER_MASK ));
2922 case PHDNLD_RESP_CMD_NOT_SUPPORTED:
2925 if ( PHDNLD_NO_OPERATION
2926 == psDnldContext->raw_mode_upgrade)
2928 status = PHNFCSTVAL(CID_NFC_DNLD,
2929 NFCSTATUS_FEATURE_NOT_SUPPORTED);
2931 else if ( PHDNLD_ADVANCED_OPERATION
2932 == psDnldContext->raw_mode_upgrade)
2934 status = PHNFCSTVAL(CID_NFC_DNLD,
2935 NFCSTATUS_FEATURE_NOT_SUPPORTED);
2938 else if( (PHDNLD_NORMAL_OPERATION
2939 & psDnldContext->raw_mode_upgrade)
2942 psDnldContext->raw_mode_upgrade =
2943 (psDnldContext->raw_mode_upgrade & ~PHDNLD_NORMAL_OPERATION);
2945 else if ( PHDNLD_SETUP_OPERATION
2946 & psDnldContext->raw_mode_upgrade )
2948 psDnldContext->raw_mode_upgrade =
2949 (psDnldContext->raw_mode_upgrade & ~PHDNLD_SETUP_OPERATION);
2954 psDnldContext->raw_mode_upgrade =
2955 (psDnldContext->raw_mode_upgrade &
2956 ~( psDnldContext->cur_frame_info & ~PHDNLD_MARKER_MASK ));
2960 /* The Chaining of the Command Frame
2961 was Successful in the Download Mode */
2962 case PHDNLD_RESP_CHAINING_SUCCESS:
2964 /* TODO: Handle the Corner Case Scenarios
2965 * the updated status */
2966 psDnldContext->dnld_retry = 0x00;
2969 /* The Error during the Chaining the Command Frame in the Download Mode */
2970 case PHDNLD_RESP_CHAINING_ERROR:
2972 /* TODO: Restart the Chunk in Corner Case
2973 * the updated status */
2974 psDnldContext->dnld_retry++;
2975 phDnldNfc_Tx_Reset(psDnldContext);
2978 /* The Command is not allowed anymore in the Download Mode */
2979 case PHDNLD_RESP_CMD_NOT_ALLOWED:
2982 psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
2983 status = PHNFCSTVAL(CID_NFC_DNLD,
2984 NFCSTATUS_NOT_ALLOWED);
2988 } /* End of the Response Frame Type Switch */
2990 if (NFCSTATUS_PENDING != status)
2992 if ((NFCSTATUS_SUCCESS != status) &&
2993 (psDnldContext->dnld_retry >= NXP_MAX_DNLD_RETRY))
2995 pphNfcIF_Notification_CB_t p_upper_notify =
2996 psDnldContext->p_upper_notify;
2997 void *p_upper_context =
2998 psDnldContext->p_upper_context;
3000 comp_info.status = status;
3001 DNLD_DEBUG(" FW_DNLD: Termination in Receive, Status = %X \n", status);
3002 status = phDal4Nfc_Unregister(
3003 psDnldContext->lower_interface.pcontext, pHwRef);
3004 phDnldNfc_Release_Lower(psDnldContext, pHwRef);
3005 phDnldNfc_Release_Resources(&psDnldContext);
3006 #ifndef NFC_TIMER_CONTEXT
3007 gpphDnldContext = psDnldContext;
3009 /* Notify the Error/Success Scenario to the upper layer */
3010 phDnldNfc_Notify( p_upper_notify, p_upper_context, pHwRef,
3011 (uint8_t) NFC_IO_ERROR, &comp_info );
3013 else if ( (NFCSTATUS_SUCCESS != status) &&
3014 (NFCSTATUS_SUCCESS == PHNFCSTATUS(status))
3017 pphNfcIF_Notification_CB_t p_upper_notify =
3018 psDnldContext->p_upper_notify;
3019 void *p_upper_context =
3020 psDnldContext->p_upper_context;
3022 comp_info.status = NFCSTATUS_SUCCESS;
3023 DNLD_DEBUG(" FW_DNLD: Termination in Receive, Status = %X \n", status);
3024 status = phDal4Nfc_Unregister(
3025 psDnldContext->lower_interface.pcontext, pHwRef);
3026 phDnldNfc_Release_Lower(psDnldContext, pHwRef);
3027 phDnldNfc_Release_Resources(&psDnldContext);
3028 #ifndef NFC_TIMER_CONTEXT
3029 gpphDnldContext = psDnldContext;
3031 /* Notify the Error/Success Scenario to the upper layer */
3032 phDnldNfc_Notify( p_upper_notify, p_upper_context, pHwRef,
3033 (uint8_t) NFC_IO_SUCCESS, &comp_info );
3036 else if (NFCSTATUS_FEATURE_NOT_SUPPORTED == PHNFCSTATUS(status))
3038 pphNfcIF_Notification_CB_t p_upper_notify =
3039 psDnldContext->p_upper_notify;
3040 void *p_upper_context =
3041 psDnldContext->p_upper_context;
3043 comp_info.status = status;
3044 DNLD_DEBUG(" FW_DNLD: Termination in Receive, Status = %X \n", status);
3045 status = phDal4Nfc_Unregister(
3046 psDnldContext->lower_interface.pcontext, pHwRef);
3047 phDnldNfc_Release_Lower(psDnldContext, pHwRef);
3048 phDnldNfc_Release_Resources(&psDnldContext);
3049 #ifndef NFC_TIMER_CONTEXT
3050 gpphDnldContext = psDnldContext;
3052 /* Notify the Error/Success Scenario to the upper layer */
3053 phDnldNfc_Notify( p_upper_notify, p_upper_context, pHwRef,
3054 (uint8_t) NFC_IO_SUCCESS, &comp_info );
3059 /* DNLD_PRINT(" FW_DNLD: Successful.\n"); */
3060 psDnldContext->resp_length = /* PHDNLD_MIN_PACKET */ 0 ;
3061 status = phDnldNfc_Set_Seq(psDnldContext,
3063 status = phDnldNfc_Resume( psDnldContext,
3064 pHwRef, pdata, length );
3067 } /* End of status != Success */
3074 phDnldNfc_Send_Complete (
3077 phNfc_sTransactionInfo_t *pInfo
3080 NFCSTATUS status = NFCSTATUS_SUCCESS ;
3081 uint16_t length = 0;
3083 DNLD_PRINT(" FW_DNLD: Send Data .... ");
3084 if ( (NULL != psContext)
3089 phDnldNfc_sContext_t *psDnldContext =
3090 (phDnldNfc_sContext_t *)psContext;
3091 status = pInfo->status ;
3092 length = pInfo->length ;
3093 if(status != NFCSTATUS_SUCCESS)
3095 DNLD_DEBUG(" Failed. Status = %02X\n",status);
3096 /* Handle the Error Scenario */
3100 DNLD_PRINT(" Successful.\n");
3101 (void)memset((void *)&psDnldContext->dnld_data, 0,
3102 sizeof(psDnldContext->dnld_data));
3103 if ((PHDNLD_CMD_SET_HIF != psDnldContext->prev_cmd)
3104 && (PHDNLD_CMD_RESET != psDnldContext->prev_cmd))
3106 psDnldContext->rx_info.rx_total = 0;
3107 status = phDnldNfc_Receive( psDnldContext, pHwRef,
3108 (uint8_t *)(&psDnldContext->dnld_resp),
3109 psDnldContext->resp_length);
3113 psDnldContext->resp_length = 0;
3114 psDnldContext->dnld_retry = 0;
3115 /* clock unstable after SW reset command, especially on UART
3116 * platform because of its sensitivity to clock. Experimentally
3117 * we found clock unstable for 750us. Delay for 5ms to be sure.
3119 if( PHDNLD_CMD_RESET == psDnldContext->prev_cmd )
3121 DO_DELAY(PHDNLD_DNLD_DELAY);
3123 #if defined(FW_DOWNLOAD_TIMER) && \
3124 (FW_DOWNLOAD_TIMER == 2)
3126 if ( NXP_INVALID_TIMER_ID != psDnldContext->timer_id )
3128 phOsalNfc_Timer_Stop( psDnldContext->timer_id );
3132 status = phDnldNfc_Set_Seq(psDnldContext,
3136 if(NFCSTATUS_SUCCESS == status )
3138 status = phDnldNfc_Resume( psDnldContext, pHwRef, NULL, length);
3141 } /* End of status != Success */
3143 } /* End of Context != NULL */
3150 phDnldNfc_Send_Command(
3151 phDnldNfc_sContext_t *psDnldContext,
3155 uint16_t param_length
3158 NFCSTATUS status = NFCSTATUS_SUCCESS;
3159 uint16_t tx_length = 0;
3160 uint16_t rx_length = 0;
3161 uint8_t **pp_resp_data = &psDnldContext->p_resp_buffer;
3162 phDnldNfc_sData_t *p_dnld_data =
3163 (phDnldNfc_sData_t *)psDnldContext->dnld_data;
3167 case PHDNLD_CMD_RESET:
3169 (void)memset((void *)&psDnldContext->dnld_data, 0,
3170 sizeof(psDnldContext->dnld_data));
3173 case PHDNLD_CMD_READ:
3175 phDnldNfc_sData_t *p_dnld_data =
3176 (phDnldNfc_sData_t *)psDnldContext->dnld_data;
3177 phDnldNfc_sParam_t *param_info = /* (phDnldNfc_sParam_t *)params */
3178 &p_dnld_data->param_info.data_param;
3179 tx_length = PHDNLD_CMD_READ_LEN;
3180 if (NULL != *pp_resp_data)
3182 phOsalNfc_FreeMemory(*pp_resp_data);
3183 *pp_resp_data = NULL;
3185 rx_length = (uint16_t) (((uint16_t)param_info->data_len[0]
3186 << BYTE_SIZE) + param_info->data_len[1]);
3188 psDnldContext->resp_length =
3189 (( rx_length + PHDNLD_MIN_PACKET ));
3190 (void)phDnldNfc_Allocate_Resource( (void **) pp_resp_data,
3194 case PHDNLD_CMD_WRITE:
3195 case PHDNLD_CMD_SEC_WRITE:
3197 phDnldNfc_sData_t *p_dnld_data =
3198 (phDnldNfc_sData_t *)psDnldContext->dnld_data;
3199 phDnldNfc_sParam_t *param_info = /* (phDnldNfc_sParam_t *)params */
3200 &p_dnld_data->param_info.data_param;
3201 tx_length = (uint16_t) (((uint16_t)param_info->data_len[0]
3202 << BYTE_SIZE) + param_info->data_len[1]
3203 + PHDNLD_CMD_WRITE_MIN_LEN );
3205 psDnldContext->resp_length = PHDNLD_MIN_PACKET;
3206 if ((0 != param_length) && (NULL != params))
3208 (void)memcpy(param_info->data_packet, params, param_length);
3212 case PHDNLD_CMD_CHECK:
3214 tx_length = PHDNLD_CMD_CHECK_LEN;
3215 psDnldContext->resp_length = PHDNLD_MIN_PACKET;
3218 case PHDNLD_CMD_ENCAPSULATE:
3221 if ((0 != param_length) && (NULL != params))
3223 p_dnld_data->frame_type =
3224 PHDNLD_CMD_ENCAPSULATE;
3225 (void)memcpy((void *)( ((uint8_t *)p_dnld_data)
3226 + PHDNLD_FRAME_DATA_OFFSET)
3227 , params, param_length);
3228 tx_length = param_length;
3230 p_dnld_data->frame_length[i++] =
3231 (uint8_t)(tx_length >> BYTE_SIZE);
3232 p_dnld_data->frame_length[i] =
3233 (uint8_t)( tx_length & BYTE_MASK );
3234 tx_length += PHDNLD_FRAME_DATA_OFFSET;
3236 psDnldContext->resp_length = PHDNLD_MIN_PACKET;
3238 status = phDnldNfc_Send( psDnldContext, pHwRef ,
3239 (uint8_t *)p_dnld_data, tx_length);
3243 status = PHNFCSTVAL(CID_NFC_DNLD,
3244 NFCSTATUS_NOT_ALLOWED);
3248 case PHDNLD_CMD_SET_HIF:
3251 psDnldContext->resp_length = PHDNLD_MIN_PACKET;
3254 case PHDNLD_CMD_ACTIVATE_PATCH:
3256 psDnldContext->resp_length = PHDNLD_MIN_PACKET;
3257 if ((NULL != params) && ( param_length > 0 ))
3259 p_dnld_data->param_info.cmd_param =
3260 (*(uint8_t *)params);
3261 tx_length = param_length;
3265 p_dnld_data->param_info.cmd_param = FALSE;
3270 case PHDNLD_CMD_CHECK_INTEGRITY:
3272 #if (NXP_FW_INTEGRITY_CHK >= 0x01)
3273 if ((NULL != params) && ( param_length > 0 ))
3275 psDnldContext->chk_integrity_param =
3276 (phDnldNfc_eChkCrc_t)(*(uint8_t *)params);
3277 tx_length = param_length;
3281 psDnldContext->chk_integrity_param = CHK_INTEGRITY_COMPLETE_CRC;
3284 p_dnld_data->param_info.cmd_param =
3285 (uint8_t) psDnldContext->chk_integrity_param;
3286 switch(psDnldContext->chk_integrity_param)
3288 case CHK_INTEGRITY_CONFIG_PAGE_CRC:
3289 case CHK_INTEGRITY_PATCH_TABLE_CRC:
3291 psDnldContext->resp_length = PHDNLD_MIN_PACKET
3292 + CHECK_INTEGRITY_RESP_CRC16_LEN;
3295 case CHK_INTEGRITY_FLASH_CODE_CRC:
3296 case CHK_INTEGRITY_PATCH_CODE_CRC:
3298 psDnldContext->resp_length = PHDNLD_MIN_PACKET
3299 + CHECK_INTEGRITY_RESP_CRC32_LEN;
3302 case CHK_INTEGRITY_COMPLETE_CRC:
3305 psDnldContext->resp_length = PHDNLD_MIN_PACKET
3306 + CHECK_INTEGRITY_RESP_COMP_LEN;
3312 p_dnld_data->param_info.cmd_param =
3313 (uint8_t) CHK_INTEGRITY_COMPLETE_CRC;
3315 #endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
3320 status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_FEATURE_NOT_SUPPORTED);
3324 if (NFCSTATUS_SUCCESS == status)
3328 p_dnld_data->frame_type = cmd;
3329 p_dnld_data->frame_length[i++] =
3330 (uint8_t)(tx_length >> BYTE_SIZE);
3331 p_dnld_data->frame_length[i] =
3332 (uint8_t)( tx_length & BYTE_MASK );
3333 tx_length = tx_length + PHDNLD_MIN_PACKET;
3334 status = phDnldNfc_Send( psDnldContext, pHwRef ,
3335 (uint8_t *)p_dnld_data, tx_length);
3336 if(NFCSTATUS_PENDING == status)
3338 psDnldContext->prev_cmd = cmd;
3340 if( PHDNLD_CMD_RESET == cmd )
3341 DO_DELAY(PHDNLD_DNLD_DELAY); //this seems like its on the wrong thread
3351 phHal_sHwReference_t *pHwRef,
3352 fw_data_hdr_t *cur_fw_hdr
3355 NFCSTATUS status = NFCSTATUS_FAILED;
3357 if ( !pHwRef->device_info.fw_version )
3359 /* Override the Firmware Version Check and upgrade*/;
3360 DNLD_PRINT(" FW_DNLD_CHK: Forceful Upgrade of the Firmware .... Required \n");
3361 status = NFCSTATUS_SUCCESS;
3363 else if ( (pHwRef->device_info.fw_version >> (BYTE_SIZE * 2))
3364 != ( cur_fw_hdr->fw_version >> (BYTE_SIZE * 2) ))
3366 /* Check for the Compatible Romlib Version for the Hardware */
3367 DNLD_PRINT(" FW_DNLD: IC Hardware Version Mismatch.. \n");
3368 status = PHNFCSTVAL( CID_NFC_DNLD, NFCSTATUS_NOT_ALLOWED );
3370 else if (( pHwRef->device_info.fw_version < cur_fw_hdr->fw_version )
3373 /* TODO: Firmware Version Check and upgrade*/
3374 DNLD_PRINT(" FW_DNLD: Older Firmware Upgrading to newerone.... \n");
3375 status = NFCSTATUS_SUCCESS;
3377 #ifdef NXP_FW_CHK_LATEST
3378 else if (( pHwRef->device_info.fw_version > cur_fw_hdr->fw_version )
3381 DNLD_PRINT(" FW_DNLD: Newer than the Stored One .... \n");
3382 status = PHNFCSTVAL( CID_NFC_DNLD, NFCSTATUS_NOT_ALLOWED );
3384 #endif /* NXP_FW_CHK_LATEST */
3387 DNLD_PRINT(" FW_DNLD: Already Updated .... \n");
3388 status = ( CID_NFC_DNLD << BYTE_SIZE ) ;
3397 phDnldNfc_Process_FW(
3398 phDnldNfc_sContext_t *psDnldContext,
3399 phHal_sHwReference_t *pHwRef
3401 ,uint8_t *nxp_nfc_fw
3402 ,uint32_t nxp_fw_len
3406 NFCSTATUS status = NFCSTATUS_FAILED;
3407 section_info_t *p_cur_sec = NULL;
3408 static unsigned sec_type;
3409 uint32_t fw_index = 0;
3410 #ifdef NXP_NFC_MULTIPLE_FW
3411 phDnldNfc_sFwImageInfo_t *p_cur_fw = NULL;
3412 #endif /* #ifdef NXP_NFC_MULTIPLE_FW */
3413 fw_data_hdr_t *cur_fw_hdr = NULL;
3414 uint8_t sec_index = 0;
3417 psDnldContext->p_img_hdr = (img_data_hdr_t *) nxp_nfc_fw;
3419 #ifdef NXP_NFC_MULTIPLE_FW
3421 /* TODO: Create a memory of pointers to store all the Firmwares */
3422 if( (NXP_NFC_IMAG_FW_MAX > psDnldContext->p_img_hdr->no_of_fw_img)
3423 && (0 != psDnldContext->p_img_hdr->no_of_fw_img)
3426 ( void )phDnldNfc_Allocate_Resource((void **)&psDnldContext->p_img_info,
3427 (psDnldContext->p_img_hdr->no_of_fw_img * sizeof(phDnldNfc_sFwImageInfo_t)));
3429 if(NULL != psDnldContext->p_img_info)
3431 p_cur_fw = psDnldContext->p_img_info;
3434 #endif /* #ifdef NXP_NFC_MULTIPLE_FW */
3436 fw_index = sizeof (img_data_hdr_t);
3438 for ( i=0; i < psDnldContext->p_img_hdr->no_of_fw_img; i++ )
3441 psDnldContext->p_fw_hdr = (fw_data_hdr_t *) ( nxp_nfc_fw + fw_index );
3443 #ifdef NXP_NFC_MULTIPLE_FW
3444 if(NULL != p_cur_fw)
3446 ( p_cur_fw + i)->p_fw_hdr = psDnldContext->p_fw_hdr;
3448 #endif /* #ifdef NXP_NFC_MULTIPLE_FW */
3449 cur_fw_hdr = psDnldContext->p_fw_hdr;
3451 fw_index = fw_index + (cur_fw_hdr->fw_hdr_len * PNDNLD_WORD_LEN);
3453 status = phDnldNfc_Check_FW( pHwRef, cur_fw_hdr);
3457 if ( ( NFCSTATUS_SUCCESS == status )
3458 #if defined (NXP_FW_INTEGRITY_VERIFY)
3459 || (NFCSTATUS_SUCCESS == PHNFCSTATUS(status) )
3460 #endif /* !defined (NXP_FW_INTEGRITY_VERIFY) */
3463 if( (BYTE_MASK > cur_fw_hdr->no_of_sections)
3464 && (0 != cur_fw_hdr->no_of_sections)
3467 (void) phDnldNfc_Allocate_Resource((void **)&psDnldContext->p_fw_sec,
3468 (cur_fw_hdr->no_of_sections * sizeof(section_info_t)));
3470 if(NULL != psDnldContext->p_fw_sec)
3472 DNLD_DEBUG(" FW_DNLD: FW Index : %x \n",
3475 DNLD_DEBUG(" FW_DNLD: No of Sections : %x \n\n",
3476 cur_fw_hdr->no_of_sections);
3478 for(sec_index = 0; sec_index
3479 < cur_fw_hdr->no_of_sections; sec_index++ )
3481 p_cur_sec = ((section_info_t *)
3482 (psDnldContext->p_fw_sec + sec_index ));
3484 p_cur_sec->p_sec_hdr = (section_hdr_t *)
3485 (nxp_nfc_fw + fw_index);
3487 DNLD_DEBUG(" FW_DNLD: Section %x \n", sec_index);
3488 DNLD_DEBUG(" FW_DNLD: Section Header Len : %x ",
3489 p_cur_sec->p_sec_hdr->section_hdr_len);
3490 DNLD_DEBUG(" Section Address : %x ",
3491 p_cur_sec->p_sec_hdr->section_address);
3492 DNLD_DEBUG(" Section Length : %x ",
3493 p_cur_sec->p_sec_hdr->section_length);
3494 DNLD_DEBUG(" Section Memory Type : %x \n",
3495 p_cur_sec->p_sec_hdr->section_mem_type);
3497 sec_type = (unsigned int)p_cur_sec->p_sec_hdr->section_mem_type;
3499 if((sec_type & DNLD_TRIM_MASK))
3501 p_cur_sec->p_trim_data = (uint8_t *)
3502 (nxp_nfc_fw + fw_index + sizeof(section_hdr_t));
3506 p_cur_sec->p_trim_data = NULL;
3511 if ((sec_type & DNLD_SM_UNLOCK_MASK))
3513 (void)phDnldNfc_Set_Seq(psDnldContext,
3518 (void)phDnldNfc_Set_Seq(psDnldContext,
3522 p_cur_sec->section_read = FALSE;
3524 p_cur_sec->section_offset = 0;
3526 p_cur_sec->p_sec_data = ((uint8_t *) nxp_nfc_fw) + fw_index +
3527 (p_cur_sec->p_sec_hdr->section_hdr_len * PNDNLD_WORD_LEN);
3529 fw_index = fw_index +
3530 (p_cur_sec->p_sec_hdr->section_hdr_len * PNDNLD_WORD_LEN)
3531 + p_cur_sec->p_sec_hdr->section_length;
3534 if( 0 != p_cur_sec->p_sec_hdr->section_checksum )
3536 DNLD_DEBUG(" FW_DNLD: Section checksum : %x \n",
3537 p_cur_sec->p_sec_hdr->section_checksum );
3539 p_cur_sec->p_sec_chksum = ( uint8_t *)(nxp_nfc_fw + fw_index);
3541 fw_index = fw_index +
3542 p_cur_sec->p_sec_hdr->section_checksum;
3545 DNLD_DEBUG(" FW_DNLD: FW Index : %x \n", fw_index );
3547 #if (NXP_FW_INTEGRITY_CHK >= 0x01)
3548 switch( p_cur_sec->p_sec_hdr->section_address )
3550 case DNLD_FW_CODE_ADDR:
3552 psDnldContext->p_flash_code_crc =
3553 p_cur_sec->p_sec_data
3554 + p_cur_sec->p_sec_hdr->section_length
3558 case DNLD_PATCH_CODE_ADDR:
3560 psDnldContext->p_patch_code_crc =
3561 p_cur_sec->p_sec_data
3562 + p_cur_sec->p_sec_hdr->section_length
3566 case DNLD_PATCH_TABLE_ADDR:
3568 psDnldContext->p_patch_table_crc =
3569 p_cur_sec->p_sec_data
3570 + p_cur_sec->p_sec_hdr->section_length
3579 } /* End of Address Switch */
3580 #endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
3581 } /* End of For Loop */
3582 } /* End of the Null Check */
3585 status = PHNFCSTVAL(CID_NFC_DNLD,
3586 NFCSTATUS_INSUFFICIENT_RESOURCES);
3591 (0 == cur_fw_hdr->no_of_sections)
3592 && (PHDNLD_FW_PATCH_SEC == cur_fw_hdr->fw_patch)
3595 psDnldContext->p_fw_raw = (uint8_t *)(nxp_nfc_fw + fw_index);
3597 psDnldContext->raw_mode_upgrade = PHDNLD_COMPLETE_OPERATION;
3599 (void)phDnldNfc_Set_Seq(psDnldContext,
3604 DNLD_PRINT("********* Empty Section and Firmware ******************\n\n");
3607 DNLD_PRINT("*******************************************\n\n");
3613 #if !defined (NXP_FW_INTEGRITY_VERIFY)
3616 phDnldNfc_Run_Check(
3617 phHal_sHwReference_t *pHwRef
3619 ,uint8_t *nxp_nfc_fw
3624 NFCSTATUS status = NFCSTATUS_FAILED;
3625 uint32_t fw_index = 0;
3626 img_data_hdr_t *p_img_hdr = NULL;
3627 fw_data_hdr_t *p_fw_hdr = NULL;
3628 fw_data_hdr_t *cur_fw_hdr = NULL;
3631 p_img_hdr = (img_data_hdr_t *) nxp_nfc_fw;
3633 fw_index = sizeof (img_data_hdr_t);
3635 for ( i=0; i < p_img_hdr->no_of_fw_img; i++ )
3637 p_fw_hdr = (fw_data_hdr_t *) ( nxp_nfc_fw + fw_index );
3638 /* TODO: Create a memory of pointers to store all the Firmwares */
3639 cur_fw_hdr = p_fw_hdr;
3641 fw_index = fw_index + (cur_fw_hdr->fw_hdr_len * PNDNLD_WORD_LEN);
3643 status = phDnldNfc_Check_FW( pHwRef, cur_fw_hdr);
3648 #endif /* #if !defined (NXP_FW_INTEGRITY_VERIFY) */
3655 #ifdef NFC_TIMER_CONTEXT
3661 phNfc_sCompletionInfo_t comp_info = {0,0,0};
3663 phDnldNfc_sContext_t *p_dnld_context = NULL;
3665 #ifdef NFC_TIMER_CONTEXT
3666 p_dnld_context = (phDnldNfc_sContext_t *)dnld_cntxt;
3668 p_dnld_context = gpphDnldContext;
3671 if ( ( NULL != p_dnld_context)
3672 && (abort_id == p_dnld_context->timer_id ))
3674 pphNfcIF_Notification_CB_t p_upper_notify =
3675 p_dnld_context->p_upper_notify;
3676 void *p_upper_context =
3677 p_dnld_context->p_upper_context;
3678 phHal_sHwReference_t *pHwRef = p_dnld_context->p_hw_ref;
3680 (void)phDal4Nfc_Unregister(
3681 p_dnld_context->lower_interface.pcontext, pHwRef );
3682 phDnldNfc_Release_Lower(p_dnld_context, pHwRef);
3683 phDnldNfc_Release_Resources(&p_dnld_context);
3684 #ifndef NFC_TIMER_CONTEXT
3685 gpphDnldContext = p_dnld_context;
3688 /* Notify the Error/Success Scenario to the upper layer */
3689 DNLD_DEBUG(" FW_DNLD: FW_DNLD Aborted with %x Timer Timeout \n",
3691 comp_info.status = NFCSTATUS_FAILED ;
3692 phDnldNfc_Notify( p_upper_notify, p_upper_context,
3693 pHwRef, (uint8_t) NFC_IO_ERROR, &comp_info );
3703 phHal_sHwReference_t *pHwRef,
3706 uint8_t *nxp_nfc_fw,
3709 pphNfcIF_Notification_CB_t upgrade_complete,
3713 phDnldNfc_sContext_t *psDnldContext = NULL;
3714 phNfcIF_sReference_t dnldReference = { NULL,0,0 };
3715 phNfcIF_sCallBack_t if_callback = { NULL, NULL, NULL, NULL };
3716 phNfc_sLowerIF_t *plower_if = NULL;
3717 NFCSTATUS status = NFCSTATUS_SUCCESS;
3718 section_info_t *p_cur_sec = NULL;
3719 unsigned sec_type = 0;
3721 if( (NULL == pHwRef)
3724 status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
3728 DNLD_PRINT(" FW_DNLD: Starting the FW Upgrade Sequence .... \n");
3731 phDnldNfc_Allocate_Resource((void **)
3732 &psDnldContext,sizeof(phDnldNfc_sContext_t));
3733 if(psDnldContext != NULL)
3735 #ifndef NFC_TIMER_CONTEXT
3736 gpphDnldContext = psDnldContext;
3738 psDnldContext->p_hw_ref = pHwRef;
3739 psDnldContext->timer_id = NXP_INVALID_TIMER_ID;
3741 DNLD_PRINT(" FW_DNLD: Initialisation in Progress.... \n");
3743 if_callback.pif_ctxt = psDnldContext ;
3744 if_callback.send_complete = &phDnldNfc_Send_Complete;
3745 if_callback.receive_complete= &phDnldNfc_Receive_Complete;
3746 /* if_callback.notify = &phDnldNfc_Notify_Event; */
3747 plower_if = dnldReference.plower_if = &(psDnldContext->lower_interface);
3748 status = phDal4Nfc_Register(&dnldReference, if_callback,
3750 DNLD_DEBUG(" FW_DNLD: Lower Layer Register, Status = %02X\n",status);
3752 if( (NFCSTATUS_SUCCESS == status) && (NULL != plower_if->init))
3754 /* psDnldContext->p_config_params = pHwConfig ; */
3755 status = plower_if->init((void *)plower_if->pcontext,
3757 DNLD_DEBUG(" FW_DNLD: Lower Layer Initialisation, Status = %02X\n",status);
3761 /* TODO: Handle Initialisation in the Invalid State */
3763 /* The Lower layer Initialisation successful */
3764 if (NFCSTATUS_SUCCESS == status)
3766 psDnldContext->p_upper_notify = upgrade_complete;
3767 psDnldContext->p_upper_context = context;
3769 status = phDnldNfc_Process_FW( psDnldContext, pHwRef
3771 ,*nxp_nfc_fw , fw_length
3775 if (NFCSTATUS_SUCCESS == status)
3777 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
3778 PHDNLD_CMD_RESET , NULL , 0 );
3779 if (NFCSTATUS_PENDING == status)
3781 DNLD_PRINT("\n FW_DNLD: Initial Reset .... \n");
3783 #if defined(FW_DOWNLOAD_TIMER)
3785 psDnldContext->timer_id = phOsalNfc_Timer_Create( );
3787 #if (FW_DOWNLOAD_TIMER < 2)
3788 phOsalNfc_Timer_Start( psDnldContext->timer_id,
3789 NXP_DNLD_COMPLETE_TIMEOUT,
3790 (ppCallBck_t) phDnldNfc_Abort
3791 #ifdef NFC_TIMER_CONTEXT
3792 , (void *) psDnldContext
3796 #endif /* #if (FW_DOWNLOAD_TIMER < 2) */
3798 #endif /* #if defined(FW_DOWNLOAD_TIMER) */
3802 else if (NFCSTATUS_SUCCESS == PHNFCSTATUS(status))
3804 #if defined (NXP_FW_INTEGRITY_VERIFY)
3806 * To check for the integrity if the firmware is already
3809 status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
3810 PHDNLD_CMD_RESET , NULL , 0 );
3811 if (NFCSTATUS_PENDING == status)
3813 DNLD_PRINT("\n FW_DNLD: Integrity Reset .... \n");
3814 (void)phDnldNfc_Set_Seq(psDnldContext, DNLD_SEQ_COMPLETE);
3815 status = PHNFCSTVAL( CID_NFC_DNLD,
3816 NFCSTATUS_PENDING );
3817 #if defined(FW_DOWNLOAD_TIMER)
3818 psDnldContext->timer_id = phOsalNfc_Timer_Create( );
3819 #if (FW_DOWNLOAD_TIMER < 2)
3820 phOsalNfc_Timer_Start( psDnldContext->timer_id,
3821 NXP_DNLD_COMPLETE_TIMEOUT,
3822 (ppCallBck_t) phDnldNfc_Abort
3823 #ifdef NFC_TIMER_CONTEXT
3824 , (void *) psDnldContext
3828 #endif /* #if (FW_DOWNLOAD_TIMER < 2) */
3830 #endif /* #if defined(FW_DOWNLOAD_TIMER) */
3834 status = NFCSTATUS_SUCCESS;
3836 #endif /* #if defined (NXP_FW_INTEGRITY_VERIFY) */
3841 DNLD_PRINT(" FW_DNLD Initialisation in Failed \n");
3845 if (NFCSTATUS_PENDING != PHNFCSTATUS(status))
3847 (void)phDal4Nfc_Unregister(
3848 psDnldContext->lower_interface.pcontext, pHwRef);
3849 phDnldNfc_Release_Lower(psDnldContext, pHwRef);
3850 phDnldNfc_Release_Resources(&psDnldContext);
3851 #ifndef NFC_TIMER_CONTEXT
3852 gpphDnldContext = psDnldContext;
3855 } /* End of Status Check for Memory */
3858 status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INSUFFICIENT_RESOURCES);
3860 DNLD_PRINT(" FW_DNLD: Memory Allocation of Context Failed\n");