tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / property / secure_efuse.c
1 /*
2  * Copyright (C) 2014 Spreadtrum Communications Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16
17 #include "efuse_operate.h"
18 #include "secure_efuse.h"
19
20 extern int get_spl_hash(void* hash_data);
21
22 int secure_efuse_program(void){
23
24   int ret = 0;
25   //printf("secure efuse ------------------------\n");
26   ret = calc_sha1_write_efuse();
27   if(ret)
28     return SHA1_ERR;
29   return PROG_OK;
30 }
31
32 int calc_sha1_write_efuse(void){
33
34   union sha_1{
35     unsigned char sha1_char[24];
36     unsigned int  sha1_int[6];
37   }sha1;
38
39   char sha1_string[41];
40   int ret = 0;
41   memset(&sha1,   0x0, 24);
42   memset(sha1_string,   0x0, 41);
43 //  -----   generate SHA1 key   -----
44   get_spl_hash((void*)sha1.sha1_char);
45   /*sprintf(sha1_string,"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", sha1.sha1_char[0],
46                                 sha1.sha1_char[1],
47                                 sha1.sha1_char[2],
48                                 sha1.sha1_char[3],
49                                 sha1.sha1_char[4],
50                                 sha1.sha1_char[5],
51                                 sha1.sha1_char[6],
52                                 sha1.sha1_char[7],
53                                 sha1.sha1_char[8],
54                                 sha1.sha1_char[9],
55                                 sha1.sha1_char[10],
56                                 sha1.sha1_char[11],
57                                 sha1.sha1_char[12],
58                                 sha1.sha1_char[13],
59                                 sha1.sha1_char[14],
60                                 sha1.sha1_char[15],
61                                 sha1.sha1_char[16],
62                                 sha1.sha1_char[17],
63                                 sha1.sha1_char[18],
64                                 sha1.sha1_char[19]);*/
65   sprintf(sha1_string,"%08x%08x%08x%08x%08x", sha1.sha1_int[0],
66                                 sha1.sha1_int[1],
67                                 sha1.sha1_int[2],
68                                 sha1.sha1_int[3],
69                                 sha1.sha1_int[4]);
70 //  -----   write SHA1 key Efuse   -----
71   ret = efuse_hash_write_1(sha1_string, 40);
72   if(ret < 0){
73     printf("sha1 efuse write Error [%d]\n", ret);
74     return SHA1_ERR;
75   }
76 //
77   if ( efuse_secure_is_enabled() ){
78     printf("enabled\n");
79     return PROG_OK;
80   }
81   efuse_secure_enable();
82 /*
83   char sha2_string[41];
84   memset(sha2_string,   0x0, 41);
85   efuse_hash_read_1(sha2_string, 40);
86   printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n~~~~~~~[%s]\n~~~~~~~~~~~~~~~~~~~~~~~\n", sha2_string);
87 */
88   return PROG_OK;
89 }
90
91
92
93
94
95
96