blob: a23be4e968ad97fe7e683b8f53c9bf61d3d3c0a1 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/******************************************************************************
2**
3** INTEL CONFIDENTIAL
4** Copyright 2003-2004 Intel Corporation All Rights Reserved.
5**
6** The source code contained or described herein and all documents
7** related to the source code (Material) are owned by Intel Corporation
8** or its suppliers or licensors. Title to the Material remains with
9** Intel Corporation or its suppliers and licensors. The Material contains
10** trade secrets and proprietary and confidential information of Intel
11** or its suppliers and licensors. The Material is protected by worldwide
12** copyright and trade secret laws and treaty provisions. No part of the
13** Material may be used, copied, reproduced, modified, published, uploaded,
14** posted, transmitted, distributed, or disclosed in any way without Intel's
15** prior express written permission.
16**
17** No license under any patent, copyright, trade secret or other intellectual
18** property right is granted to or conferred upon you by disclosure or
19** delivery of the Materials, either expressly, by implication, inducement,
20** estoppel or otherwise. Any license under such intellectual property rights
21** must be express and approved by Intel in writing.
22**
23** ProtocolManager.h
24******************************************************************************//******************************************************************************
25 *
26 * (C)Copyright 2005 - 2011 Marvell. All Rights Reserved.
27 *
28 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MARVELL.
29 * The copyright notice above does not evidence any actual or intended
30 * publication of such source code.
31 * This Module contains Proprietary Information of Marvell and should be
32 * treated as Confidential.
33 * The information in this file is provided for the exclusive use of the
34 * licensees of Marvell.
35 * Such users have the right to use, modify, and incorporate this code into
36 * products for purposes authorized by the license agreement provided they
37 * include this notice and the associated copyright notice with any such
38 * product.
39 * The information in this file is provided "AS IS" without warranty.
40 *
41 ******************************************************************************/
42
43/******************************************************************************
44**
45** FILENAME: ProtocolManager.h
46**
47** PURPOSE: This module manages the boot ROM protocol used for communication
48** over the UART or USB ports
49**
50**
51******************************************************************************/
52#ifndef _protocol_manager_h
53#define _protocol_manager_h
54
55#include "Typedef.h"
56#include "Flash.h"
57#include "general.h"
58#include "loadoffsets.h"
59#include "usbapi.h"
60
61#define VERSION_OFFSET 0x24
62/********************* Image Types ***********************************/
63#define FIRSTIMAGE 1
64
65/************* Commands definitions **********************************/
66
67//ErrorCodes for Host Application
68#define Ack 0x00
69#define Nack 0x01
70#define SeqError 0x02
71#define JtagAccessGranted 0x11
72#define JtagAccessDenied 0xFF
73#define JtagREIssued 0x05
74#define DebugCmdIssued 0x06
75#define DebugBootIssued 0x07
76#define Untested 0x02
77#define InvalidParameterError 0x08
78
79//Status Flags
80#define MESSAGE_FLAG BIT0
81#define FAST_DOWNLOAD BIT2
82#define UUID_FLAG BIT3
83
84//Commands
85#define INVALIDCMD 0x00
86#define GetVersionCmd 0x20
87#define StartAddrCmd 0x21
88#define DownloadDataCmd 0x22
89#define JumpAddrCmd 0x23
90#define OEMPublicKeyCmd 0x24
91#define OEMSignedKeyCmd 0x25
92#define SelectImageCmd 0x26
93#define VerifyImageCmd 0x27
94#define PasswordCmd 0x28
95#define DataHeaderCmd 0x2a
96#define MessageCmd 0x2b
97#define ViewOTPCmd 0x2c
98#define DebugBootCmd 0x2d
99#define DoneCmd 0x30
100#define DisconnectCmd 0x31
101#define UploadDataHeaderCmd 0x32
102#define UploadDataCmd 0x33
103#define ProtocolVersionCmd 0x34
104#define GetParametersCmd 0x35
105#define JtagOverMediaCmd 0x36
106#define GetBadBlockCmd 0x37
107#define GetImageCrcCmd 0x38
108
109#define PROTOCOL_WAITTIME 0x80 // in seconds, max time to wait for command
110//Max time to wait between a PREAMBLE and GETVERSION (triggering a download)
111#define PM_DL_STARTTIME_MS 0x10000 // update to 0x10000 instead of 0x80 to support multi FBFs download
112
113// 0x10000ms might be not enough for SWDConsole to download FBF,
114// enlarge it to 0x40000ms
115#define PM_DL_IMAGE_MS 0x40000 //Max time to wait for a single image to be downloaded
116#define PM_DISCONNET_MS 0x20 //Max time to wait for the disconnect command to appear
117
118#define DATA_BLOCK_SIZE 0x3f8 //block size + sizeof(ProtocolCmd) must be word aligned
119#define FD_BLOCK_SIZE 0x4000 //Fast download block size
120#define UPLOAD_BLOCK_SIZE 0x1FFA // Upload block size. 6 bytes short of USB FIFO size for Status portion,
121#define LENGTHOFMESSAGES 0x40
122#define MAXNUMOFMESSAGES 0x40
123#define PREAMBLE_SIZE 0x4
124#define COMMAND_SIZE 0x8
125
126#define COMMAND_DATALENGTH 0x10 // Maximum command data size
127
128//Communication Protocol Version
129#define COMM_PROTOCOL_MAJOR_VERSION 0x1
130#define COMM_PROTOCOL_MINOR_VERSION 0x1
131#define COMM_PROTOCOL_REV_VERSION 0x0
132
133//Communication Protocol Parameters
134#define COMM_PROTOCOL_BUFFER_SIZE 0x2000
135// 3 more reserved parameters
136
137// Upload Cmd Data Source Types
138#define UPLOAD_FLASH 0x0
139#define UPLOAD_DDR 0x1
140
141//#pragma pack (8)
142
143//Download ISR information
144typedef struct
145{
146 volatile UINT8_T PreambleReceived;
147 volatile UINT8_T CommandReceived;
148 volatile UINT8_T DisconnectReceived;
149 volatile UINT8_T DownloadsEnabled;
150 volatile UINT8_T FastDLInProgress;
151 volatile UINT8_T DLWaiting;
152 volatile UINT32_T DataLeft;
153 volatile UINT32_T CurrentTransferAddress;
154 volatile UINT32_T MaxImageSize;
155 volatile UINT32_T ErrorCode;
156 UINT32_T CurrentImageID;
157 P_USBAPI_T plinkedUSB;
158} ProtocolISR, *pProtocolISR;
159
160typedef struct {
161 volatile UINT8_T Command;
162 volatile UINT8_T Sequence;
163 volatile UINT8_T CID;
164 volatile UINT8_T Flags;
165 volatile UINT32_T Length;
166 volatile UINT8_T Data[COMMAND_DATALENGTH];
167} ProtocolCmd, *pProtocolCmd;
168
169typedef struct {
170 UINT8_T Command;
171 UINT8_T Sequence;
172 UINT8_T CID;
173 UINT8_T Status;
174 UINT8_T Flags;
175 UINT8_T Length;
176 UINT8_T Data[32];
177} ProtocolRsp, *pProtocolRsp;
178
179#define REPORT_LENGTH 4
180
181#define REPORT_NOTIFICATION 0
182#define REPORT_ERROR 1
183#define REPORT_BURNT_IMAGE_LENGTH 2
184#define REPORT_UPLOAD_NOTIFICATION 3
185#define REPORT_FLASH_SIZE_NOTIFICATION 4
186#define REPORT_EXTENDED_FUSE_INFO 5
187#define REPORT_EXTENDED2_FUSE_INFO 6
188
189typedef struct {
190 volatile UINT8_T ReportType; // indicate an error (1) or a notification (0) or others
191 volatile UINT8_T Reserved;
192 volatile UINT8_T ReportCode[REPORT_LENGTH];
193} MessageReport, *pMessageReport;
194
195typedef enum
196{
197 NonTrustedBoot1 = 0x00000000,
198 NonTrustedBoot2 = 0x00000001,
199 TrustedBoot = 0x00000002,
200 TamperBoot = 0x00000003 // BootROM will not boot device, so, OBM can't detect such mode.
201}BootROM_Operation_Mode;
202
203typedef struct
204{
205 UINT_T ChipID : 16; // 0x1188
206 UINT_T RevisionID : 8; // 0xB0
207 UINT_T Reserved : 8;
208}ChipIDInfo;
209
210// extended message data
211typedef struct {
212 volatile UINT_T OEMKeyHash[8]; // fixed length: 256bits
213 volatile UINT_T DeviceUID[2]; // fixed length: 64bits
214 volatile BootROM_Operation_Mode BRMode;
215 volatile UINT_T MMCSerialNumber; // fixed length: 32bits
216 volatile UINT_T ID; // ChipIDInfo
217} ExMessageData, *pExMessageData;
218
219// extended message data
220typedef struct {
221 // first message
222 volatile UINT_T OEMKeyHash[8]; // fixed length: 256bits
223 volatile UINT_T DeviceUID[2]; // fixed length: 64bits
224 volatile BootROM_Operation_Mode BRMode;
225 volatile UINT_T ID; // ChipIDInfo
226 // second message
227 volatile UINT_T CID[4]; // fixed lenght: 128bits
228 volatile UINT_T reserved0; // make struct align
229 volatile UINT_T reserved1; // make struct align
230 volatile UINT_T eMMCSize; // MB
231 volatile UINT_T DDRSize; // MB
232} Ex2MessageData, *pEx2MessageData;
233
234// extended message report
235typedef struct {
236 volatile UINT8_T ReportType;
237 volatile UINT8_T ReportLength;
238 volatile UINT8_T TotalNumber;
239 volatile UINT8_T Index;
240 volatile ExMessageData ReportData;
241} ExMessageReport, *pExMessageReport;
242
243// extended message report
244typedef struct {
245 volatile UINT8_T ReportType;
246 volatile UINT8_T ReportLength;
247 volatile UINT8_T TotalNumber;
248 volatile UINT8_T Index;
249 volatile Ex2MessageData ReportData;
250} Ex2MessageReport, *pEx2MessageReport;
251
252typedef struct {
253 VUINT_T MessageFlag;
254 volatile UINT8_T Messages[MAXNUMOFMESSAGES][LENGTHOFMESSAGES];
255 volatile UINT8_T Lengths[MAXNUMOFMESSAGES];
256 volatile UINT8_T MessageType[MAXNUMOFMESSAGES];
257 UINT8_T CurrentMessageIndex;
258 volatile UINT8_T NumMessagesQueued;
259} ProtocolMsg, *pProtocolMsg;
260
261/*
262 * Upload Data structures
263 * UploadDataParams; To select data source, address and size
264 * ProtocolParams ; To select buffer size etc. This is meant
265 * ; to be general for the protocol. But currently
266 * ; only used for Upload Data.
267 */
268typedef struct {
269 UINT8_T Type;
270 UINT8_T SubType;
271 UINT8_T Partition;
272 UINT8_T Times; // indicate how many times SWD want to do upload
273 UINT_T Offset;
274 UINT_T DataSize;
275 UINT8_T IncludeOOB : 1;
276 UINT8_T UploadBypassBBT : 1;
277 UINT8_T DisableECC : 1;
278 UINT8_T Reserved : 5;
279 UINT8_T ResetUE; // indicate whether reset UE or not
280 UINT8_T ResetTimeDelay; // indicate the delay time before resetting UE
281 UINT8_T Reserved2; //used as emmc high address if its size exceeds 4GB
282} UploadDataParameters, *pUploadDataParameters;
283
284typedef struct
285{
286 UINT_T BufferSize;
287 UINT_T Rsvd1;
288 UINT_T Rsvd2;
289 UINT_T Rsvd3;
290} ProtocolParams, *pProtocolParams;
291
292typedef struct
293{
294 UINT8_T MajorVersion;
295 UINT8_T MinorVersion;
296 UINT16_T RevisionVersion;
297} ProtocolVersion, *pProtocolVersion;
298
299
300typedef struct {
301 UINT8_T FFUART_Init;
302 UINT8_T ALTUART_Init;
303 UINT8_T CI2_USB_Init;
304} PortStates, *pPortStates;
305
306typedef struct
307{
308 UINT32 ImageID;
309 UINT32 BadCnt;
310}ImageBBInfo;
311
312// Badblock data
313typedef struct {
314 UINT32 TotalBadBlocks;
315 UINT32 TotalBlocks;
316 ImageBBInfo BadCount[8]; //reserved for critical partitions support
317} BadBlockData, *pBadBlockData;
318
319#define CRC_MAX_IMAGE_NUM 32
320
321typedef struct
322{
323 UINT32 ImageID;
324 UINT32 CRC32;
325}CRCInfo;
326
327// Image CRC data
328typedef struct
329{
330 UINT32 MCPID;
331 UINT32 ImageNum;
332 CRCInfo ImageCRC[CRC_MAX_IMAGE_NUM];
333}ImageCRCInfo, *pImageCRCInfo;
334
335//#pragma pack ()
336
337//Prototype Definitions
338pProtocolISR getProtocolISR(void);
339pProtocolCmd getProtocolCmd(void);
340pProtocolCmd setProtocolCmd(void *addr);
341pProtocolRsp getProtocolRsp(void);
342pProtocolMsg getProtocolMsg(void);
343void setProtocolError(UINT8_T Error);
344UINT8_T getProtocolError(void);
345UCHAR * getProtoBuff(void);
346void setProtoBuff(UCHAR* pAddr);
347void resetProtoBuff(void);
348UINT PreambleReceived(void);
349void ClearPreambleReceived(void);
350unsigned int ImageDownloadWaiting(unsigned int media_num);
351
352//Reply routines
353UINT_T SendResponse(UINT8_T *pAckBuff, UINT_T size);
354UINT_T SendAck(void);
355UINT_T SendError(UINT_T ErrorCode);
356
357//Individual Commmand handler
358UINT_T HandleGetVersionCmd(void);
359UINT_T HandleSelectImageCmd(UINT_T imageType);
360UINT_T HandleVerifyImageCmd(void);
361UINT_T HandleDataHeaderCmd(void);
362UINT_T HandleDataCmd(void);
363UINT_T HandleDoneCmd(void);
364UINT_T HandleMessageCmd(void);
365UINT_T HandleDisconnect(void);
366
367//Routines that interact with upper level
368UINT_T InitPort(UINT_T port);
369void ShutdownPorts ();
370UINT_T PM_ReceiveImage(UINT_T dummy, UINT_T address, UINT_T size, UINT_T image_id);
371
372//Interrupt routines that work with USB drivers
373void PM_ISR(P_USBAPI_T this, UINT bytes, UINT * buffer);
374UINT PM_Handler(UINT packetLength);
375
376//routines for uploads
377UINT_T GetUploadCommand(void);
378UINT_T HandleUploadFlow(UINT_T address);
379UINT_T HandleUploadDataHeaderCmd(void);
380UINT_T HandleUploadDataCmd(void);
381UINT_T CopyUploadDataIntoBuffer(UINT_T address, pUploadDataParameters pUploadParams);
382UINT_T VerifyUploadParameters(pUploadDataParameters pUploadParams);
383UINT_T HandleProtocolVersionCmd(void);
384UINT_T HandleGetParametersCmd(void);
385UINT_T HandleGetCrcCmd();
386UINT_T HandleGetBadBlock();
387
388//message routines
389UINT_T AddMessageError(UINT_T ReportType, UINT_T ReportCode);
390UINT_T AddMessageCompound(UINT8_T* message, UINT number);
391
392//others
393UINT_T HandleRequest(UINT_T src_addr, UINT_T dest_addr, UINT_T max_size, UINT_T image_id);
394UINT8_T PM_VerifyPreamble( UINT8_T *candidateString ) ;
395UINT8_T CheckProtocolTimeOut(UINT_T StartTime);
396
397#endif
398