ASR_BASE
Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/marvell/uboot/lib/sha256.c b/marvell/uboot/lib/sha256.c
new file mode 100644
index 0000000..a294fb2
--- /dev/null
+++ b/marvell/uboot/lib/sha256.c
@@ -0,0 +1,119 @@
+#include <common.h>
+#include <watchdog.h>
+#include <linux/string.h>
+#include <sha256.h>
+#include <tee.h>
+#include <asm/arch/cpu.h>
+
+void sha256_starts(sha256_context * ctx)
+{
+#ifdef CONFIG_ASR_TE200
+ if (cpu_is_asr1903_b0()) {
+ #ifdef CONFIG_TEE_OS
+ sha256_starts_optee(ctx);
+ if (ctx->tee_sha256 == TEE_SUCCESS)
+ return;
+ #else
+ return sha256_starts_te200(ctx);
+ #endif
+ }
+#endif
+
+#ifdef CONFIG_ASR_BCM
+ if (cpu_is_asr1901() || cpu_is_asr1906()) {
+ #ifdef CONFIG_TEE_OS
+ sha256_starts_optee(ctx);
+ if (ctx->tee_sha256 == TEE_SUCCESS)
+ return;
+ #else
+ return sha256_starts_bcm(ctx);
+ #endif
+ }
+#endif
+
+ return sha256_starts_neon(ctx);
+}
+
+void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length)
+{
+#ifdef CONFIG_ASR_TE200
+ if (cpu_is_asr1903_b0()) {
+ #ifdef CONFIG_TEE_OS
+ if (ctx->tee_sha256 == TEE_SUCCESS)
+ return sha256_update_optee(ctx, input, length);
+ #else
+ return sha256_update_te200(ctx, input, length);
+ #endif
+ }
+#endif
+
+#ifdef CONFIG_ASR_BCM
+ if (cpu_is_asr1901() || cpu_is_asr1906()) {
+ #ifdef CONFIG_TEE_OS
+ if (ctx->tee_sha256 == TEE_SUCCESS)
+ return sha256_update_optee(ctx, input, length);
+ #else
+ return sha256_update_bcm(ctx, input, length);
+ #endif
+ }
+#endif
+
+ return sha256_update_neon(ctx, input, length);
+}
+
+void sha256_finish(sha256_context * ctx, uint8_t digest[32])
+{
+#ifdef CONFIG_ASR_TE200
+ if (cpu_is_asr1903_b0()) {
+ #ifdef CONFIG_TEE_OS
+ if (ctx->tee_sha256 == TEE_SUCCESS)
+ return sha256_finish_optee(ctx, digest);
+ #else
+ return sha256_finish_te200(ctx, digest);
+ #endif
+ }
+#endif
+
+#ifdef CONFIG_ASR_BCM
+ if (cpu_is_asr1901() || cpu_is_asr1906()) {
+ #ifdef CONFIG_TEE_OS
+ if (ctx->tee_sha256 == TEE_SUCCESS)
+ return sha256_finish_optee(ctx, digest);
+ #else
+ return sha256_finish_bcm(ctx, digest);
+ #endif
+ }
+#endif
+
+ return sha256_finish_neon(ctx, digest);
+}
+
+
+void sha256_csum_wd(const unsigned char *input, unsigned int ilen,
+ unsigned char *output, unsigned int chunk_sz)
+{
+ sha256_context ctx;
+#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+ unsigned char *end, *curr;
+ int chunk;
+#endif
+
+ sha256_starts(&ctx);
+
+#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+ curr = input;
+ end = input + ilen;
+ while (curr < end) {
+ chunk = end - curr;
+ if (chunk > chunk_sz)
+ chunk = chunk_sz;
+ sha256_update(&ctx, curr, chunk);
+ curr += chunk;
+ WATCHDOG_RESET();
+ }
+#else
+ sha256_update(&ctx, input, ilen);
+#endif
+
+ sha256_finish(&ctx, output);
+}