blob: 5cd20ec8481f59a31b1674f696810c36b2508a09 [file] [log] [blame]
b.liua76c9612025-03-28 13:58:09 +08001#ifndef __TIM_H__
2#define __TIM_H__
3
4enum {
5 IMAGE_ID_DTIM_A = 0x54494D31, /* dtim primary */
6 IMAGE_ID_DTIM_B = 0x54494d32, /* dtim recovery */
7 IMAGE_ID_UBOOT = 0x4F534C4F,
8 IMAGE_ID_KERNEL = 0x5A494D47,
9 IMAGE_ID_ROOTFS = 0x5359534A,
10 IMAGE_ID_ARBEL = 0x41524249,
11 IMAGE_ID_MSA = 0x47524249,
12 IMAGE_ID_RF = 0x52464249,
13 IMAGE_ID_OEMD = 0x4F454D44,
14 IMAGE_ID_OBM = 0x4f424d49,
15 IMAGE_ID_TIMH = 0x54494d48,
16
17 // Add by liubin
18 IMAGE_ID_DEVICE = 0x4F454D55,
19};
20
21#define TIMIDENTIFIER 0x54494D48 // "TIMH"
22// TIM Versions
23#define TIM_3_2_00 0x30200 // Support for Partitioning
24#define TIM_3_3_00 0x30300 // Support for ECDSA-256
25#define TIM_3_4_00 0x30400 // Support for ECDSA-521
26
27// Defined for DTIM support
28typedef enum
29{
30 TIMH_NOTINC = 0,
31 TIMH_INC = 1,
32 DTIM_PRIMARY_INC = 2,
33 DTIM_RECOVERY_INC = 3,
34 DTIM_CP_INC = 4,
35 TIMH_RECOVERY_INC = 5,
36 DTIM_PPSETTING_INC = 6,
37 // 7-9 reserved
38 DTIM_CUSTMOZIEDTYPE1 = 10,
39 DTIM_CUSTMOZIEDTYPE2 = 11,
40 DTIM_CUSTMOZIEDTYPE3 = 12,
41 DTIM_CUSTMOZIEDTYPE4 = 13,
42 DTIM_CUSTMOZIEDTYPE5 = 14,
43 DTIM_CUSTMOZIEDTYPE6 = 15,
44 DTIM_CUSTMOZIEDTYPE7 = 16,
45 DTIM_CUSTMOZIEDTYPE8 = 17,
46 DTIM_CUSTMOZIEDTYPE9 = 18,
47 DTIM_CUSTMOZIEDTYPE10 = 19,
48 DTIM_CUSTMOZIEDTYPE11 = 20,
49 DTIM_CUSTMOZIEDTYPE12 = 21,
50 DTIM_CUSTMOZIEDTYPE13 = 22,
51 DTIM_CUSTMOZIEDTYPE14 = 23,
52 DTIM_CUSTMOZIEDTYPE15 = 24,
53 DTIM_CUSTMOZIEDTYPE16 = 25,
54 DTIM_CUSTMOZIEDTYPE17 = 26,
55 DTIM_CUSTMOZIEDTYPE18 = 27,
56 DTIM_CUSTMOZIEDTYPE19 = 28,
57 DTIM_CUSTMOZIEDTYPE20 = 29,
58
59 DTIM_CUSTMOZIED_MAX = 50
60} TIMIncluded_Type;
61
62typedef unsigned int UINT_T, *PUINT;
63typedef unsigned char UINT8_T;
64
65typedef enum
66{
67 SHA160 = 0x00000014, //20
68 SHA256 = 0x00000020, //32
69 SHA512 = 0x00000040, //64
70 DUMMY_HASH = 0x7FFFFFFF
71}
72HASHALGORITHMID_T;
73
74typedef struct
75{
76 UINT_T Version;
77 UINT_T Identifier; // "TIMH"
78 UINT_T Trusted; // 1- Trusted, 0 Non
79 UINT_T IssueDate;
80 UINT_T OEMUniqueID;
81} VERSION_I, *pVERSION_I; // 0x10 bytes
82
83typedef struct
84{
85 UINT_T WTMFlashSign;
86 UINT_T WTMEntryAddr;
87 UINT_T WTMEntryAddrBack;
88 UINT_T WTMPatchSign;
89 UINT_T WTMPatchAddr;
90 UINT_T BootFlashSign;
91} FLASH_I, *pFLASH_I; // 0x10 bytes
92
93typedef struct
94{
95 UINT_T PartitionNumber : 4;
96 UINT_T ImageType : 8;
97 UINT_T Reserved : 20;
98}TIM_INT;
99
100typedef union{
101 TIM_INT bits;
102 UINT_T value;
103}PN, *pPN;
104
105typedef struct
106{
107 UINT_T ImageID; // Indicate which Image
108 UINT_T NextImageID; // Indicate next image in the chain
109 UINT_T FlashEntryAddr; // Block numbers for NAND
110 UINT_T LoadAddr;
111 UINT_T ImageSize;
112 UINT_T ImageSizeToHash;
113 HASHALGORITHMID_T HashAlgorithmID; // See HASHALGORITHMID_T
114 UINT_T Hash[16]; // Reserve 512 bits for the hash
115 PN PartitionNumber;
116} IMAGE_INFO_3_4_0, *pIMAGE_INFO_3_4_0; // 0x60 bytes
117
118typedef struct
119{
120 UINT_T ImageID; // Indicate which Image
121 UINT_T NextImageID; // Indicate next image in the chain
122 UINT_T FlashEntryAddr; // Block numbers for NAND
123 UINT_T LoadAddr;
124 UINT_T ImageSize;
125 UINT_T ImageSizeToHash;
126 HASHALGORITHMID_T HashAlgorithmID; // See HASHALGORITHMID_T
127 UINT_T Hash[8]; // Reserve 256 bits for the hash
128 UINT_T PartitionNumber; // This is new for V3.2.0
129} IMAGE_INFO_3_2_0, *pIMAGE_INFO_3_2_0; // 0x40 bytes
130
131// Constant part of the TIMs
132typedef struct
133{
134 VERSION_I VersionBind; // 0
135 FLASH_I FlashInfo; // 0x10
136 UINT_T NumImages; // 0x20
137 UINT_T NumKeys; // 0x24
138 UINT_T SizeOfReserved; // 0x28
139} CTIM, *pCTIM; // 0x2C
140
141// TIM structure for use by DKB/OBM/BootROM
142typedef struct
143{
144 pCTIM pConsTIM; // Constant part
145 pIMAGE_INFO_3_4_0 pImg; // Pointer to Images
146 void *pKey; // Pointer to Keys
147 PUINT pReserved; // Pointer to Reserved Area
148 void *pTBTIM_DS; // Pointer to Digital Signature
149} TIM, *pTIM;
150
151/**
152 * General error code definitions 0x0 - 0x1F
153 **/
154#define NoError 0x0
155#define NotFoundError 0x1
156#define TIMNotFound 0x6D
157
158// WTP Format Recognized Reserved Area Indicator
159#define WTPRESERVEDAREAID 0x4F505448 // "OPTH"
160
161// Reserved Area Package Headers
162#define TERMINATORID 0x5465726D // "Term"
163
164/********** WTP Recognized Reserved Area Layout ********************************
165*
166* WTPTP_Defined_Reserved_Format_ID \ This clues BR, OBM and DKB that the reserved area is in a known format
167* Number of Reserved Area Packages / For each package there is a header, payload size and payload
168*
169* Header \ Indicates what type of a Reserved Area Package
170* Size \ Size Comprises a single Reserved Area Package
171* Payload / There may be any number of Packages so long as TIM/NTIM < 4KB
172* /
173*
174* Header \ The Last one should be a Package with a Terminator Header
175* Size / The size should be 8 bytes (the size of this package)
176*
177**********************************************************************************/
178typedef struct
179{
180 UINT_T WTPTP_Reserved_Area_ID; // This clues BR, OBM and DKB that the reserved area is in a known format
181 UINT_T NumReservedPackages; // For each package there is a header, payload size and payload
182}WTP_RESERVED_AREA, *pWTP_RESERVED_AREA;
183
184typedef struct
185{
186 UINT_T Identifier; // Identification of this reserved area entry
187 UINT_T Size; // Size = Payload Size + 2 words (8 bytes).
188}WTP_RESERVED_AREA_HEADER, *pWTP_RESERVED_AREA_HEADER;
189
190#define DDR_FLASH_MCP_PACKAGE_ID 0X44464D50 // "DFMP"
191typedef struct
192{
193 unsigned int VendorDdrPid;
194 unsigned int FlashInfo; //for eMMC, FlashInfo is flash size, MB; for nand, FlashInfo is NandID
195} VendorDdrFlashSpec, *pVendorDdrFlashSpec;
196
197
198typedef struct
199{
200 WTP_RESERVED_AREA_HEADER WRAH;
201 unsigned int NumberVendorDdrFlashSpec;
202 VendorDdrFlashSpec ddrFlashSpec[2];
203} DDR_FLASH_MCP_PACKAGE, *pDDR_FLASH_MCP_PACKAGE;
204
205#define MAXRSAKEYSIZEWORDS 64 // 2048 bits
206#define MAXECCKEYSIZEWORDS 17 // 521 bits+
207
208typedef enum
209{
210 Marvell_DS = 0x00000000,
211 PKCS1_v1_5_Caddo = 0x00000001,
212 PKCS1_v2_1_Caddo = 0x00000002,
213 PKCS1_v1_5_Ippcp = 0x00000003,
214 PKCS1_v2_1_Ippcp = 0x00000004,
215 ECDSA_256 = 0x00000005,
216 ECDSA_521 = 0x00000006,
217 PKCS1_v2_2_Ippcp = 0x00000007,
218 DUMMY_ENALG = 0x7FFFFFFF // See _Cryptographic_Scheme for additional id's
219}
220ENCRYPTALGORITHMID_T;
221
222typedef struct
223{
224 UINT_T KeyID; // Associate an ID with this key
225 HASHALGORITHMID_T HashAlgorithmID; // See HASHALGORITHMID_T
226 UINT_T KeySize; // Specified in bits
227 UINT_T PublicKeySize; // Specified in bits
228 UINT_T RSAPublicExponent[MAXRSAKEYSIZEWORDS]; // Contents depend on PublicKeySize
229 UINT_T RSAModulus[MAXRSAKEYSIZEWORDS]; // Up to 2K bits
230 UINT_T KeyHash[8]; // Reserve 256 bits for the hash
231} KEY_MOD_3_2_0, *pKEY_MOD_3_2_0; // 0x22C bytes
232
233typedef struct
234{
235 UINT_T KeyID; // Associate an ID with this key
236 HASHALGORITHMID_T HashAlgorithmID; // See HASHALGORITHMID_T
237 UINT_T KeySize; // Specified in bits
238 UINT_T PublicKeySize; // Specified in bits
239 ENCRYPTALGORITHMID_T EncryptAlgorithmID; // See ENCRYPTALGORITHMID_T;
240 union
241 {
242 struct
243 {
244 UINT_T RSAPublicExponent[MAXRSAKEYSIZEWORDS]; // Contents depend on PublicKeySize
245 UINT_T RSAModulus[MAXRSAKEYSIZEWORDS]; // Up to 2K bits
246 }Rsa;
247
248 struct
249 {
250 UINT_T PublicKeyCompX[MAXECCKEYSIZEWORDS]; // Contents depend on PublicKeySize
251 UINT_T PublicKeyCompY[MAXECCKEYSIZEWORDS]; // Up to 521 bits
252 // Pad this struct so it remains consistent with RSA struct
253 UINT_T Reserved[(2*MAXRSAKEYSIZEWORDS)-(2*MAXECCKEYSIZEWORDS)];
254 }Ecdsa;
255 };
256
257 UINT_T KeyHash[8]; // Reserve 256 bits for the hash
258} KEY_MOD_3_3_0, *pKEY_MOD_3_3_0; //
259
260typedef struct
261{
262 UINT_T KeyID; // Associate an ID with this key
263 HASHALGORITHMID_T HashAlgorithmID; // See HASHALGORITHMID_T
264 UINT_T KeySize; // Specified in bits
265 UINT_T PublicKeySize; // Specified in bits
266 ENCRYPTALGORITHMID_T EncryptAlgorithmID; // See ENCRYPTALGORITHMID_T;
267 union
268 {
269 struct
270 {
271 UINT_T RSAPublicExponent[MAXRSAKEYSIZEWORDS]; // Contents depend on PublicKeySize
272 UINT_T RSAModulus[MAXRSAKEYSIZEWORDS]; // Up to 2K bits
273 }Rsa;
274
275 struct
276 {
277 UINT_T PublicKeyCompX[MAXECCKEYSIZEWORDS]; // Contents depend on PublicKeySize
278 UINT_T PublicKeyCompY[MAXECCKEYSIZEWORDS]; // Up to 521 bits
279 // Pad this struct so it remains consistent with RSA struct
280 UINT_T Reserved[(2*MAXRSAKEYSIZEWORDS)-(2*MAXECCKEYSIZEWORDS)];
281 }Ecdsa;
282
283 struct
284 {
285 UINT_T EncryptedHashRSAPublicExponent[MAXRSAKEYSIZEWORDS]; // Contents depend on PublicKeySize
286 UINT_T EncryptedHashRSAModulus[MAXRSAKEYSIZEWORDS]; // Up to 2K bits
287 }EncryptedRsa;
288
289 struct
290 {
291 UINT_T EncryptedHashPublicKeyCompX_R[MAXECCKEYSIZEWORDS]; // Contents depend on PublicKeySize
292 UINT_T EncryptedHashPublicKeyCompX_S[MAXECCKEYSIZEWORDS]; // Contents depend on PublicKeySize
293
294 UINT_T EncryptedHashPublicKeyCompY_R[MAXECCKEYSIZEWORDS]; // Up to 521 bits
295 UINT_T EncryptedHashPublicKeyCompY_S[MAXECCKEYSIZEWORDS]; // Up to 521 bits
296
297 // Pad this struct so it remains consistent with encrypted RSA struct
298 UINT_T Reserved[(2 * MAXRSAKEYSIZEWORDS)-(4 * MAXECCKEYSIZEWORDS)];
299 }EncryptedEcdsa;
300 };
301
302 UINT_T KeyHash[16]; // Reserve 512 bits for the hash
303} KEY_MOD_3_4_0, *pKEY_MOD_3_4_0; //
304
305
306typedef struct
307{
308 ENCRYPTALGORITHMID_T DSAlgorithmID; // See ENCRYPTALGORITHMID_T
309 HASHALGORITHMID_T HashAlgorithmID; // See HASHALGORITHMID_T
310 UINT_T KeySize; // Specified in bits
311 UINT_T Hash[8]; // Reserve 256 bits for optional key hash
312 union // Note that this union should not be included as part of the hash for TIM in the Digital Signature
313 {
314 struct
315 {
316 UINT_T RSAPublicExponent[MAXRSAKEYSIZEWORDS];
317 UINT_T RSAModulus[MAXRSAKEYSIZEWORDS]; // Up to 2K bits
318 UINT_T RSADigS[MAXRSAKEYSIZEWORDS]; // Contains TIM Hash
319 }Rsa;
320
321 struct
322 {
323 UINT_T ECDSAPublicKeyCompX[MAXECCKEYSIZEWORDS]; // Allow for 544 bits (17 words, 68 bytes for use with EC-521)
324 UINT_T ECDSAPublicKeyCompY[MAXECCKEYSIZEWORDS];
325 UINT_T ECDSADigS_R[MAXECCKEYSIZEWORDS];
326 UINT_T ECDSADigS_S[MAXECCKEYSIZEWORDS];
327 // Pad this struct so it remains consistent with RSA struct
328 UINT_T Reserved[(MAXRSAKEYSIZEWORDS*3)-(MAXECCKEYSIZEWORDS*4)];
329 } Ecdsa;
330 };
331} PLAT_DS, *pPLAT_DS;
332
333#endif
334