driver: crypto: SHA: npcx: fix SHA driver for npcx4 QS chip

The commit fixes the SHA driver because the ROM API has the following
changes from ES to QS chip:
1. base addres: from 0x13c -> 0x148
2. required SHA context buffer size : from 228 -> 240 bytes

This change also adds a check for the pre-allocated buffer size of the
SHA context when the driver initiliazes.

Signed-off-by: Jun Lin <CHLin56@nuvoton.com>
This commit is contained in:
Jun Lin 2023-12-08 13:36:05 +08:00 committed by Fabio Baltieri
parent 11d4f8e5e5
commit fde31c03c5
2 changed files with 19 additions and 5 deletions

View File

@ -13,9 +13,9 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(sha_npcx, CONFIG_CRYPTO_LOG_LEVEL);
#define NPCX_HASH_CAPS_SUPPORT (CAP_SEPARATE_IO_BUFS | CAP_SYNC_OPS)
#define NPCX_HASH_CAPS_SUPPORT (CAP_SEPARATE_IO_BUFS | CAP_SYNC_OPS)
#define NPCX_SHA256_HANDLE_SIZE DT_INST_PROP(0, context_buffer_size)
#define NPCX_SHA_MAX_SESSION 1
#define NPCX_SHA_MAX_SESSION 1
/* The status code returns from Nuvoton Cryptographic Library ROM APIs */
enum ncl_status {
@ -204,13 +204,27 @@ static int npcx_query_caps(const struct device *dev)
return NPCX_HASH_CAPS_SUPPORT;
}
static int npcx_hash_init(const struct device *dev)
{
uint32_t handle_size_required;
handle_size_required = NPCX_NCL_SHA->get_context_size();
if (handle_size_required != NPCX_SHA256_HANDLE_SIZE) {
LOG_ERR("Pre-alloc buf size doesn't match required buf size (%d)",
handle_size_required);
return -ENOSR;
}
return 0;
}
static struct crypto_driver_api npcx_crypto_api = {
.hash_begin_session = npcx_hash_session_setup,
.hash_free_session = npcx_hash_session_free,
.query_hw_caps = npcx_query_caps,
};
DEVICE_DT_INST_DEFINE(0, NULL, NULL, NULL, NULL, POST_KERNEL, CONFIG_CRYPTO_INIT_PRIORITY,
DEVICE_DT_INST_DEFINE(0, npcx_hash_init, NULL, NULL, NULL, POST_KERNEL, CONFIG_CRYPTO_INIT_PRIORITY,
&npcx_crypto_api);
BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 1,
"only one 'nuvoton,npcx-sha' compatible node can be supported");

View File

@ -291,8 +291,8 @@
sha0: sha@13c {
compatible = "nuvoton,npcx-sha";
reg = <0x13c 0x3c>;
context-buffer-size = <228>;
reg = <0x148 0x4c>;
context-buffer-size = <240>;
status = "disabled";
};