| /****************************************************************************** |
| ** |
| ** INTEL CONFIDENTIAL |
| ** Copyright 2003-2004 Intel Corporation All Rights Reserved. |
| ** |
| ** The source code contained or described herein and all documents |
| ** related to the source code (Material) are owned by Intel Corporation |
| ** or its suppliers or licensors. Title to the Material remains with |
| ** Intel Corporation or its suppliers and licensors. The Material contains |
| ** trade secrets and proprietary and confidential information of Intel |
| ** or its suppliers and licensors. The Material is protected by worldwide |
| ** copyright and trade secret laws and treaty provisions. No part of the |
| ** Material may be used, copied, reproduced, modified, published, uploaded, |
| ** posted, transmitted, distributed, or disclosed in any way without Intel's |
| ** prior express written permission. |
| ** |
| ** No license under any patent, copyright, trade secret or other intellectual |
| ** property right is granted to or conferred upon you by disclosure or |
| ** delivery of the Materials, either expressly, by implication, inducement, |
| ** estoppel or otherwise. Any license under such intellectual property rights |
| ** must be express and approved by Intel in writing. |
| ** |
| ** ProtocolManager.h |
| ******************************************************************************//****************************************************************************** |
| * |
| * (C)Copyright 2005 - 2011 Marvell. All Rights Reserved. |
| * |
| * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MARVELL. |
| * The copyright notice above does not evidence any actual or intended |
| * publication of such source code. |
| * This Module contains Proprietary Information of Marvell and should be |
| * treated as Confidential. |
| * The information in this file is provided for the exclusive use of the |
| * licensees of Marvell. |
| * Such users have the right to use, modify, and incorporate this code into |
| * products for purposes authorized by the license agreement provided they |
| * include this notice and the associated copyright notice with any such |
| * product. |
| * The information in this file is provided "AS IS" without warranty. |
| * |
| ******************************************************************************/ |
| |
| /****************************************************************************** |
| ** |
| ** FILENAME: ProtocolManager.h |
| ** |
| ** PURPOSE: This module manages the boot ROM protocol used for communication |
| ** over the UART or USB ports |
| ** |
| ** |
| ******************************************************************************/ |
| #ifndef _protocol_manager_h |
| #define _protocol_manager_h |
| |
| #include "Typedef.h" |
| #include "Flash.h" |
| #include "general.h" |
| #include "loadoffsets.h" |
| #include "usbapi.h" |
| |
| #define VERSION_OFFSET 0x24 |
| /********************* Image Types ***********************************/ |
| #define FIRSTIMAGE 1 |
| |
| /************* Commands definitions **********************************/ |
| |
| //ErrorCodes for Host Application |
| #define Ack 0x00 |
| #define Nack 0x01 |
| #define SeqError 0x02 |
| #define JtagAccessGranted 0x11 |
| #define JtagAccessDenied 0xFF |
| #define JtagREIssued 0x05 |
| #define DebugCmdIssued 0x06 |
| #define DebugBootIssued 0x07 |
| #define Untested 0x02 |
| #define InvalidParameterError 0x08 |
| |
| //Status Flags |
| #define MESSAGE_FLAG BIT0 |
| #define FAST_DOWNLOAD BIT2 |
| #define UUID_FLAG BIT3 |
| |
| //Commands |
| #define INVALIDCMD 0x00 |
| #define GetVersionCmd 0x20 |
| #define StartAddrCmd 0x21 |
| #define DownloadDataCmd 0x22 |
| #define JumpAddrCmd 0x23 |
| #define OEMPublicKeyCmd 0x24 |
| #define OEMSignedKeyCmd 0x25 |
| #define SelectImageCmd 0x26 |
| #define VerifyImageCmd 0x27 |
| #define PasswordCmd 0x28 |
| #define DataHeaderCmd 0x2a |
| #define MessageCmd 0x2b |
| #define ViewOTPCmd 0x2c |
| #define DebugBootCmd 0x2d |
| #define DoneCmd 0x30 |
| #define DisconnectCmd 0x31 |
| #define UploadDataHeaderCmd 0x32 |
| #define UploadDataCmd 0x33 |
| #define ProtocolVersionCmd 0x34 |
| #define GetParametersCmd 0x35 |
| #define JtagOverMediaCmd 0x36 |
| #define GetBadBlockCmd 0x37 |
| #define GetImageCrcCmd 0x38 |
| |
| #define PROTOCOL_WAITTIME 0x80 // in seconds, max time to wait for command |
| //Max time to wait between a PREAMBLE and GETVERSION (triggering a download) |
| #define PM_DL_STARTTIME_MS 0x10000 // update to 0x10000 instead of 0x80 to support multi FBFs download |
| |
| // 0x10000ms might be not enough for SWDConsole to download FBF, |
| // enlarge it to 0x40000ms |
| #define PM_DL_IMAGE_MS 0x40000 //Max time to wait for a single image to be downloaded |
| #define PM_DISCONNET_MS 0x20 //Max time to wait for the disconnect command to appear |
| |
| #define DATA_BLOCK_SIZE 0x3f8 //block size + sizeof(ProtocolCmd) must be word aligned |
| #define FD_BLOCK_SIZE 0x4000 //Fast download block size |
| #define UPLOAD_BLOCK_SIZE 0x1FFA // Upload block size. 6 bytes short of USB FIFO size for Status portion, |
| #define LENGTHOFMESSAGES 0x40 |
| #define MAXNUMOFMESSAGES 0x40 |
| #define PREAMBLE_SIZE 0x4 |
| #define COMMAND_SIZE 0x8 |
| |
| #define COMMAND_DATALENGTH 0x10 // Maximum command data size |
| |
| //Communication Protocol Version |
| #define COMM_PROTOCOL_MAJOR_VERSION 0x1 |
| #define COMM_PROTOCOL_MINOR_VERSION 0x1 |
| #define COMM_PROTOCOL_REV_VERSION 0x0 |
| |
| //Communication Protocol Parameters |
| #define COMM_PROTOCOL_BUFFER_SIZE 0x2000 |
| // 3 more reserved parameters |
| |
| // Upload Cmd Data Source Types |
| #define UPLOAD_FLASH 0x0 |
| #define UPLOAD_DDR 0x1 |
| |
| //#pragma pack (8) |
| |
| //Download ISR information |
| typedef struct |
| { |
| volatile UINT8_T PreambleReceived; |
| volatile UINT8_T CommandReceived; |
| volatile UINT8_T DisconnectReceived; |
| volatile UINT8_T DownloadsEnabled; |
| volatile UINT8_T FastDLInProgress; |
| volatile UINT8_T DLWaiting; |
| volatile UINT32_T DataLeft; |
| volatile UINT32_T CurrentTransferAddress; |
| volatile UINT32_T MaxImageSize; |
| volatile UINT32_T ErrorCode; |
| UINT32_T CurrentImageID; |
| P_USBAPI_T plinkedUSB; |
| } ProtocolISR, *pProtocolISR; |
| |
| typedef struct { |
| volatile UINT8_T Command; |
| volatile UINT8_T Sequence; |
| volatile UINT8_T CID; |
| volatile UINT8_T Flags; |
| volatile UINT32_T Length; |
| volatile UINT8_T Data[COMMAND_DATALENGTH]; |
| } ProtocolCmd, *pProtocolCmd; |
| |
| typedef struct { |
| UINT8_T Command; |
| UINT8_T Sequence; |
| UINT8_T CID; |
| UINT8_T Status; |
| UINT8_T Flags; |
| UINT8_T Length; |
| UINT8_T Data[32]; |
| } ProtocolRsp, *pProtocolRsp; |
| |
| #define REPORT_LENGTH 4 |
| |
| #define REPORT_NOTIFICATION 0 |
| #define REPORT_ERROR 1 |
| #define REPORT_BURNT_IMAGE_LENGTH 2 |
| #define REPORT_UPLOAD_NOTIFICATION 3 |
| #define REPORT_FLASH_SIZE_NOTIFICATION 4 |
| #define REPORT_EXTENDED_FUSE_INFO 5 |
| #define REPORT_EXTENDED2_FUSE_INFO 6 |
| |
| typedef struct { |
| volatile UINT8_T ReportType; // indicate an error (1) or a notification (0) or others |
| volatile UINT8_T Reserved; |
| volatile UINT8_T ReportCode[REPORT_LENGTH]; |
| } MessageReport, *pMessageReport; |
| |
| typedef enum |
| { |
| NonTrustedBoot1 = 0x00000000, |
| NonTrustedBoot2 = 0x00000001, |
| TrustedBoot = 0x00000002, |
| TamperBoot = 0x00000003 // BootROM will not boot device, so, OBM can't detect such mode. |
| }BootROM_Operation_Mode; |
| |
| typedef struct |
| { |
| UINT_T ChipID : 16; // 0x1188 |
| UINT_T RevisionID : 8; // 0xB0 |
| UINT_T Reserved : 8; |
| }ChipIDInfo; |
| |
| // extended message data |
| typedef struct { |
| volatile UINT_T OEMKeyHash[8]; // fixed length: 256bits |
| volatile UINT_T DeviceUID[2]; // fixed length: 64bits |
| volatile BootROM_Operation_Mode BRMode; |
| volatile UINT_T MMCSerialNumber; // fixed length: 32bits |
| volatile UINT_T ID; // ChipIDInfo |
| } ExMessageData, *pExMessageData; |
| |
| // extended message data |
| typedef struct { |
| // first message |
| volatile UINT_T OEMKeyHash[8]; // fixed length: 256bits |
| volatile UINT_T DeviceUID[2]; // fixed length: 64bits |
| volatile BootROM_Operation_Mode BRMode; |
| volatile UINT_T ID; // ChipIDInfo |
| // second message |
| volatile UINT_T CID[4]; // fixed lenght: 128bits |
| volatile UINT_T reserved0; // make struct align |
| volatile UINT_T reserved1; // make struct align |
| volatile UINT_T eMMCSize; // MB |
| volatile UINT_T DDRSize; // MB |
| } Ex2MessageData, *pEx2MessageData; |
| |
| // extended message report |
| typedef struct { |
| volatile UINT8_T ReportType; |
| volatile UINT8_T ReportLength; |
| volatile UINT8_T TotalNumber; |
| volatile UINT8_T Index; |
| volatile ExMessageData ReportData; |
| } ExMessageReport, *pExMessageReport; |
| |
| // extended message report |
| typedef struct { |
| volatile UINT8_T ReportType; |
| volatile UINT8_T ReportLength; |
| volatile UINT8_T TotalNumber; |
| volatile UINT8_T Index; |
| volatile Ex2MessageData ReportData; |
| } Ex2MessageReport, *pEx2MessageReport; |
| |
| typedef struct { |
| VUINT_T MessageFlag; |
| volatile UINT8_T Messages[MAXNUMOFMESSAGES][LENGTHOFMESSAGES]; |
| volatile UINT8_T Lengths[MAXNUMOFMESSAGES]; |
| volatile UINT8_T MessageType[MAXNUMOFMESSAGES]; |
| UINT8_T CurrentMessageIndex; |
| volatile UINT8_T NumMessagesQueued; |
| } ProtocolMsg, *pProtocolMsg; |
| |
| /* |
| * Upload Data structures |
| * UploadDataParams; To select data source, address and size |
| * ProtocolParams ; To select buffer size etc. This is meant |
| * ; to be general for the protocol. But currently |
| * ; only used for Upload Data. |
| */ |
| typedef struct { |
| UINT8_T Type; |
| UINT8_T SubType; |
| UINT8_T Partition; |
| UINT8_T Times; // indicate how many times SWD want to do upload |
| UINT_T Offset; |
| UINT_T DataSize; |
| UINT8_T IncludeOOB : 1; |
| UINT8_T UploadBypassBBT : 1; |
| UINT8_T DisableECC : 1; |
| UINT8_T Reserved : 5; |
| UINT8_T ResetUE; // indicate whether reset UE or not |
| UINT8_T ResetTimeDelay; // indicate the delay time before resetting UE |
| UINT8_T Reserved2; //used as emmc high address if its size exceeds 4GB |
| } UploadDataParameters, *pUploadDataParameters; |
| |
| typedef struct |
| { |
| UINT_T BufferSize; |
| UINT_T Rsvd1; |
| UINT_T Rsvd2; |
| UINT_T Rsvd3; |
| } ProtocolParams, *pProtocolParams; |
| |
| typedef struct |
| { |
| UINT8_T MajorVersion; |
| UINT8_T MinorVersion; |
| UINT16_T RevisionVersion; |
| } ProtocolVersion, *pProtocolVersion; |
| |
| |
| typedef struct { |
| UINT8_T FFUART_Init; |
| UINT8_T ALTUART_Init; |
| UINT8_T CI2_USB_Init; |
| } PortStates, *pPortStates; |
| |
| typedef struct |
| { |
| UINT32 ImageID; |
| UINT32 BadCnt; |
| }ImageBBInfo; |
| |
| // Badblock data |
| typedef struct { |
| UINT32 TotalBadBlocks; |
| UINT32 TotalBlocks; |
| ImageBBInfo BadCount[8]; //reserved for critical partitions support |
| } BadBlockData, *pBadBlockData; |
| |
| #define CRC_MAX_IMAGE_NUM 32 |
| |
| typedef struct |
| { |
| UINT32 ImageID; |
| UINT32 CRC32; |
| }CRCInfo; |
| |
| // Image CRC data |
| typedef struct |
| { |
| UINT32 MCPID; |
| UINT32 ImageNum; |
| CRCInfo ImageCRC[CRC_MAX_IMAGE_NUM]; |
| }ImageCRCInfo, *pImageCRCInfo; |
| |
| //#pragma pack () |
| |
| //Prototype Definitions |
| pProtocolISR getProtocolISR(void); |
| pProtocolCmd getProtocolCmd(void); |
| pProtocolCmd setProtocolCmd(void *addr); |
| pProtocolRsp getProtocolRsp(void); |
| pProtocolMsg getProtocolMsg(void); |
| void setProtocolError(UINT8_T Error); |
| UINT8_T getProtocolError(void); |
| UCHAR * getProtoBuff(void); |
| void setProtoBuff(UCHAR* pAddr); |
| void resetProtoBuff(void); |
| UINT PreambleReceived(void); |
| void ClearPreambleReceived(void); |
| unsigned int ImageDownloadWaiting(unsigned int media_num); |
| |
| //Reply routines |
| UINT_T SendResponse(UINT8_T *pAckBuff, UINT_T size); |
| UINT_T SendAck(void); |
| UINT_T SendError(UINT_T ErrorCode); |
| |
| //Individual Commmand handler |
| UINT_T HandleGetVersionCmd(void); |
| UINT_T HandleSelectImageCmd(UINT_T imageType); |
| UINT_T HandleVerifyImageCmd(void); |
| UINT_T HandleDataHeaderCmd(void); |
| UINT_T HandleDataCmd(void); |
| UINT_T HandleDoneCmd(void); |
| UINT_T HandleMessageCmd(void); |
| UINT_T HandleDisconnect(void); |
| |
| //Routines that interact with upper level |
| UINT_T InitPort(UINT_T port); |
| void ShutdownPorts (); |
| UINT_T PM_ReceiveImage(UINT_T dummy, UINT_T address, UINT_T size, UINT_T image_id); |
| |
| //Interrupt routines that work with USB drivers |
| void PM_ISR(P_USBAPI_T this, UINT bytes, UINT * buffer); |
| UINT PM_Handler(UINT packetLength); |
| |
| //routines for uploads |
| UINT_T GetUploadCommand(void); |
| UINT_T HandleUploadFlow(UINT_T address); |
| UINT_T HandleUploadDataHeaderCmd(void); |
| UINT_T HandleUploadDataCmd(void); |
| UINT_T CopyUploadDataIntoBuffer(UINT_T address, pUploadDataParameters pUploadParams); |
| UINT_T VerifyUploadParameters(pUploadDataParameters pUploadParams); |
| UINT_T HandleProtocolVersionCmd(void); |
| UINT_T HandleGetParametersCmd(void); |
| UINT_T HandleGetCrcCmd(); |
| UINT_T HandleGetBadBlock(); |
| |
| //message routines |
| UINT_T AddMessageError(UINT_T ReportType, UINT_T ReportCode); |
| UINT_T AddMessageCompound(UINT8_T* message, UINT number); |
| |
| //others |
| UINT_T HandleRequest(UINT_T src_addr, UINT_T dest_addr, UINT_T max_size, UINT_T image_id); |
| UINT8_T PM_VerifyPreamble( UINT8_T *candidateString ) ; |
| UINT8_T CheckProtocolTimeOut(UINT_T StartTime); |
| |
| #endif |
| |