diff --git a/bootloader/sec/tsec.c b/bootloader/sec/tsec.c index 28ecafa..6c97a81 100644 --- a/bootloader/sec/tsec.c +++ b/bootloader/sec/tsec.c @@ -23,6 +23,7 @@ #include "../sec/se_t210.h" #include "../soc/bpmp.h" #include "../soc/clock.h" +#include "../soc/kfuse.h" #include "../soc/smmu.h" #include "../soc/t210.h" #include "../mem/heap.h" @@ -78,6 +79,8 @@ int tsec_query(u8 *tsec_keys, u8 kb, tsec_ctxt_t *tsec_ctxt) clock_enable_sor1(); clock_enable_kfuse(); + kfuse_wait_ready(); + // Configure Falcon. TSEC(TSEC_DMACTL) = 0; TSEC(TSEC_IRQMSET) = diff --git a/bootloader/soc/kfuse.c b/bootloader/soc/kfuse.c index cd42309..f2fde5a 100644 --- a/bootloader/soc/kfuse.c +++ b/bootloader/soc/kfuse.c @@ -21,16 +21,25 @@ #pragma GCC push_options #pragma GCC optimize ("Os") +int kfuse_wait_ready() +{ + // Wait for KFUSE to finish init and verification of data. + while (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_DONE)) + ; + + if (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_CRCPASS)) + return 0; + + return 1; +} + int kfuse_read(u32 *buf) { int res = 0; clock_enable_kfuse(); - while (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_DONE)) - ; - - if (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_CRCPASS)) + if (!kfuse_wait_ready()) goto out; KFUSE(KFUSE_KEYADDR) = KFUSE_KEYADDR_AUTOINC; diff --git a/bootloader/soc/kfuse.h b/bootloader/soc/kfuse.h index f3d4903..a535803 100644 --- a/bootloader/soc/kfuse.h +++ b/bootloader/soc/kfuse.h @@ -36,6 +36,7 @@ #define KFUSE_NUM_WORDS 144 +int kfuse_wait_ready(); int kfuse_read(u32 *buf); #endif diff --git a/nyx/nyx_gui/sec/tsec.c b/nyx/nyx_gui/sec/tsec.c index 28ecafa..6c97a81 100644 --- a/nyx/nyx_gui/sec/tsec.c +++ b/nyx/nyx_gui/sec/tsec.c @@ -23,6 +23,7 @@ #include "../sec/se_t210.h" #include "../soc/bpmp.h" #include "../soc/clock.h" +#include "../soc/kfuse.h" #include "../soc/smmu.h" #include "../soc/t210.h" #include "../mem/heap.h" @@ -78,6 +79,8 @@ int tsec_query(u8 *tsec_keys, u8 kb, tsec_ctxt_t *tsec_ctxt) clock_enable_sor1(); clock_enable_kfuse(); + kfuse_wait_ready(); + // Configure Falcon. TSEC(TSEC_DMACTL) = 0; TSEC(TSEC_IRQMSET) = diff --git a/nyx/nyx_gui/soc/kfuse.c b/nyx/nyx_gui/soc/kfuse.c index 16a7dbc..a02acda 100644 --- a/nyx/nyx_gui/soc/kfuse.c +++ b/nyx/nyx_gui/soc/kfuse.c @@ -18,16 +18,25 @@ #include "../soc/clock.h" #include "../soc/t210.h" +int kfuse_wait_ready() +{ + // Wait for KFUSE to finish init and verification of data. + while (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_DONE)) + ; + + if (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_CRCPASS)) + return 0; + + return 1; +} + int kfuse_read(u32 *buf) { int res = 0; clock_enable_kfuse(); - while (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_DONE)) - ; - - if (!(KFUSE(KFUSE_STATE) & KFUSE_STATE_CRCPASS)) + if (!kfuse_wait_ready()) goto out; KFUSE(KFUSE_KEYADDR) = KFUSE_KEYADDR_AUTOINC; diff --git a/nyx/nyx_gui/soc/kfuse.h b/nyx/nyx_gui/soc/kfuse.h index f3d4903..a535803 100644 --- a/nyx/nyx_gui/soc/kfuse.h +++ b/nyx/nyx_gui/soc/kfuse.h @@ -36,6 +36,7 @@ #define KFUSE_NUM_WORDS 144 +int kfuse_wait_ready(); int kfuse_read(u32 *buf); #endif