1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2006-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95 ////////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file drvDSCMB.c
98 /// @brief Descrambler (DSCMB) Driver Interface
99 /// @author MStar Semiconductor,Inc.
100 ////////////////////////////////////////////////////////////////////////////////////////////////////
101
102 #include "MsCommon.h"
103 #include "MsVersion.h"
104
105 #ifdef MSOS_TYPE_LINUX_KERNEL
106 #include <linux/string.h>
107 #else
108 #include <string.h>
109 #endif
110
111 #include "drvMMIO.h"
112 #include "drvCA.h"
113 #include "regCA.h"
114 #include "halCA.h"
115 #include "utopia.h"
116
117 #ifdef CA_UTOPIA_20
118 #define CA_UTOPIA20
119 #else
120 #undef CA_UTOPIA20
121 #endif
122
123 #ifdef CA_UTOPIA20
124 #include "drvCA_v2.h"
125 #endif
126
127 #include "drvCA_private.h"
128
129 static MS_BOOL _bCADrv_Inited = FALSE;
130 static MS_S32 _s32CADrv_Mutex = -1 ;
131 static MS_BOOL _bBGCDrv_Inited = FALSE;
132 static MS_BOOL _bCASTRDrv_Inited = FALSE;
133
134 #ifdef CA_NO_PRINTF
135 #define DRV_CA_DEBUG(fmt, args...)
136 #else
137 #define DRV_CA_DEBUG(fmt, args...) do{ \
138 printf("[%s][%d]"fmt"\n", __FUNCTION__, __LINE__, ## args);}\
139 while(0)
140 #endif
141
142 #define DRV_CA_ASSERT( _bool_, _msg_, ret) \
143 do { if(!(_bool_)) { DRV_CA_DEBUG(_msg_); return (ret); } } while(0)
144
145 #define DRV_CA_INIT_CHECK(ret) DRV_CA_ASSERT(_bCADrv_Inited == TRUE, "The drvCA is not initialized\n", ret)
146 #define DRV_BGC_INIT_CHECK(ret) DRV_CA_ASSERT(_bBGCDrv_Inited == TRUE, "The drvBGC is not initialized\n", ret)
147 #define DRV_CASTR_INIT_CHECK(ret) DRV_CA_ASSERT(_bCASTRDrv_Inited == TRUE, "The drvCASTR is not initialized\n", ret)
148
149 #if !defined (MSOS_TYPE_NOS) && !defined (MCU_AEON)
150 //BGC Isr proc
151 #define BGC_FAIL_INT (0x80000000UL)
152 #define BGC_START_INT (0x40000000UL)
153 #define BGC_TASK_STACK_SIZE (4096UL)
154 static MS_U8 _u8BGC_StackBuffer[BGC_TASK_STACK_SIZE];
155 static MS_S32 _s32BGCTaskId;
156 static MS_S32 _s32BGCEventId;
157
158 #define BGCIntEnable() MsOS_EnableInterrupt (BGC_IRQ)
159 #define BGCIntDisable() MsOS_DisableInterrupt(BGC_IRQ)
160 #define BGCIntAttach(isr) MsOS_AttachInterrupt (BGC_IRQ, (InterruptCb )isr)
161 #define BGCIntDetach() MsOS_DetachInterrupt (BGC_IRQ)
162 #endif
163
164 typedef struct
165 {
166 MS_BOOL bUsed;
167 MS_U32 u32BGCMode;
168 }ST_BGC_SEC_CFG;
169
170 ST_BGC_SEC_CFG stBGCSecCfg[BGC_SEC_MAX];
171
172 #ifdef CA_UTOPIA20
173 static void *pu32CAInst = NULL;
174 #endif
175
176 //--------------------------------------------------------------------------------------------------
177 /// Initialize CA driver
178 /// @return TRUE - Success
179 /// @return FALSE - Failure
180 /// @note
181 //--------------------------------------------------------------------------------------------------
_MDrv_CA_Init(void)182 MS_BOOL _MDrv_CA_Init(void)
183 {
184 MS_VIRT ptrRegBank;
185 MS_PHY u32BankSize;
186
187 if(TRUE == _bCADrv_Inited)
188 {
189 return TRUE;
190 }
191
192 if (FALSE == MDrv_MMIO_GetBASE(&ptrRegBank, &u32BankSize, MS_MODULE_HW))
193 {
194 MS_DEBUG_MSG(printf("[%s][%d] Get MMIO base fail\n", __FUNCTION__, __LINE__));
195 return FALSE;
196 }
197
198 HAL_CA_SetBank(ptrRegBank);
199
200 if(HAL_CA_Init() == FALSE)
201 {
202 MS_DEBUG_MSG(printf("[%s][%d] HAL CA init fail\n", __FUNCTION__, __LINE__));
203 return FALSE;
204 }
205
206 _bCADrv_Inited = TRUE;
207 _bBGCDrv_Inited = FALSE;
208
209 _s32CADrv_Mutex = MsOS_CreateMutex(E_MSOS_FIFO, (char*) "CA2_Mutex", MSOS_PROCESS_SHARED);
210
211 return TRUE;
212 }
213
214 //-------------------------------------------------------------------------------------------------
215 /// @brief Enable Secure Boot
216 /// @return TRUE: Process success.
217 /// @return FALSE: Process fail.
218 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_EnableSecureBoot(void)219 MS_BOOL _MDrv_CA_OTP_EnableSecureBoot(void)
220 {
221 DRV_CA_INIT_CHECK(FALSE);
222 return HAL_CA_OTP_EnableSecureBoot();
223 }
224
225 //-------------------------------------------------------------------------------------------------
226 /// @brief Check if Secure Boot Enabled
227 /// @return TRUE: Enabled
228 /// @return FALSE: Disabled
229 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_IsSecureBootEnabled(void)230 MS_BOOL _MDrv_CA_OTP_IsSecureBootEnabled(void)
231 {
232 DRV_CA_INIT_CHECK(FALSE);
233 return HAL_CA_OTP_IsSecureBootEnabled();
234 }
235
236 //-------------------------------------------------------------------------------------------------
237 /// @brief Forbid OTP read/write by the range
238 /// @param[in] u32Start: start address. unit in 4 bytes
239 /// @param[in] u32End: end address. unit in 4 bytes
240 /// @param[in] eLockType: E_CA_LOCK_WRITE forbid writing, E_CA_LOCK_READ forbid reading
241 /// @return
242 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_SetBlockLock(MS_U32 u32Start,MS_U32 u32End,CA_LOCK_TYPE eLockType)243 MS_BOOL _MDrv_CA_OTP_SetBlockLock(MS_U32 u32Start, MS_U32 u32End, CA_LOCK_TYPE eLockType)
244 {
245 DRV_CA_INIT_CHECK(FALSE);
246 return HAL_CA_OTP_SetBlockLock(u32Start, u32End, eLockType);
247 }
248
_MDrv_CA_OTP_GetBlockLock(MS_U32 * pu32Start,MS_U32 * pu32End,CA_LOCK_TYPE * peLockType)249 MS_BOOL _MDrv_CA_OTP_GetBlockLock(MS_U32 *pu32Start, MS_U32 *pu32End, CA_LOCK_TYPE *peLockType)
250 {
251 DRV_CA_INIT_CHECK(FALSE);
252 return HAL_CA_OTP_GetBlockLock(pu32Start, pu32End, peLockType);
253 }
254
255 //-------------------------------------------------------------------------------------------------
256 /// @brief Check if the value is zero in OTP
257 /// @param[in] addr from 0x0000 to 0x1ffc
258 /// @return OTP value
259 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_IsBlank(MS_U32 addr)260 MS_BOOL _MDrv_CA_OTP_IsBlank(MS_U32 addr)
261 {
262 DRV_CA_INIT_CHECK(FALSE);
263 return HAL_CA_OTP_IsBlank(addr);
264 }
265
266 //-------------------------------------------------------------------------------------------------
267 /// @brief Read 32bits value from OTP
268 /// @param[in] addr from 0x0000 to 0x1ffc
269 /// @return OTP value
270 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_Read(MS_U32 addr)271 MS_U32 _MDrv_CA_OTP_Read(MS_U32 addr)
272 {
273 DRV_CA_INIT_CHECK(FALSE);
274 return HAL_CA_OTP_Read(addr);
275 }
276
277 //-------------------------------------------------------------------------------------------------
278 /// @brief Write 32bits value to OTP
279 /// @param[in] addr from 0x0000 to 0x1ffc
280 /// @param[in] value
281 /// @return TRUE: Process success.
282 /// @return FALSE: Process fail.
283 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_Write(MS_U32 addr,MS_U32 value)284 MS_BOOL _MDrv_CA_OTP_Write(MS_U32 addr, MS_U32 value)
285 {
286 DRV_CA_INIT_CHECK(FALSE);
287 return HAL_CA_OTP_Write(addr, value);
288 }
289
290 //-------------------------------------------------------------------------------------------------
291 /// @brief Read the OTP Lock config
292 /// @param[in] eLock
293 /// @return TRUE: Locked.
294 /// @return FALSE: Not locked
295 //-------------------------------------------------------------------------------------------------
_MDrv_CA_Locked(CA_OTP_LOCK eLock)296 MS_BOOL _MDrv_CA_Locked(CA_OTP_LOCK eLock)
297 {
298 DRV_CA_INIT_CHECK(FALSE);
299 return HAL_CA_Locked(eLock);
300 }
301
302 //-------------------------------------------------------------------------------------------------
303 /// @brief Lock OTP area
304 /// @param[in] eLock
305 /// @return TRUE: Process success.
306 /// @return FALSE: Process fail.
307 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_Lock(CA_OTP_LOCK eLock)308 MS_BOOL _MDrv_CA_OTP_Lock(CA_OTP_LOCK eLock)
309 {
310 DRV_CA_INIT_CHECK(FALSE);
311 return HAL_CA_OTP_Lock(eLock);
312 }
313
314 //-------------------------------------------------------------------------------------------------
315 /// @brief Set the value of the RSAextID in OTP
316 /// @return TRUE: Process success.
317 /// @return FALSE: Process fail.
318 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_SetRSAextID(MS_U32 u32Value)319 MS_BOOL _MDrv_CA_OTP_SetRSAextID(MS_U32 u32Value)
320 {
321 DRV_CA_INIT_CHECK(FALSE);
322 return HAL_CA_OTP_SetRSAextID(u32Value);
323 }
324
325 //-------------------------------------------------------------------------------------------------
326 /// @brief Get the value of the RSAextID in OTP
327 /// @return TRUE: Process success.
328 /// @return FALSE: Process fail.
329 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_GetRSAextID(void)330 MS_U32 _MDrv_CA_OTP_GetRSAextID(void)
331 {
332 DRV_CA_INIT_CHECK(FALSE);
333 return HAL_CA_OTP_GetRSAextID();
334 }
335
_MDrv_CA_OTP_SetHASH1_REF_VER(MS_U32 u32HASH1_REF_VER)336 MS_BOOL _MDrv_CA_OTP_SetHASH1_REF_VER(MS_U32 u32HASH1_REF_VER)
337 {
338 DRV_CA_INIT_CHECK(FALSE);
339 return HAL_CA_OTP_SetHASH1_REF_VER(u32HASH1_REF_VER);
340 }
341
_MDrv_CA_OTP_GetHASH1_REF_VER(MS_U32 * pu32HASH1_REF_VER)342 MS_BOOL _MDrv_CA_OTP_GetHASH1_REF_VER(MS_U32 *pu32HASH1_REF_VER)
343 {
344 DRV_CA_INIT_CHECK(FALSE);
345 if(pu32HASH1_REF_VER == NULL)
346 return FALSE;
347 return HAL_CA_OTP_GetHASH1_REF_VER(pu32HASH1_REF_VER);
348 }
349
350
_MDrv_CA_OTP_SetHASH_REF_VER(MS_U32 u32HASH0_REF_VER,MS_U32 u32HASH2_REF_VER)351 MS_BOOL _MDrv_CA_OTP_SetHASH_REF_VER(MS_U32 u32HASH0_REF_VER, MS_U32 u32HASH2_REF_VER)
352 {
353 DRV_CA_INIT_CHECK(FALSE);
354 return HAL_CA_OTP_SetHASH_REF_VER(u32HASH0_REF_VER, u32HASH2_REF_VER);
355 }
356
_MDrv_CA_OTP_GetHASH_REF_VER(MS_U32 * pu32HASH0_REF_VER,MS_U32 * pu32HASH2_REF_VER)357 MS_BOOL _MDrv_CA_OTP_GetHASH_REF_VER(MS_U32 *pu32HASH0_REF_VER, MS_U32 *pu32HASH2_REF_VER)
358 {
359 DRV_CA_INIT_CHECK(FALSE);
360 if(pu32HASH0_REF_VER == NULL || pu32HASH2_REF_VER == NULL)
361 return FALSE;
362 return HAL_CA_OTP_GetHASH_REF_VER(pu32HASH0_REF_VER, pu32HASH2_REF_VER);
363 }
364
365 //-------------------------------------------------------------------------------------------------
366 /// @brief Set debug port mode
367 /// @param[in] eDebugPort E_CA_DEBUG_PORT_I2C or E_CA_DEBUG_PORT_JTAG
368 /// @param[in] eMode OPEN, PASSWORD_PROTECTED, or CLOSE
369 /// @return TRUE: Process success.
370 /// @return FALSE: Process fail.
371 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_SetDebugPortMode(CA_DEBUG_PORT eDebugPort,CA_DEBUG_PORT_MODE eMode)372 MS_BOOL _MDrv_CA_OTP_SetDebugPortMode(CA_DEBUG_PORT eDebugPort, CA_DEBUG_PORT_MODE eMode)
373 {
374 DRV_CA_INIT_CHECK(FALSE);
375 return HAL_CA_OTP_SetDebugPortMode(eDebugPort, eMode);
376 }
377
378
379 //--------------------------------------------------------------------------------------------------
380 /// Get debug port state from the shadow register
381 /// @param[in] eDebugPort choose debug port
382 /// @param[out] eMode the state of the eDebugPort
383 /// @return TRUE: OK
384 /// @return FALSE: Error
385 /// @note
386 //--------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_GetDebugPortMode(CA_DEBUG_PORT eDebugPort,CA_DEBUG_PORT_MODE * eMode)387 MS_BOOL _MDrv_CA_OTP_GetDebugPortMode(CA_DEBUG_PORT eDebugPort, CA_DEBUG_PORT_MODE *eMode)
388 {
389 DRV_CA_INIT_CHECK(FALSE);
390 return HAL_CA_OTP_GetDebugPortMode(eDebugPort, eMode);
391 }
392
393 //-------------------------------------------------------------------------------------------------
394 /// @brief Write the OTP Device ID
395 /// @param[in] pu8Did a buffer to store the Device ID. In LSB first format
396 /// @param[in] u32Size The size of the buffer
397 /// @return TRUE: OK
398 /// @return FALSE: Error
399 /// @note: The device ID in the OTP is LSB first and this is a byte-to-byte copy API.
400 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_SetDeviceId(const MS_U8 * pu8Did,MS_U32 u32Size)401 MS_BOOL _MDrv_CA_OTP_SetDeviceId(const MS_U8 *pu8Did, MS_U32 u32Size)
402 {
403 DRV_CA_INIT_CHECK(FALSE);
404 return HAL_CA_OTP_SetDeviceId(pu8Did, u32Size);
405 }
406
407 //-------------------------------------------------------------------------------------------------
408 /// @brief Read the OTP Device ID
409 /// @param[out] pu8Did a buffer to store the Device ID. In LSB first format
410 /// @param[in] u32Size The size of the buffer
411 /// @return TRUE: OK
412 /// @return FALSE: Error
413 /// @note: The device ID in the OTP is LSB first and this is a byte-to-byte copy API.
414 //-------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_GetDeviceId(MS_U8 * pu8Did,MS_U32 u32Size)415 MS_BOOL _MDrv_CA_OTP_GetDeviceId(MS_U8 *pu8Did, MS_U32 u32Size)
416 {
417 DRV_CA_INIT_CHECK(FALSE);
418 return HAL_CA_OTP_GetDeviceId(pu8Did, u32Size);
419 }
420
421
422 //--------------------------------------------------------------------------------------------------
423 /// @brief The MAX size of the Device ID
424 /// @return TRUE: OK
425 /// @return FALSE: Error
426
427 /// @note
428 //--------------------------------------------------------------------------------------------------
_MDrv_CA_MaxDeviceIdSize(void)429 MS_U32 _MDrv_CA_MaxDeviceIdSize(void)
430 {
431 DRV_CA_INIT_CHECK(FALSE);
432 return HAL_CA_MaxDeviceIdSize();
433 }
434
435 //--------------------------------------------------------------------------------------------------
436 /// @brief Set ACPU cannot write clear CW to key table
437 /// @return TRUE: OK
438 /// @return FALSE: Error
439 /// @note
440 //--------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_EnableSecureCWMode(void)441 MS_BOOL _MDrv_CA_OTP_EnableSecureCWMode(void)
442 {
443 DRV_CA_INIT_CHECK(FALSE);
444 return HAL_CA_OTP_EnableSecureCWMode();
445 }
446
447 //--------------------------------------------------------------------------------------------------
448 /// @brief Check if ACPU can write clear CW to key table
449 /// @return TRUE: OK
450 /// @return FALSE: Error
451 /// @note
452 //--------------------------------------------------------------------------------------------------
_MDrv_CA_OTP_IsSecureCWMode(void)453 MS_BOOL _MDrv_CA_OTP_IsSecureCWMode(void)
454 {
455 DRV_CA_INIT_CHECK(FALSE);
456 return HAL_CA_OTP_IsSecureCWMode();
457 }
458
459 //-------------------------------------------------------------------------------------------------
460 /// 16bits Hardware random number generator
461 /// @return 16-bits random number
462 //-------------------------------------------------------------------------------------------------
_MDrv_CA_Random(void)463 MS_U32 _MDrv_CA_Random(void)
464 {
465 DRV_CA_INIT_CHECK(FALSE);
466
467 MsOS_ObtainMutex(_s32CADrv_Mutex, MSOS_WAIT_FOREVER);
468 MS_U32 u32Rnd = HAL_CA_Random();
469 MsOS_ReleaseMutex(_s32CADrv_Mutex);
470
471 return u32Rnd;
472 }
473
_MDrv_CA_OTP_ReadCAVendor(void)474 MS_U32 _MDrv_CA_OTP_ReadCAVendor(void)
475 {
476 DRV_CA_INIT_CHECK(FALSE);
477 return HAL_CA_OTP_ReadCAVendor();
478 }
479
480 //--------------------------------------------------------------------------------------------------
481 /// Initialize CA driver
482 /// @return TRUE - Success
483 /// @return FALSE - Failure
484 /// @note
485 //--------------------------------------------------------------------------------------------------
MDrv_CA_Init(void)486 MS_BOOL MDrv_CA_Init(void)
487 {
488 #ifdef CA_UTOPIA20
489 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
490
491 if(pu32CAInst == NULL)
492 {
493 if(UTOPIA_STATUS_FAIL == UtopiaOpen(MODULE_CA, &pu32CAInst, 0x0, NULL))
494 {
495 MS_DEBUG_MSG(printf("[%s][%d] UtopiaOpen CA fail\n", __FUNCTION__, __LINE__));
496 return FALSE;
497 }
498 }
499
500 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_Init, NULL);
501 if(UTOPIA_STATUS_SUCCESS != u32Ret)
502 {
503 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
504 return FALSE;
505 }
506
507 return TRUE;
508 #else
509 return _MDrv_CA_Init();
510 #endif
511 }
512
513 #if !defined (MSOS_TYPE_NOS) && !defined (MCU_AEON)
_BGC_Isr_Proc(void)514 static void _BGC_Isr_Proc(void)
515 {
516 MS_U32 u32Events = 0;
517
518 // coverity[no_escape]
519 while (1)
520 {
521 MsOS_WaitEvent(_s32BGCEventId, BGC_FAIL_INT, &u32Events, E_OR_CLEAR, MSOS_WAIT_FOREVER);
522
523 if(u32Events & BGC_FAIL_INT)
524 {
525 HAL_CA_BGC_ISR();
526 }
527
528 HAL_CA_BGC_DisableINT();
529 BGCIntEnable();
530 } // Task while loop
531 }
532
_BGC_Isr(void)533 static void _BGC_Isr(void)
534 {
535 //set event to trigger proc deal with bgc fail
536 MsOS_SetEvent(_s32BGCEventId, BGC_FAIL_INT);
537 }
538 #endif
539
540 //--------------------------------------------------------------------------------------------------
541 /// Load BGC FW
542 /// @return TRUE - Success
543 /// @return FALSE - Failure
544 /// @note
545 //--------------------------------------------------------------------------------------------------
MDrv_CA_BGC_Init(CA_BGC_CFG stBGCCfg)546 MS_BOOL MDrv_CA_BGC_Init(CA_BGC_CFG stBGCCfg)
547 {
548 DRV_CA_INIT_CHECK(FALSE);
549 MS_BOOL ret = FALSE;
550 if(stBGCCfg.u32FwAddr == 0)
551 {
552 return FALSE;
553 }
554
555 if(stBGCCfg.u32FwSize > 0x2000)
556 { //max size is 8K
557 return FALSE;
558 }
559
560 if(_bBGCDrv_Inited == TRUE)
561 {
562 return TRUE;
563 }
564
565 ret = HAL_CA_BGC_LoadFW(stBGCCfg.u32FwAddr, stBGCCfg.u32FwSize);
566 if(ret == FALSE)
567 {
568 return FALSE;
569 }
570
571
572 #if !defined (MSOS_TYPE_NOS) && !defined (MCU_AEON)
573 //Isr event
574 _s32BGCEventId = MsOS_CreateEventGroup("BGC_Event");
575 if (_s32BGCEventId < 0)
576 {
577 return FALSE;
578 }
579
580 //Isr Task
581 _s32BGCTaskId = MsOS_CreateTask((TaskEntry)_BGC_Isr_Proc,
582 0,
583 E_TASK_PRI_SYS,
584 TRUE,
585 (void*)_u8BGC_StackBuffer,
586 BGC_TASK_STACK_SIZE,
587 "BGC_Task");
588
589 if (_s32BGCTaskId < 0)
590 {
591 MsOS_DeleteEventGroup(_s32BGCEventId);
592 return FALSE;
593 }
594
595
596 BGCIntDisable();
597 BGCIntDetach ();
598 BGCIntAttach (_BGC_Isr);
599 BGCIntEnable ();
600 #endif
601
602 memset(stBGCSecCfg, 0, sizeof(ST_BGC_SEC_CFG));
603
604 _bBGCDrv_Inited = TRUE;
605
606 return TRUE;
607 }
608
609 //--------------------------------------------------------------------------------------------------
610 /// Set BGC Protected section by u32SecId
611 /// @return TRUE - Success
612 /// @return FALSE - Failure
613 /// @note
614 //--------------------------------------------------------------------------------------------------
MDrv_CA_BGC_SetSection(MS_U32 u32SecId,const CA_BGC_SEC_CFG * pstSecCfg)615 MS_BOOL MDrv_CA_BGC_SetSection(MS_U32 u32SecId, const CA_BGC_SEC_CFG* pstSecCfg)
616 {
617 DRV_CA_INIT_CHECK(FALSE);
618 DRV_BGC_INIT_CHECK(FALSE);
619 MS_BOOL ret = FALSE;
620
621 if(u32SecId >= BGC_SEC_MAX || (pstSecCfg == NULL))
622 {
623 return FALSE;
624 }
625
626 ret = HAL_CA_BGC_SetSec(u32SecId, pstSecCfg);
627 if(ret == TRUE)
628 {
629 stBGCSecCfg[u32SecId].bUsed = TRUE;
630 stBGCSecCfg[u32SecId].u32BGCMode = pstSecCfg->u32BGCMode;
631 }
632
633 return TRUE;
634 }
635
636 //--------------------------------------------------------------------------------------------------
637 /// Reset BGC Protected section if BGC mode is 0:dynamic by u32SecId,
638 /// This function will check if the pu8RstPSWD is equal to CA_BGC_SEC_CFG.u8ResetPassword
639 /// If correct, reset the BGC section with u32SecId
640 /// @return TRUE - If pu8RstPSWD is match
641 /// @return FALSE -If pu8RstPSWD is not match
642 /// @note
643 //--------------------------------------------------------------------------------------------------
MDrv_CA_BGC_ResetSection(MS_U32 u32SecId,const MS_U8 * const pu8RstPSWD)644 MS_BOOL MDrv_CA_BGC_ResetSection(MS_U32 u32SecId, const MS_U8* const pu8RstPSWD)
645 {
646 DRV_CA_INIT_CHECK(FALSE);
647 DRV_BGC_INIT_CHECK(FALSE);
648 MS_BOOL ret = FALSE;
649
650 if((u32SecId >= BGC_SEC_MAX) || (pu8RstPSWD == NULL))
651 {
652 return FALSE;
653 }
654
655 if(stBGCSecCfg[u32SecId].bUsed == TRUE)
656 {
657 if(stBGCSecCfg[u32SecId].u32BGCMode == 0)//dynamic
658 {
659 ret = HAL_CA_BGC_ResetSec(u32SecId, pu8RstPSWD);
660 if(ret == TRUE)
661 {
662 stBGCSecCfg[u32SecId].bUsed = FALSE;
663 }
664 }
665 }
666 return ret;
667 }
668
669 //-------------------------------------------------------------------------------------------------
670 /// @brief Init CA MBX driver
671 /// @return TRUE: OK
672 /// @return FALSE: Error
673 //-------------------------------------------------------------------------------------------------
MDrv_CA_MBX_Init(void)674 MS_BOOL MDrv_CA_MBX_Init(void)
675 {
676 // Not Implement
677 DRV_CA_DEBUG("Not Implement\n");
678 return FALSE;
679 }
680
681 //-------------------------------------------------------------------------------------------------
682 /// @brief Write data to MBX
683 /// @param[in] u8Addr The address of the input buffer
684 /// @param[in] u32Length The length of the input buffer
685 /// @return The length that actually write to MBX
686 //-------------------------------------------------------------------------------------------------
MDrv_CA_MBX_Write(MS_U8 * pu8Addr,MS_U32 u32Length)687 MS_U32 MDrv_CA_MBX_Write(MS_U8* pu8Addr, MS_U32 u32Length)
688 {
689 // Not Implement
690 DRV_CA_DEBUG("Not Implement\n");
691 return FALSE;
692 }
693
694 //-------------------------------------------------------------------------------------------------
695 /// @brief Read data from MBX
696 /// @param[Out] u8Addr The address of the output buffer
697 /// @param[in] u32Length The length of the output buffer
698 /// @return The length that actually read from MBX
699 //-------------------------------------------------------------------------------------------------
MDrv_CA_MBX_Read(MS_U8 * pu8Addr,MS_U32 u32Length)700 MS_U32 MDrv_CA_MBX_Read(MS_U8* pu8Addr, MS_U32 u32Length)
701 {
702 // Not Implement
703 DRV_CA_DEBUG("Not Implement\n");
704 return FALSE;
705 }
706
707 //-------------------------------------------------------------------------------------------------
708 /// @brief Enable Secure Boot
709 /// @return TRUE: Process success.
710 /// @return FALSE: Process fail.
711 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_EnableSecureBoot(void)712 MS_BOOL MDrv_CA_OTP_EnableSecureBoot(void)
713 {
714 #ifdef CA_UTOPIA20
715 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
716
717 if(pu32CAInst == NULL)
718 {
719 return FALSE;
720 }
721
722 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_EnableSecureBoot, NULL);
723 if(UTOPIA_STATUS_SUCCESS != u32Ret)
724 {
725 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
726 return FALSE;
727 }
728
729 return TRUE;
730 #else
731 return _MDrv_CA_OTP_EnableSecureBoot();
732 #endif
733 }
734
735 //-------------------------------------------------------------------------------------------------
736 /// @brief Check if Secure Boot Enabled
737 /// @return TRUE: Enabled
738 /// @return FALSE: Disabled
739 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_IsSecureBootEnabled(void)740 MS_BOOL MDrv_CA_OTP_IsSecureBootEnabled(void)
741 {
742 #ifdef CA_UTOPIA20
743 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
744
745 if(pu32CAInst == NULL)
746 {
747 return FALSE;
748 }
749
750 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_IsSecureBootEnabled, NULL);
751 if(UTOPIA_STATUS_SUCCESS != u32Ret)
752 {
753 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
754 return FALSE;
755 }
756
757 return TRUE;
758 #else
759 return _MDrv_CA_OTP_IsSecureBootEnabled();
760 #endif
761 }
762
763 //-------------------------------------------------------------------------------------------------
764 /// @brief Forbid OTP read/write by the range
765 /// @param[in] u32Start: start address. unit in 4 bytes
766 /// @param[in] u32End: end address. unit in 4 bytes
767 /// @param[in] eLockType: E_CA_LOCK_WRITE forbid writing, E_CA_LOCK_READ forbid reading
768 /// @return
769 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_SetBlockLock(MS_U32 u32Start,MS_U32 u32End,CA_LOCK_TYPE eLockType)770 MS_BOOL MDrv_CA_OTP_SetBlockLock(MS_U32 u32Start, MS_U32 u32End, CA_LOCK_TYPE eLockType)
771 {
772 #ifdef CA_UTOPIA20
773 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
774 CA_OTP_SETBLOCKLOCK pArgs;
775 if(pu32CAInst == NULL)
776 {
777 return FALSE;
778 }
779
780 pArgs.u32Start = u32Start;
781 pArgs.u32End = u32End;
782 pArgs.eLockType = eLockType;
783
784 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_SetBlockLock, (void*)&pArgs);
785 if(UTOPIA_STATUS_SUCCESS != u32Ret)
786 {
787 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
788 return FALSE;
789 }
790
791 return TRUE;
792 #else
793 return _MDrv_CA_OTP_SetBlockLock(u32Start, u32End, eLockType);
794 #endif
795 }
796
MDrv_CA_OTP_GetBlockLock(MS_U32 * pu32Start,MS_U32 * pu32End,CA_LOCK_TYPE * peLockType)797 MS_BOOL MDrv_CA_OTP_GetBlockLock(MS_U32 *pu32Start, MS_U32 *pu32End, CA_LOCK_TYPE *peLockType)
798 {
799 #ifdef CA_UTOPIA20
800 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
801 CA_OTP_GETBLOCKLOCK pArgs;
802 if(pu32CAInst == NULL)
803 {
804 return FALSE;
805 }
806
807 pArgs.pu32Start = pu32Start;
808 pArgs.pu32End = pu32End;
809 pArgs.peLockType = peLockType;
810
811 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_GetBlockLock, (void*)&pArgs);
812 if(UTOPIA_STATUS_SUCCESS != u32Ret)
813 {
814 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
815 return FALSE;
816 }
817
818 return TRUE;
819 #else
820 return _MDrv_CA_OTP_GetBlockLock(pu32Start, pu32End, peLockType);
821 #endif
822 }
823
824 //-------------------------------------------------------------------------------------------------
825 /// @brief Check if the value is zero in OTP
826 /// @param[in] addr from 0x0000 to 0x1ffc
827 /// @return OTP value
828 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_IsBlank(MS_U32 addr)829 MS_BOOL MDrv_CA_OTP_IsBlank(MS_U32 addr)
830 {
831 #ifdef CA_UTOPIA20
832 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
833 CA_OTP_ISBLANK pArgs;
834 if(pu32CAInst == NULL)
835 {
836 return FALSE;
837 }
838
839 pArgs.u32addr = addr;
840
841 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_IsBlank, (void*)&pArgs);
842 if(UTOPIA_STATUS_SUCCESS != u32Ret)
843 {
844 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
845 return FALSE;
846 }
847
848 return TRUE;
849 #else
850 return _MDrv_CA_OTP_IsBlank(addr);
851 #endif
852 }
853
854 //-------------------------------------------------------------------------------------------------
855 /// @brief Read 32bits value from OTP
856 /// @param[in] addr from 0x0000 to 0x1ffc
857 /// @return OTP value
858 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_Read(MS_U32 addr)859 MS_U32 MDrv_CA_OTP_Read(MS_U32 addr)
860 {
861 #ifdef CA_UTOPIA20
862 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
863 CA_OTP_READ pArgs;
864 if(pu32CAInst == NULL)
865 {
866 return FALSE;
867 }
868
869 pArgs.u32Addr = addr;
870 pArgs.u32OTPValue = 0;
871
872 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_Read, (void*)&pArgs);
873 if(UTOPIA_STATUS_SUCCESS != u32Ret)
874 {
875 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
876 return FALSE;
877 }
878
879 return pArgs.u32OTPValue;
880 #else
881 return _MDrv_CA_OTP_Read(addr);
882 #endif
883 }
884
885 //-------------------------------------------------------------------------------------------------
886 /// @brief Write 32bits value to OTP
887 /// @param[in] addr from 0x0000 to 0x1ffc
888 /// @param[in] value
889 /// @return TRUE: Process success.
890 /// @return FALSE: Process fail.
891 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_Write(MS_U32 addr,MS_U32 value)892 MS_BOOL MDrv_CA_OTP_Write(MS_U32 addr, MS_U32 value)
893 {
894 #ifdef CA_UTOPIA20
895 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
896 CA_OTP_WRITE pArgs;
897 if(pu32CAInst == NULL)
898 {
899 return FALSE;
900 }
901
902 pArgs.u32Addr = addr;
903 pArgs.u32value = value;
904
905 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_Write, (void*)&pArgs);
906 if(UTOPIA_STATUS_SUCCESS != u32Ret)
907 {
908 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
909 return FALSE;
910 }
911
912 return TRUE;
913 #else
914 return _MDrv_CA_OTP_Write(addr, value);
915 #endif
916 }
917
918 //-------------------------------------------------------------------------------------------------
919 /// @brief Read the OTP Lock config
920 /// @param[in] eLock
921 /// @return TRUE: Locked.
922 /// @return FALSE: Not locked
923 //-------------------------------------------------------------------------------------------------
MDrv_CA_Locked(CA_OTP_LOCK eLock)924 MS_BOOL MDrv_CA_Locked(CA_OTP_LOCK eLock)
925 {
926 #ifdef CA_UTOPIA20
927 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
928 CA_OTP_LOCK20 pArgs;
929 if(pu32CAInst == NULL)
930 {
931 return FALSE;
932 }
933
934 pArgs.eLock = eLock;
935
936 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_Locked, (void*)&pArgs);
937 if(UTOPIA_STATUS_SUCCESS != u32Ret)
938 {
939 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
940 return FALSE;
941 }
942
943 return TRUE;
944 #else
945 return _MDrv_CA_Locked(eLock);
946 #endif
947 }
948
949 //-------------------------------------------------------------------------------------------------
950 /// @brief Lock OTP area
951 /// @param[in] eLock
952 /// @return TRUE: Process success.
953 /// @return FALSE: Process fail.
954 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_Lock(CA_OTP_LOCK eLock)955 MS_BOOL MDrv_CA_OTP_Lock(CA_OTP_LOCK eLock)
956 {
957 #ifdef CA_UTOPIA20
958 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
959 CA_OTP_LOCK20 pArgs;
960 if(pu32CAInst == NULL)
961 {
962 return FALSE;
963 }
964
965 pArgs.eLock = eLock;
966
967 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_Lock, (void*)&pArgs);
968 if(UTOPIA_STATUS_SUCCESS != u32Ret)
969 {
970 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
971 return FALSE;
972 }
973
974 return TRUE;
975 #else
976 return _MDrv_CA_OTP_Lock(eLock);
977 #endif
978 }
979
980 //-------------------------------------------------------------------------------------------------
981 /// @brief Set the value of the RSAextID in OTP
982 /// @return TRUE: Process success.
983 /// @return FALSE: Process fail.
984 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_SetRSAextID(MS_U32 u32Value)985 MS_BOOL MDrv_CA_OTP_SetRSAextID(MS_U32 u32Value)
986 {
987 #ifdef CA_UTOPIA20
988 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
989 CA_OTP_SETRSAEXTID pArgs;
990 if(pu32CAInst == NULL)
991 {
992 return FALSE;
993 }
994
995 pArgs.u32value= u32Value;
996
997 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_SetRSAextID, (void*)&pArgs);
998 if(UTOPIA_STATUS_SUCCESS != u32Ret)
999 {
1000 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1001 return FALSE;
1002 }
1003
1004 return TRUE;
1005 #else
1006 return _MDrv_CA_OTP_SetRSAextID(u32Value);
1007 #endif
1008 }
1009
1010 //-------------------------------------------------------------------------------------------------
1011 /// @brief Get the value of the RSAextID in OTP
1012 /// @return TRUE: Process success.
1013 /// @return FALSE: Process fail.
1014 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_GetRSAextID(void)1015 MS_U32 MDrv_CA_OTP_GetRSAextID(void)
1016 {
1017 #ifdef CA_UTOPIA20
1018 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1019 CA_OTP_GETRSAEXTID pArgs;
1020 if(pu32CAInst == NULL)
1021 {
1022 return FALSE;
1023 }
1024
1025 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_GetRSAextID, (void*)&pArgs);
1026 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1027 {
1028 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1029 return FALSE;
1030 }
1031
1032 return pArgs.u32value;
1033 #else
1034 return _MDrv_CA_OTP_GetRSAextID();
1035 #endif
1036 }
1037
1038 //-------------------------------------------------------------------------------------------------
1039 /// @brief Set the value of the TEE RSAextID in OTP
1040 /// @return TRUE: Process success.
1041 /// @return FALSE: Process fail.
1042 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_SetTEERSAextID(MS_U32 u32Value)1043 MS_BOOL MDrv_CA_OTP_SetTEERSAextID(MS_U32 u32Value)
1044 {
1045 // Not Implement
1046 DRV_CA_DEBUG("Not Implement\n");
1047 return FALSE;
1048 }
1049
1050 //-------------------------------------------------------------------------------------------------
1051 /// @brief Get the value of the TEE RSAextID in OTP
1052 /// @return TRUE: Process success.
1053 /// @return FALSE: Process fail.
1054 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_GetTEERSAextID(void)1055 MS_U32 MDrv_CA_OTP_GetTEERSAextID(void)
1056 {
1057 // Not Implement
1058 DRV_CA_DEBUG("Not Implement\n");
1059 return FALSE;
1060 }
1061
MDrv_CA_OTP_SetHASH1_REF_VER(MS_U32 u32HASH1_REF_VER)1062 MS_BOOL MDrv_CA_OTP_SetHASH1_REF_VER(MS_U32 u32HASH1_REF_VER)
1063 {
1064 #ifdef CA_UTOPIA20
1065 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1066 CA_OTP_SETHASH1REFVER pArgs;
1067 if(pu32CAInst == NULL)
1068 {
1069 return FALSE;
1070 }
1071
1072 pArgs.u32HASH1_REF_VER = u32HASH1_REF_VER;
1073
1074 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_SetHASH1_REF_VER, (void*)&pArgs);
1075 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1076 {
1077 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1078 return FALSE;
1079 }
1080
1081 return TRUE;
1082 #else
1083 return _MDrv_CA_OTP_SetHASH1_REF_VER(u32HASH1_REF_VER);
1084 #endif
1085 }
1086
MDrv_CA_OTP_GetHASH1_REF_VER(MS_U32 * pu32HASH1_REF_VER)1087 MS_BOOL MDrv_CA_OTP_GetHASH1_REF_VER(MS_U32 *pu32HASH1_REF_VER)
1088 {
1089 #ifdef CA_UTOPIA20
1090 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1091 CA_OTP_GETHASH1REFVER pArgs;
1092 if(pu32CAInst == NULL)
1093 {
1094 return FALSE;
1095 }
1096
1097 pArgs.pu32HASH1_REF_VER = pu32HASH1_REF_VER;
1098
1099 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_GetHASH1_REF_VER, (void*)&pArgs);
1100 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1101 {
1102 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1103 return FALSE;
1104 }
1105
1106 return TRUE;
1107 #else
1108 return _MDrv_CA_OTP_GetHASH1_REF_VER(pu32HASH1_REF_VER);
1109 #endif
1110 }
1111
1112
MDrv_CA_OTP_SetHASH_REF_VER(MS_U32 u32HASH0_REF_VER,MS_U32 u32HASH2_REF_VER)1113 MS_BOOL MDrv_CA_OTP_SetHASH_REF_VER(MS_U32 u32HASH0_REF_VER, MS_U32 u32HASH2_REF_VER)
1114 {
1115 #ifdef CA_UTOPIA20
1116 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1117 CA_OTP_SETHASHREFVER pArgs;
1118 if(pu32CAInst == NULL)
1119 {
1120 return FALSE;
1121 }
1122
1123 pArgs.u32HASH0_REF_VER = u32HASH0_REF_VER;
1124 pArgs.u32HASH2_REF_VER = u32HASH2_REF_VER;
1125
1126 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_SetHASH_REF_VER, (void*)&pArgs);
1127 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1128 {
1129 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1130 return FALSE;
1131 }
1132
1133 return TRUE;
1134 #else
1135 return _MDrv_CA_OTP_SetHASH_REF_VER(u32HASH0_REF_VER, u32HASH2_REF_VER);
1136 #endif
1137 }
1138
MDrv_CA_OTP_GetHASH_REF_VER(MS_U32 * pu32HASH0_REF_VER,MS_U32 * pu32HASH2_REF_VER)1139 MS_BOOL MDrv_CA_OTP_GetHASH_REF_VER(MS_U32 *pu32HASH0_REF_VER, MS_U32 *pu32HASH2_REF_VER)
1140 {
1141 #ifdef CA_UTOPIA20
1142 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1143 CA_OTP_GETHASHREFVER pArgs;
1144 if(pu32CAInst == NULL)
1145 {
1146 return FALSE;
1147 }
1148
1149 pArgs.pu32HASH0_REF_VER = pu32HASH0_REF_VER;
1150 pArgs.pu32HASH2_REF_VER = pu32HASH2_REF_VER;
1151
1152 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_GetHASH_REF_VER, (void*)&pArgs);
1153 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1154 {
1155 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1156 return FALSE;
1157 }
1158
1159 return TRUE;
1160 #else
1161 return _MDrv_CA_OTP_GetHASH_REF_VER(pu32HASH0_REF_VER, pu32HASH2_REF_VER);
1162 #endif
1163 }
1164
MDrv_CA_OTP_SetHASH_TEE_REF_VER(MS_U32 u32HASH_TEE0_REF_VER,MS_U32 u32HASH_TEE1_REF_VER,MS_U32 u32HASH_TEE2_REF_VER)1165 MS_BOOL MDrv_CA_OTP_SetHASH_TEE_REF_VER(MS_U32 u32HASH_TEE0_REF_VER, MS_U32 u32HASH_TEE1_REF_VER, MS_U32 u32HASH_TEE2_REF_VER)
1166 {
1167 // Not Implement
1168 DRV_CA_DEBUG("Not Implement\n");
1169 return FALSE;
1170 }
1171
MDrv_CA_OTP_GetHASH_TEE_REF_VER(MS_U32 * pu32HASH_TEE0_REF_VER,MS_U32 * pu32HASH_TEE1_REF_VER,MS_U32 * pu32HASH_TEE2_REF_VER)1172 MS_BOOL MDrv_CA_OTP_GetHASH_TEE_REF_VER(MS_U32 *pu32HASH_TEE0_REF_VER, MS_U32 *pu32HASH_TEE1_REF_VER, MS_U32 *pu32HASH_TEE2_REF_VER)
1173 {
1174 // Not Implement
1175 DRV_CA_DEBUG("Not Implement\n");
1176 return FALSE;
1177 }
1178
1179 //-------------------------------------------------------------------------------------------------
1180 /// @brief Set debug port mode
1181 /// @param[in] eDebugPort E_CA_DEBUG_PORT_I2C or E_CA_DEBUG_PORT_JTAG
1182 /// @param[in] eMode OPEN, PASSWORD_PROTECTED, or CLOSE
1183 /// @return TRUE: Process success.
1184 /// @return FALSE: Process fail.
1185 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_SetDebugPortMode(CA_DEBUG_PORT eDebugPort,CA_DEBUG_PORT_MODE eMode)1186 MS_BOOL MDrv_CA_OTP_SetDebugPortMode(CA_DEBUG_PORT eDebugPort, CA_DEBUG_PORT_MODE eMode)
1187 {
1188 #ifdef CA_UTOPIA20
1189 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1190 CA_OTP_SETDEBUGPORTMODE pArgs;
1191 if(pu32CAInst == NULL)
1192 {
1193 return FALSE;
1194 }
1195
1196 pArgs.eDebugPort = eDebugPort;
1197 pArgs.eMode = eMode;
1198
1199 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_SetDebugPortMode, (void*)&pArgs);
1200 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1201 {
1202 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1203 return FALSE;
1204 }
1205
1206 return TRUE;
1207 #else
1208 return _MDrv_CA_OTP_SetDebugPortMode(eDebugPort, eMode);
1209 #endif
1210 }
1211
1212
1213 //--------------------------------------------------------------------------------------------------
1214 /// Get debug port state from the shadow register
1215 /// @param[in] eDebugPort choose debug port
1216 /// @param[out] eMode the state of the eDebugPort
1217 /// @return TRUE: OK
1218 /// @return FALSE: Error
1219 /// @note
1220 //--------------------------------------------------------------------------------------------------
MDrv_CA_OTP_GetDebugPortMode(CA_DEBUG_PORT eDebugPort,CA_DEBUG_PORT_MODE * eMode)1221 MS_BOOL MDrv_CA_OTP_GetDebugPortMode(CA_DEBUG_PORT eDebugPort, CA_DEBUG_PORT_MODE *eMode)
1222 {
1223 #ifdef CA_UTOPIA20
1224 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1225 CA_OTP_GETDEBUGPORTMODE pArgs;
1226 if(pu32CAInst == NULL)
1227 {
1228 return FALSE;
1229 }
1230
1231 pArgs.eDebugPort = eDebugPort;
1232 pArgs.eMode = eMode;
1233
1234 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_GetDebugPortMode, (void*)&pArgs);
1235 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1236 {
1237 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1238 return FALSE;
1239 }
1240
1241 return TRUE;
1242 #else
1243 return _MDrv_CA_OTP_GetDebugPortMode(eDebugPort, eMode);
1244 #endif
1245 }
1246
1247 //-------------------------------------------------------------------------------------------------
1248 /// @brief Write the OTP Device ID
1249 /// @param[in] pu8Did a buffer to store the Device ID. In LSB first format
1250 /// @param[in] u32Size The size of the buffer
1251 /// @return TRUE: OK
1252 /// @return FALSE: Error
1253 /// @note: The device ID in the OTP is LSB first and this is a byte-to-byte copy API.
1254 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_SetDeviceId(const MS_U8 * pu8Did,MS_U32 u32Size)1255 MS_BOOL MDrv_CA_OTP_SetDeviceId(const MS_U8 *pu8Did, MS_U32 u32Size)
1256 {
1257 #ifdef CA_UTOPIA20
1258 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1259 CA_OTP_SETDEVICEID pArgs;
1260 if(pu32CAInst == NULL)
1261 {
1262 return FALSE;
1263 }
1264
1265 pArgs.pu8Did = pu8Did;
1266 pArgs.u32Size = u32Size;
1267
1268 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_SetDeviceId, (void*)&pArgs);
1269 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1270 {
1271 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1272 return FALSE;
1273 }
1274
1275 return TRUE;
1276 #else
1277 return _MDrv_CA_OTP_SetDeviceId(pu8Did, u32Size);
1278 #endif
1279 }
1280
1281 //-------------------------------------------------------------------------------------------------
1282 /// @brief Read the OTP Device ID
1283 /// @param[out] pu8Did a buffer to store the Device ID. In LSB first format
1284 /// @param[in] u32Size The size of the buffer
1285 /// @return TRUE: OK
1286 /// @return FALSE: Error
1287 /// @note: The device ID in the OTP is LSB first and this is a byte-to-byte copy API.
1288 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_GetDeviceId(MS_U8 * pu8Did,MS_U32 u32Size)1289 MS_BOOL MDrv_CA_OTP_GetDeviceId(MS_U8 *pu8Did, MS_U32 u32Size)
1290 {
1291 #ifdef CA_UTOPIA20
1292 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1293 CA_OTP_GETDEVICEID pArgs;
1294 if(pu32CAInst == NULL)
1295 {
1296 return FALSE;
1297 }
1298
1299 pArgs.pu8Did = pu8Did;
1300 pArgs.u32Size = u32Size;
1301
1302 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_GetDeviceId, (void*)&pArgs);
1303 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1304 {
1305 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1306 return FALSE;
1307 }
1308
1309 return TRUE;
1310 #else
1311 return _MDrv_CA_OTP_GetDeviceId(pu8Did, u32Size);
1312 #endif
1313 }
1314
1315
1316 //--------------------------------------------------------------------------------------------------
1317 /// @brief The MAX size of the Device ID
1318 /// @return TRUE: OK
1319 /// @return FALSE: Error
1320
1321 /// @note
1322 //--------------------------------------------------------------------------------------------------
MDrv_CA_MaxDeviceIdSize(void)1323 MS_U32 MDrv_CA_MaxDeviceIdSize(void)
1324 {
1325 #ifdef CA_UTOPIA20
1326 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1327 CA_MAXDEVICEIDSIZE pArgs;
1328 if(pu32CAInst == NULL)
1329 {
1330 return FALSE;
1331 }
1332
1333 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_MaxDeviceIdSize, (void*)&pArgs);
1334 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1335 {
1336 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1337 return FALSE;
1338 }
1339
1340 return pArgs.u32MaxDeviceIdSize;
1341 #else
1342 return _MDrv_CA_MaxDeviceIdSize();
1343 #endif
1344 }
1345
1346 //-------------------------------------------------------------------------------------------------
1347 /// @brief Write the OTP reserved area
1348 /// @param[in] pu8RData a buffer to write the reserved area.
1349 /// @param[in] u32Size The size of the buffer
1350 /// @return TRUE: OK
1351 /// @return FALSE: Error
1352 /// @note:
1353 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_WriteReserved(const MS_U8 * pu8RData,MS_U32 u32Size)1354 MS_BOOL MDrv_CA_OTP_WriteReserved(const MS_U8 *pu8RData, MS_U32 u32Size)
1355 {
1356 DRV_CA_INIT_CHECK(FALSE);
1357 return HAL_CA_OTP_WriteReserved(pu8RData, u32Size);
1358 }
1359
1360 //-------------------------------------------------------------------------------------------------
1361 /// @brief Read the OTP reserved area
1362 /// @param[out] pu8RData a buffer to read the reserved area.
1363 /// @param[in] u32Size The size of the buffer
1364 /// @return TRUE: OK
1365 /// @return FALSE: Error
1366 /// @note:
1367 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_ReadReserved(MS_U8 * pu8RData,MS_U32 u32Size)1368 MS_BOOL MDrv_CA_OTP_ReadReserved(MS_U8 *pu8RData, MS_U32 u32Size)
1369 {
1370 DRV_CA_INIT_CHECK(FALSE);
1371 return HAL_CA_OTP_ReadReserved(pu8RData, u32Size);
1372 }
1373
1374 //--------------------------------------------------------------------------------------------------
1375 /// @brief The MAX size of the reserved area
1376 /// @return the MAX size of the reserved area
1377 /// @note
1378 //--------------------------------------------------------------------------------------------------
MDrv_CA_MaxReservedSize(void)1379 MS_U32 MDrv_CA_MaxReservedSize(void)
1380 {
1381 DRV_CA_INIT_CHECK(FALSE);
1382 return HAL_CA_MaxReservedSize();
1383 }
1384
1385 //--------------------------------------------------------------------------------------------------
1386 /// @brief Set ACPU cannot write clear CW to key table
1387 /// @return TRUE: OK
1388 /// @return FALSE: Error
1389 /// @note
1390 //--------------------------------------------------------------------------------------------------
MDrv_CA_OTP_EnableSecureCWMode(void)1391 MS_BOOL MDrv_CA_OTP_EnableSecureCWMode(void)
1392 {
1393 #ifdef CA_UTOPIA20
1394 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1395
1396 if(pu32CAInst == NULL)
1397 {
1398 return FALSE;
1399 }
1400
1401 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_EnableSecureCWMode, NULL);
1402 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1403 {
1404 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1405 return FALSE;
1406 }
1407
1408 return TRUE;
1409 #else
1410 return _MDrv_CA_OTP_EnableSecureCWMode();
1411 #endif
1412 }
1413
1414 //--------------------------------------------------------------------------------------------------
1415 /// @brief Check if ACPU can write clear CW to key table
1416 /// @return TRUE: OK
1417 /// @return FALSE: Error
1418 /// @note
1419 //--------------------------------------------------------------------------------------------------
MDrv_CA_OTP_IsSecureCWMode(void)1420 MS_BOOL MDrv_CA_OTP_IsSecureCWMode(void)
1421 {
1422 #ifdef CA_UTOPIA20
1423 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1424
1425 if(pu32CAInst == NULL)
1426 {
1427 return FALSE;
1428 }
1429
1430 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_IsSecureCWMode, NULL);
1431 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1432 {
1433 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1434 return FALSE;
1435 }
1436
1437 return TRUE;
1438 #else
1439 return _MDrv_CA_OTP_IsSecureCWMode();
1440 #endif
1441 }
1442
1443 //-------------------------------------------------------------------------------------------------
1444 /// 16bits Hardware random number generator
1445 /// @return 16-bits random number
1446 //-------------------------------------------------------------------------------------------------
MDrv_CA_Random(void)1447 MS_U32 MDrv_CA_Random(void)
1448 {
1449 #ifdef CA_UTOPIA20
1450 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1451 CA_RANDOM pArgs;
1452 if(pu32CAInst == NULL)
1453 {
1454 return FALSE;
1455 }
1456
1457 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_Random, (void*)&pArgs);
1458 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1459 {
1460 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1461 return FALSE;
1462 }
1463
1464 return pArgs.u32Random;
1465 #else
1466 return _MDrv_CA_Random();
1467 #endif
1468 }
1469
MDrv_CA_OTP_ReadCAVendor(void)1470 MS_U32 MDrv_CA_OTP_ReadCAVendor(void)
1471 {
1472 #ifdef CA_UTOPIA20
1473 MS_U32 u32Ret = UTOPIA_STATUS_SUCCESS;
1474 CA_OTP_READCAVENDOR pArgs;
1475 if(pu32CAInst == NULL)
1476 {
1477 return FALSE;
1478 }
1479
1480 u32Ret = UtopiaIoctl(pu32CAInst, E_MDRV_CMD_CA_OTP_ReadCAVendor, (void*)&pArgs);
1481 if(UTOPIA_STATUS_SUCCESS != u32Ret)
1482 {
1483 MS_DEBUG_MSG(printf("[%s]ERROR : UtopiaIoctl return value 0x%x\n", __FUNCTION__, (unsigned int)u32Ret));
1484 return FALSE;
1485 }
1486
1487 return pArgs.u32CAVendor;
1488 #else
1489 return _MDrv_CA_OTP_ReadCAVendor();
1490 #endif
1491 }
1492
MDrv_CA_STR_Init(void)1493 MS_BOOL MDrv_CA_STR_Init(void)
1494 {
1495 MS_VIRT virtRegBank;
1496 MS_PHY u32BankSize;
1497
1498
1499 if(FALSE == MDrv_MMIO_GetBASE(&virtRegBank, &u32BankSize, MS_MODULE_PM))
1500 {
1501 DRV_CA_DEBUG("Error:MDrv_MMIO_GetBASE fail\n");
1502 return FALSE;
1503 }
1504
1505 HAL_CA_STR_SetBank(virtRegBank);
1506 HAL_CA_STR_EnableKey(); //Catch PM signature nonce
1507 HAL_CA_STR_EnableWarmBoot(); //Set magic number
1508
1509 _bCASTRDrv_Inited = TRUE;
1510
1511 return TRUE;
1512
1513 }
1514
MDrv_CA_STR_SetParamAddr(MS_U8 * pu8BAddr)1515 MS_BOOL MDrv_CA_STR_SetParamAddr(MS_U8 *pu8BAddr)
1516 {
1517 DRV_CASTR_INIT_CHECK(FALSE);
1518
1519 if(NULL == pu8BAddr)
1520 {
1521 DRV_CA_DEBUG("Error:pu8BAddr is NULL\n");
1522 return FALSE;
1523 }
1524
1525 //Set STR param stored bus address, used bySCS
1526 HAL_CA_STR_SetParamAddr(pu8BAddr);
1527
1528 return TRUE;
1529
1530 }
1531
MDrv_CA_STR_SetMAC(MS_U8 * pu8MAC,MS_U32 u32MACSize)1532 MS_BOOL MDrv_CA_STR_SetMAC(MS_U8 *pu8MAC, MS_U32 u32MACSize)
1533 {
1534 DRV_CASTR_INIT_CHECK(FALSE);
1535
1536 if(NULL == pu8MAC)
1537 {
1538 DRV_CA_DEBUG("Error:pu8STRMAC is NULL\n");
1539 return FALSE;
1540 }
1541
1542 if((0 == u32MACSize) || (32 < u32MACSize))
1543 {
1544 DRV_CA_DEBUG("Error:u32STRMACSize = [%u] is not correct\n", u32MACSize);
1545 return FALSE;
1546 }
1547
1548 //Set MAC to PM
1549 HAL_CA_STR_SetMAC(pu8MAC, u32MACSize);
1550
1551 return TRUE;
1552
1553 }
1554
MDrv_CA_OTP_DumpKeyProperty(MS_U32 u32KeyNumber)1555 MS_BOOL MDrv_CA_OTP_DumpKeyProperty(MS_U32 u32KeyNumber)
1556 {
1557 // Not Implement
1558 DRV_CA_DEBUG("Not Implement\n");
1559 return FALSE;
1560 }
1561
1562 //-------------------------------------------------------------------------------------------------
1563 /// @brief Write the OTP CAV_SecretKey
1564 /// @param[in] eKeySel select from SecretKey1 ~ SecretKey8
1565 /// @param[in] pu8SecretKey a buffer to store the CAV_SecretKey. In MSB first format
1566 /// @param[in] u32Size The size of the buffer
1567 /// @return TRUE: OK
1568 /// @return FALSE: Error
1569 /// @note: The CAV_SecretKey in the OTP is MSB first and this is a byte-to-byte copy API.
1570 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_SetSecretKey(CA_SECRET_KEY eKeySel,const MS_U8 * pu8SecretKey,MS_U32 u32Size)1571 MS_BOOL MDrv_CA_OTP_SetSecretKey(CA_SECRET_KEY eKeySel, const MS_U8 *pu8SecretKey, MS_U32 u32Size)
1572 {
1573 DRV_CA_INIT_CHECK(FALSE);
1574 return HAL_CA_OTP_SetSecretKey(eKeySel, pu8SecretKey, u32Size);
1575 }
1576
1577 //-------------------------------------------------------------------------------------------------
1578 /// @brief Read the OTP CAV_SecretKey
1579 /// @param[in] eKeySel select from SecretKey1 ~ SecretKey8
1580 /// @param[out] pu8SecretKey a buffer to store the CAV_SecretKey. In MSB first format
1581 /// @param[in] u32Size The size of the buffer
1582 /// @return TRUE: OK
1583 /// @return FALSE: Error
1584 /// @note: The device ID in the OTP is MSB first and this is a byte-to-byte copy API.
1585 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_GetSecretKey(CA_SECRET_KEY eKeySel,MS_U8 * pu8SecretKey,MS_U32 u32Size)1586 MS_BOOL MDrv_CA_OTP_GetSecretKey(CA_SECRET_KEY eKeySel, MS_U8 *pu8SecretKey, MS_U32 u32Size)
1587 {
1588 DRV_CA_INIT_CHECK(FALSE);
1589 return HAL_CA_OTP_GetSecretKey(eKeySel, pu8SecretKey, u32Size);
1590 }
1591
1592 //-------------------------------------------------------------------------------------------------
1593 /// @brief Write the OTP RSAKey
1594 /// @param[in] eKeySel select from RSAKey0 or RSAKey1
1595 /// @param[in] pu8RSAKey a buffer to store the RSAKey. In LSB first format
1596 /// @param[in] u32Size The size of the buffer
1597 /// @return TRUE: OK
1598 /// @return FALSE: Error
1599 /// @note: The RSAKey in the OTP is LSB first and this is a byte-to-byte copy API.
1600 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_SetRSAKey(CA_RSA_KEY eKeySel,const MS_U8 * pu8RSAKey,MS_U32 u32Size)1601 MS_BOOL MDrv_CA_OTP_SetRSAKey(CA_RSA_KEY eKeySel, const MS_U8 *pu8RSAKey, MS_U32 u32Size)
1602 {
1603 DRV_CA_INIT_CHECK(FALSE);
1604 return HAL_CA_OTP_SetRSAKey(eKeySel, pu8RSAKey, u32Size);
1605 }
1606
1607 //-------------------------------------------------------------------------------------------------
1608 /// @brief Read the OTP RSAKey
1609 /// @param[in] eKeySel select from RSAKey0 or RSAKey1
1610 /// @param[out] pu8RSAKey a buffer to store the RSAKey. In LSB first format
1611 /// @param[in] u32Size The size of the buffer
1612 /// @return TRUE: OK
1613 /// @return FALSE: Error
1614 /// @note: The RSAKey in the OTP is LSB first and this is a byte-to-byte copy API.
1615 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_GetRSAKey(CA_RSA_KEY eKeySel,MS_U8 * pu8RSAKey,MS_U32 u32Size)1616 MS_BOOL MDrv_CA_OTP_GetRSAKey(CA_RSA_KEY eKeySel, MS_U8 *pu8RSAKey, MS_U32 u32Size)
1617 {
1618 DRV_CA_INIT_CHECK(FALSE);
1619 return HAL_CA_OTP_GetRSAKey(eKeySel, pu8RSAKey, u32Size);
1620 }
1621
1622 //-------------------------------------------------------------------------------------------------
1623 /// @brief Write the OTP DebugPort Password
1624 /// @param[in] eDebugPort choose debug port
1625 /// @param[in] pu8Password a buffer to store the DebugPort Password. In MSB first format
1626 /// @param[in] u32Size The size of the buffer
1627 /// @return TRUE: OK
1628 /// @return FALSE: Error
1629 /// @note: The DebugPort Password in the OTP is MSB first and this is a byte-to-byte copy API.
1630 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_SetDebugPortPassword(CA_DEBUG_PORT eDebugPort,const MS_U8 * pu8Password,MS_U32 u32Size)1631 MS_BOOL MDrv_CA_OTP_SetDebugPortPassword(CA_DEBUG_PORT eDebugPort, const MS_U8 *pu8Password, MS_U32 u32Size)
1632 {
1633 DRV_CA_INIT_CHECK(FALSE);
1634 return HAL_CA_OTP_SetDebugPortPassword(eDebugPort, pu8Password, u32Size);
1635 }
1636
1637 //-------------------------------------------------------------------------------------------------
1638 /// @brief Read the OTP DebugPort Password
1639 /// @param[in] eDebugPort choose debug port
1640 /// @param[out] pu8Password a buffer to store the DebugPort Password. In MSB first format
1641 /// @param[in] u32Size The size of the buffer
1642 /// @return TRUE: OK
1643 /// @return FALSE: Error
1644 /// @note: The DebugPort Password in the OTP is MSB first and this is a byte-to-byte copy API.
1645 //-------------------------------------------------------------------------------------------------
MDrv_CA_OTP_GetDebugPortPassword(CA_DEBUG_PORT eDebugPort,MS_U8 * pu8Password,MS_U32 u32Size)1646 MS_BOOL MDrv_CA_OTP_GetDebugPortPassword(CA_DEBUG_PORT eDebugPort, MS_U8 *pu8Password, MS_U32 u32Size)
1647 {
1648 DRV_CA_INIT_CHECK(FALSE);
1649 return HAL_CA_OTP_GetDebugPortPassword(eDebugPort, pu8Password, u32Size);
1650 }
1651