diff options
author | Ji Luo <ji.luo@nxp.com> | 2018-10-29 11:51:34 +0800 |
---|---|---|
committer | Nitin Garg <nitin.garg@nxp.com> | 2018-11-02 20:50:09 -0500 |
commit | 86b33989f42cc97ef16dd8e57c26eb0fc96224c1 (patch) | |
tree | a73f20283a04fbc983ed1c012921b8acd9e60391 /lib | |
parent | ced616aa4adcde2b4712ff8070cd0f6df9e7bdb5 (diff) |
MA-13234 [Auto] Calculate SHA256 hash with CAAM
Use CAAM to accelerate SHA256 hash calculation in AVB,
this will reduce u-boot boot time, about 570ms can be
saved for imx8qxp.
Test: Build and boot ok for imx8qxp.
Change-Id: Idbbd781e5ad8e7d6cd8865190d7547c165d02190
Signed-off-by: Ji Luo <ji.luo@nxp.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/avb/libavb/avb_slot_verify.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/avb/libavb/avb_slot_verify.c b/lib/avb/libavb/avb_slot_verify.c index 64e2666643..4f2e3ce64f 100644 --- a/lib/avb/libavb/avb_slot_verify.c +++ b/lib/avb/libavb/avb_slot_verify.c @@ -33,6 +33,10 @@ #include "avb_util.h" #include "avb_vbmeta_image.h" #include "avb_version.h" +#if defined(CONFIG_IMX_TRUSTY_OS) && defined(CONFIG_ANDROID_AUTO_SUPPORT) +#include "trusty/hwcrypto.h" +#include <memalign.h> +#endif /* Maximum number of partitions that can be loaded with avb_slot_verify(). */ #define MAX_NUMBER_OF_LOADED_PARTITIONS 32 @@ -294,11 +298,41 @@ static AvbSlotVerifyResult load_and_verify_hash_partition( } if (avb_strcmp((const char*)hash_desc.hash_algorithm, "sha256") == 0) { +#if defined(CONFIG_IMX_TRUSTY_OS) && defined(CONFIG_ANDROID_AUTO_SUPPORT) + /* DMA requires cache aligned input/output buffer */ + ALLOC_CACHE_ALIGN_BUFFER(uint8_t, hash_out, AVB_SHA256_DIGEST_SIZE); + uint32_t round_buf_size = ROUND(hash_desc.salt_len + hash_desc.image_size, + ARCH_DMA_MINALIGN); + uint8_t *hash_buf = memalign(ARCH_DMA_MINALIGN, round_buf_size); + if (hash_buf == NULL) { + avb_error("failed to alloc memory!\n"); + return AVB_SLOT_VERIFY_RESULT_ERROR_OOM; + goto out; + } + + avb_memcpy(hash_buf, desc_salt, hash_desc.salt_len); + avb_memcpy(hash_buf + hash_desc.salt_len, + image_buf, hash_desc.image_size); + /* calculate sha256 hash by caam */ + if (hwcrypto_hash((uint32_t)(ulong)hash_buf, + (hash_desc.salt_len + hash_desc.image_size), + (uint32_t)(ulong)hash_out, + AVB_SHA256_DIGEST_SIZE, + SHA256) != 0) { + avb_error("Failed to calculate sha256 hash with caam.\n"); + ret = AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION; + goto out; + } + + digest = hash_out; + free(hash_buf); +#else AvbSHA256Ctx sha256_ctx; avb_sha256_init(&sha256_ctx); avb_sha256_update(&sha256_ctx, desc_salt, hash_desc.salt_len); avb_sha256_update(&sha256_ctx, image_buf, hash_desc.image_size); digest = avb_sha256_final(&sha256_ctx); +#endif digest_len = AVB_SHA256_DIGEST_SIZE; } else if (avb_strcmp((const char*)hash_desc.hash_algorithm, "sha512") == 0) { AvbSHA512Ctx sha512_ctx; |