1 /**
2 * \ingroup <FILEGROUP>
3 *
4 * \file BlowFuseXv2.c
5 *
6 * \brief Blow JTAG security fuse
7 *
8 */
9 /*
10  * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
11  *
12  *
13  *  Redistribution and use in source and binary forms, with or without
14  *  modification, are permitted provided that the following conditions
15  *  are met:
16  *
17  *    Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  *
20  *    Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the
23  *    distribution.
24  *
25  *    Neither the name of Texas Instruments Incorporated nor the names of
26  *    its contributors may be used to endorse or promote products derived
27  *    from this software without specific prior written permission.
28  *
29  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
42 #include "arch.h"
43 #include "edt.h"
44 #include "hal.h"
45 #include "stream.h"
46 #include "hal_ref.h"
47 #include "error_def.h"
48 #ifdef DB_PRINT
49 #include "debug.h"
50 #endif
51 
52 /**
53   BlowFuse
54   Blow JTAG security fuse.
55   After calling this function JTAG access is not possible anymore.
56   inData:  <tgtHasTest(8)>
57   outData: -
58   tgtHasTest: specifies if target device has TEST pin or not (bool)
59 */
60 
61 extern unsigned long JTAGLock5xx;
62 
63 //! \todo implementation & rename to jtag access protection
64 #if defined(MSP430_UIF) || defined(MSP_FET)
HAL_FUNCTION(_hal_BlowFuseXv2)65 HAL_FUNCTION(_hal_BlowFuseXv2)
66 {
67     short ret_value = 0;
68     short bslValue = 0;
69     StreamSafe stream_tmp;
70     unsigned char stream_in_tmp[26];
71     unsigned short i =0;
72 
73     WriteMemWordXv2(0x182, 0x0003);
74     bslValue = ReadMemWordXv2(0x182);
75 
76     if( (bslValue & 0x8000) == 0 )
77     {
78         // Coppy incoming stream to forward it to HAL_ExecuteFuncletXv2
79         for(i=0;i<(sizeof(stream_in_tmp) - 4);i++)
80         {
81             STREAM_get_byte(&stream_in_tmp[i]);
82         }
83         // add Password to stream
84         stream_in_tmp[i]   = (unsigned char) (JTAGLock5xx & 0xFF);
85         stream_in_tmp[i+1] = (unsigned char) ((JTAGLock5xx >> 8) & 0xFF);
86         stream_in_tmp[i+2] = (unsigned char) ((JTAGLock5xx >> 16) & 0xFF);
87         stream_in_tmp[i+3] = (unsigned char) ((JTAGLock5xx >> 24) & 0xFF);
88 
89         // Write password into device
90         STREAM_internal_stream(stream_in_tmp, sizeof(stream_in_tmp), MESSAGE_OUT_TO_DLL, 0, &stream_tmp);
91         HAL_ExecuteFuncletXv2(MESSAGE_NEW_MSG | MESSAGE_LAST_MSG); // Data from DLL Stream
92         STREAM_external_stream(&stream_tmp);
93 
94         // now perform a BOR via JTAG - we loose control of the device then...
95         test_reg();
96         SetReg_32Bits(0x00000200);
97     }
98     else
99     {
100          ret_value = HALERR_UNDEFINED_ERROR;
101     }
102     return ret_value;
103 }
104 #endif
105 
106 #ifdef eZ_FET
HAL_FUNCTION(_hal_BlowFuseXv2)107 HAL_FUNCTION(_hal_BlowFuseXv2)
108 {
109     // fuseblow is not supported on eZ-FET
110     return API_CALL_NOT_SUPPORTED;
111 }
112 #endif
113