WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
nv_porting.h
浏览该文件的文档.
1/*
2 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2021-2023. All rights reserved.
3 * Description: Function headers of different chips in the NV module.
4 */
5
6#ifndef NV_PORTING_H
7#define NV_PORTING_H
8
9#include "stdint.h"
10#include "stdbool.h"
11#include "errcode.h"
12#include "securec.h"
13#include "soc_osal.h"
14#include "osal_addr.h"
15#include "nv_config.h"
16#include "nv_key.h"
17
18static inline void *kv_malloc(uint32_t x)
19{
20 return osal_kmalloc(x, 0);
21}
22
23static inline void *kv_zalloc(uint32_t x)
24{
25 return osal_kzalloc(x, 0);
26}
27
28static inline void kv_free(void *x)
29{
30 osal_kfree(x);
31}
32
33/*
34 * nv_psram_malloc:从psram上分配内存存放NV数据
35 * NV支持异步存储时(CONFIG_NV_SUPPORT_ASYNCHRONOUS_STORE特性宏设置为NV_YES)有效
36 * 根据实际NV支持异步存储时NV数据存放器件进行配置
37 * 默认内存分配函数为kv_malloc
38*/
39static inline void *nv_psram_malloc(uint32_t x)
40{
41 return kv_malloc(x);
42}
43
44/*
45 * nv_psram_free:从psram上释放内存
46 * NV支持异步存储时(CONFIG_NV_SUPPORT_ASYNCHRONOUS_STORE特性宏设置为NV_YES)有效
47 * 根据实际NV支持异步存储时NV数据存放器件进行配置
48 * 默认内存释放函数为kv_free
49*/
50static inline void nv_psram_free(void *x)
51{
52 kv_free(x);
53}
54
55errcode_t kv_flash_read(const uint32_t flash_offset, const uint32_t read_size, uint8_t *read_buffer);
56errcode_t kv_flash_write(const uint32_t flash_offset, uint32_t write_size, const uint8_t *write_data, bool do_erase);
57errcode_t kv_flash_erase(const uint32_t flash_addr, uint32_t size);
58
59/* 创建加解密通道 */
60errcode_t nv_crypto_claim_aes(uint32_t *crypto_handle, const kv_key_header_t *header);
61
62/* 释放加解密通道 */
63void nv_crypto_release_aes(uint32_t crypto_handle);
64
65/* NV数据加密 */
66errcode_t nv_crypto_encode(uint32_t crypto_handle, const uintptr_t src, uintptr_t dest, uint32_t length);
67
68/* NV数据解密 */
69errcode_t nv_crypto_decode(uint32_t crypto_handle, const uintptr_t src, uintptr_t dest, uint32_t length);
70
71/* 获取加密Tag */
72errcode_t nv_crypto_get_tag(uint32_t crypto_handle, uint8_t *tag, uint32_t *tag_len);
73
74/* 设置当前NV的Tag */
75errcode_t nv_crypto_set_tag(uint32_t crypto_handle, uint8_t *tag, uint32_t tag_len);
76
77/* 校验Tag */
78errcode_t nv_crypto_validate_tag(uint32_t crypto_handle);
79
80/* 获取随机数 */
81void nv_crypto_generate_random(uint32_t *rnd);
82
83/* 启动HASH计算 */
85
86/* 更新HASH */
87errcode_t nv_crypto_update_hash(const uint8_t *src, uint32_t length);
88
89/* 完成HASH计算并返回HASH值 */
91
92#if (defined(CONFIG_NV_SUPPORT_DEBUG) && (CONFIG_NV_SUPPORT_DEBUG == NV_YES))
93#define nv_log_err(fmt, arg...) osal_printk(fmt, ##arg)
94#define nv_log_info(fmt, arg...) osal_printk(fmt, ##arg)
95#define nv_log_debug(fmt, arg...) osal_printk(fmt, ##arg)
96#else
97#define nv_log_err(fmt, arg...)
98#define nv_log_info(fmt, arg...)
99#define nv_log_debug(fmt, arg...)
100#endif
101
102#endif /* NV_PORTING_H */
103
uint32_t errcode_t
Definition of error code.
Definition errcode.h:30
void * osal_kmalloc(unsigned long size, unsigned int osal_gfp_flag)
Alloc dynamic memory.
Definition osal_addr.c:20
void osal_kfree(void *addr)
Free dynamic memory.
Definition osal_addr.c:52
void * osal_kzalloc(unsigned long size, unsigned int osal_gfp_flag)
Alloc dynamic memory.
Definition osal_addr.c:26
void nv_crypto_generate_random(uint32_t *rnd)
errcode_t nv_crypto_complete_hash(uint8_t *hash)
errcode_t nv_crypto_get_tag(uint32_t crypto_handle, uint8_t *tag, uint32_t *tag_len)
errcode_t nv_crypto_decode(uint32_t crypto_handle, const uintptr_t src, uintptr_t dest, uint32_t length)
errcode_t nv_crypto_validate_tag(uint32_t crypto_handle)
void nv_crypto_release_aes(uint32_t crypto_handle)
errcode_t kv_flash_read(const uint32_t flash_offset, const uint32_t read_size, uint8_t *read_buffer)
Definition nv_flash.c:11
errcode_t kv_flash_erase(const uint32_t flash_addr, uint32_t size)
Definition nv_flash.c:52
errcode_t nv_crypto_set_tag(uint32_t crypto_handle, uint8_t *tag, uint32_t tag_len)
errcode_t nv_crypto_update_hash(const uint8_t *src, uint32_t length)
errcode_t nv_crypto_start_hash(void)
errcode_t kv_flash_write(const uint32_t flash_offset, uint32_t write_size, const uint8_t *write_data, bool do_erase)
Definition nv_flash.c:20
errcode_t nv_crypto_encode(uint32_t crypto_handle, const uintptr_t src, uintptr_t dest, uint32_t length)
errcode_t nv_crypto_claim_aes(uint32_t *crypto_handle, const kv_key_header_t *header)
Definition nv_key.h:82
unsigned int uintptr_t
Definition td_type.h:65