Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/soc/kfuse.c
1476 views
1
/*
2
* Copyright (c) 2018 naehrwert
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms and conditions of the GNU General Public License,
6
* version 2, as published by the Free Software Foundation.
7
*
8
* This program is distributed in the hope it will be useful, but WITHOUT
9
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11
* more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*/
16
17
#include <soc/kfuse.h>
18
#include <soc/clock.h>
19
#include <soc/t210.h>
20
21
int kfuse_wait_ready()
22
{
23
// Wait for KFUSE to finish init and verification of data.
24
while (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_DONE))
25
;
26
27
if (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_CRCPASS))
28
return 0;
29
30
return 1;
31
}
32
33
int kfuse_read(u32 *buf)
34
{
35
int res = 0;
36
37
clock_enable_kfuse();
38
39
if (!kfuse_wait_ready())
40
goto out;
41
42
KFUSE(KFUSE_KEYADDR) = KFUSE_KEYADDR_AUTOINC;
43
for (int i = 0; i < KFUSE_NUM_WORDS; i++)
44
buf[i] = KFUSE(KFUSE_KEYS);
45
46
res = 1;
47
48
out:
49
clock_disable_kfuse();
50
return res;
51
}
52
53