hpm_romapi.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. /*
  2. * Copyright (c) 2021-2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_ROMAPI_H
  8. #define HPM_ROMAPI_H
  9. /**
  10. * @brief ROM APIs
  11. * @defgroup romapi_interface ROM APIs
  12. * @{
  13. */
  14. #include "hpm_common.h"
  15. #include "hpm_otp_drv.h"
  16. #include "hpm_romapi_xpi_def.h"
  17. #include "hpm_romapi_xpi_soc_def.h"
  18. #include "hpm_romapi_xpi_nor_def.h"
  19. #include "hpm_romapi_xpi_ram_def.h"
  20. #include "hpm_sdp_drv.h"
  21. /* XPI0 base address */
  22. #define HPM_XPI0_BASE (0xF3040000UL) /**< XPI0 Base address */
  23. /* XPI0 base pointer */
  24. #define HPM_XPI0 ((XPI_Type *) HPM_XPI0_BASE) /**< XPI0 Base pointer */
  25. /* XPI1 base address */
  26. #define HPM_XPI1_BASE (0xF3044000UL) /**< XPI1 Base address */
  27. /* XPI1 base pointer */
  28. #define HPM_XPI1 ((XPI_Type *) HPM_XPI1_BASE) /**< XPI1 Base pointer */
  29. /***********************************************************************************************************************
  30. *
  31. *
  32. * Definitions
  33. *
  34. *
  35. **********************************************************************************************************************/
  36. /**
  37. * @brief Enter Bootloader API argument
  38. */
  39. typedef union {
  40. uint32_t U;
  41. struct {
  42. uint32_t index: 8; /**< Image index */
  43. uint32_t peripheral: 8; /**< Boot peripheral */
  44. uint32_t src: 8; /**< Boot source */
  45. uint32_t tag: 8; /**< ROM API parameter tag, must be 0xEB */
  46. };
  47. } api_boot_arg_t;
  48. /*EXiP Region Parameter */
  49. typedef struct {
  50. uint32_t start; /**< Start address, must be 4KB aligned */
  51. uint32_t len; /**< Must be 4KB aligned */
  52. uint8_t key[16]; /**< AES Key */
  53. uint8_t ctr[8]; /**< Initial Vector/Counter */
  54. } exip_region_param_t;
  55. #define API_BOOT_TAG (0xEBU) /**< ROM API parameter tag */
  56. #define API_BOOT_SRC_OTP (0U) /**< Boot source: OTP */
  57. #define API_BOOT_SRC_PRIMARY (1U) /**< Boot source: Primary */
  58. #define API_BOOT_SRC_SERIAL_BOOT (2U) /**< Boot source: Serial Boot */
  59. #define API_BOOT_SRC_ISP (3U) /**< Boot source: ISP */
  60. #define API_BOOT_PERIPH_AUTO (0U) /**< Boot peripheral: Auto detected */
  61. #define API_BOOT_PERIPH_UART (1U) /**< Boot peripheral: UART */
  62. #define API_BOOT_PERIPH_USBHID (2U) /**< Boot Peripheral: USB-HID */
  63. typedef struct {
  64. uint32_t _internal[138];
  65. } sm3_context_t;
  66. #define SM4_ENCRYPT 1
  67. #define SM4_DECRYPT 0
  68. typedef struct {
  69. uint32_t mode;
  70. uint32_t _internal[116];
  71. } sm4_context_t;
  72. /**
  73. * @brief OTP driver interface
  74. */
  75. typedef struct {
  76. /**< OTP driver interface version */
  77. uint32_t version;
  78. /**< OTP driver interface: init */
  79. void (*init)(void);
  80. /**< OTP driver interface: deinit */
  81. void (*deinit)(void);
  82. /**< OTP driver interface: read from shadow */
  83. uint32_t (*read_from_shadow)(uint32_t addr);
  84. /**< OTP driver interface: read from ip */
  85. uint32_t (*read_from_ip)(uint32_t addr);
  86. /**< OTP driver interface: program */
  87. hpm_stat_t (*program)(uint32_t addr, const uint32_t *src, uint32_t num_of_words);
  88. /**< OTP driver interface: reload */
  89. hpm_stat_t (*reload)(otp_region_t region);
  90. /**< OTP driver interface: lock */
  91. hpm_stat_t (*lock)(uint32_t addr, otp_lock_option_t lock_option);
  92. /**< OTP driver interface: lock_shadow */
  93. hpm_stat_t (*lock_shadow)(uint32_t addr, otp_lock_option_t lock_option);
  94. /**< OTP driver interface: set_configurable_region */
  95. hpm_stat_t (*set_configurable_region)(uint32_t start, uint32_t num_of_words);
  96. /**< OTP driver interface: write_shadow_register */
  97. hpm_stat_t (*write_shadow_register)(uint32_t addr, uint32_t data);
  98. } otp_driver_interface_t;
  99. /**
  100. * @brief XPI driver interface
  101. */
  102. typedef struct {
  103. /**< XPI driver interface: version */
  104. uint32_t version;
  105. /**< XPI driver interface: get default configuration */
  106. hpm_stat_t (*get_default_config)(xpi_config_t *xpi_config);
  107. /**< XPI driver interface: get default device configuration */
  108. hpm_stat_t (*get_default_device_config)(xpi_device_config_t *dev_config);
  109. /**< XPI driver interface: initialize the XPI using xpi_config */
  110. hpm_stat_t (*init)(XPI_Type *base, xpi_config_t *xpi_config);
  111. /**< XPI driver interface: configure the AHB buffer */
  112. hpm_stat_t (*config_ahb_buffer)(XPI_Type *base, xpi_ahb_buffer_cfg_t *ahb_buf_cfg);
  113. /**< XPI driver interface: configure the device */
  114. hpm_stat_t (*config_device)(XPI_Type *base, xpi_device_config_t *dev_cfg, xpi_channel_t channel);
  115. /**< XPI driver interface: update instruction talbe */
  116. hpm_stat_t (*update_instr_table)(XPI_Type *base, const uint32_t *inst_base, uint32_t seq_idx, uint32_t num);
  117. /**< XPI driver interface: transfer command/data using block interface */
  118. hpm_stat_t (*transfer_blocking)(XPI_Type *base, xpi_xfer_ctx_t *xfer);
  119. /**< Software reset the XPI controller */
  120. void (*software_reset)(XPI_Type *base);
  121. /**< XPI driver interface: Check whether IP is idle */
  122. bool (*is_idle)(XPI_Type *base);
  123. /**< XPI driver interface: update delay line setting */
  124. void (*update_dllcr)(XPI_Type *base, uint32_t serial_root_clk_freq, uint32_t data_valid_time, xpi_channel_t channel,
  125. uint32_t dly_target);
  126. /**< XPI driver interface: Get absolute address for APB transfer */
  127. hpm_stat_t (*get_abs_apb_xfer_addr)(XPI_Type *base, xpi_xfer_channel_t channel, uint32_t in_addr,
  128. uint32_t *out_addr);
  129. } xpi_driver_interface_t;
  130. /**
  131. * @brief XPI NOR driver interface
  132. */
  133. typedef struct {
  134. /**< XPI NOR driver interface: API version */
  135. uint32_t version;
  136. /**< XPI NOR driver interface: Get FLASH configuration */
  137. hpm_stat_t (*get_config)(XPI_Type *base, xpi_nor_config_t *nor_cfg, xpi_nor_config_option_t *cfg_option);
  138. /**< XPI NOR driver interface: initialize FLASH */
  139. hpm_stat_t (*init)(XPI_Type *base, xpi_nor_config_t *nor_config);
  140. /**< XPI NOR driver interface: Enable write access to FLASH */
  141. hpm_stat_t (*enable_write)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config,
  142. uint32_t addr);
  143. /**< XPI NOR driver interface: Get FLASH status register */
  144. hpm_stat_t (*get_status)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config,
  145. uint32_t addr,
  146. uint16_t *out_status);
  147. /**< XPI NOR driver interface: Wait when FLASH is still busy */
  148. hpm_stat_t (*wait_busy)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config,
  149. uint32_t addr);
  150. /**< XPI NOR driver interface: erase a specified FLASH region */
  151. hpm_stat_t (*erase)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t start,
  152. uint32_t length);
  153. /**< XPI NOR driver interface: Erase the whole FLASH */
  154. hpm_stat_t (*erase_chip)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config);
  155. /**< XPI NOR driver interface: Erase specified FLASH sector */
  156. hpm_stat_t (*erase_sector)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config,
  157. uint32_t addr);
  158. /**< XPI NOR driver interface: Erase specified FLASH block */
  159. hpm_stat_t (*erase_block)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config,
  160. uint32_t addr);
  161. /**< XPI NOR driver interface: Program data to specified FLASH address */
  162. hpm_stat_t (*program)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config,
  163. const uint32_t *src,
  164. uint32_t dst_addr, uint32_t length);
  165. /**< XPI NOR driver interface: read data from specified FLASH address */
  166. hpm_stat_t (*read)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t *dst,
  167. uint32_t start, uint32_t length);
  168. /**< XPI NOR driver interface: program FLASH page using nonblocking interface */
  169. hpm_stat_t (*page_program_nonblocking)(XPI_Type *base, xpi_xfer_channel_t channel,
  170. const xpi_nor_config_t *nor_config,
  171. const uint32_t *src, uint32_t dst_addr, uint32_t length);
  172. /**< XPI NOR driver interface: erase FLASH sector using nonblocking interface */
  173. hpm_stat_t (*erase_sector_nonblocking)(XPI_Type *base, xpi_xfer_channel_t channel,
  174. const xpi_nor_config_t *nor_config,
  175. uint32_t addr);
  176. /**< XPI NOR driver interface: erase FLASH block using nonblocking interface */
  177. hpm_stat_t (*erase_block_nonblocking)(XPI_Type *base, xpi_xfer_channel_t channel,
  178. const xpi_nor_config_t *nor_config,
  179. uint32_t addr);
  180. /**< XPI NOR driver interface: erase the whole FLASh using nonblocking interface */
  181. hpm_stat_t (*erase_chip_nonblocking)(XPI_Type *base, xpi_xfer_channel_t channel,
  182. const xpi_nor_config_t *nor_config);
  183. uint32_t reserved0[3];
  184. /**< XPI NOR driver interface: automatically configuration flash based on the cfg_option setting */
  185. hpm_stat_t (*auto_config)(XPI_Type *base, xpi_nor_config_t *nor_cfg, xpi_nor_config_option_t *cfg_option);
  186. /**< XPI NOR driver interface: Get FLASH properties */
  187. hpm_stat_t (*get_property)(XPI_Type *base, xpi_nor_config_t *nor_cfg, uint32_t property_id, uint32_t *value);
  188. } xpi_nor_driver_interface_t;
  189. /**
  190. * @brief XPI RAM driver interface
  191. */
  192. typedef struct {
  193. /**< XPI RAM driver interface: API version */
  194. uint32_t version;
  195. /**< Get XPI RAM configuration based on cfg_option */
  196. hpm_stat_t (*get_config)(XPI_Type *base, xpi_ram_config_t *ram_cfg, xpi_ram_config_option_t *cfg_option);
  197. /**< XPI RAM driver interface: Initialize XPI RAM */
  198. hpm_stat_t (*init)(XPI_Type *base, xpi_ram_config_t *ram_cfg);
  199. } xpi_ram_driver_interface_t;
  200. /**
  201. * @brief SDP API interface
  202. */
  203. typedef struct {
  204. /**< SDP API interface: API version */
  205. uint32_t version;
  206. /**< SDP API interface: Initialize IP */
  207. hpm_stat_t (*sdp_ip_init)(void);
  208. /**< SDP API interface: Deinitialize IP */
  209. hpm_stat_t (*sdp_ip_deinit)(void);
  210. /**< SDP API interface: Set AES key */
  211. hpm_stat_t (*aes_set_key)(sdp_aes_ctx_t *aes_ctx, const uint8_t *key, sdp_aes_key_bits_t keybits, uint32_t key_idx);
  212. /**< SDP API interface: AES ECB crypto operation */
  213. hpm_stat_t (*aes_crypt_ecb)(sdp_aes_ctx_t *aes_ctx, sdp_aes_op_t op, uint32_t len, const uint8_t *in, uint8_t *out);
  214. /**< SDP API interface: AES CBC crypto operation */
  215. hpm_stat_t (*aes_crypt_cbc)(sdp_aes_ctx_t *aes_ctx, sdp_aes_op_t op, uint32_t length, uint8_t iv[16],
  216. const uint8_t *input, uint8_t *output);
  217. /**< SDP API interface: AES CTR crypto operation */
  218. hpm_stat_t (*aes_crypt_ctr)(sdp_aes_ctx_t *aes_ctx, uint8_t *nonce_ctr, uint8_t *input, uint8_t *output,
  219. uint32_t length);
  220. /**< SDP API interface: AES CCM encryption */
  221. hpm_stat_t (*aes_ccm_gen_enc)(sdp_aes_ctx_t *aes_ctx, uint32_t input_len, const uint8_t *nonce, uint32_t nonce_len,
  222. const uint8_t *aad, uint32_t aad_len, const uint8_t *input, uint8_t *output,
  223. uint8_t *tag, uint32_t tag_len);
  224. /**< SDP API interface: AES CCM Decrypt and verify */
  225. hpm_stat_t (*aes_ccm_dec_verify)(sdp_aes_ctx_t *aes_ctx, uint32_t input_len, const uint8_t *nonce,
  226. uint32_t nonce_len, const uint8_t *aad, uint32_t aad_len, const uint8_t *input,
  227. uint8_t *output, const uint8_t *tag, uint32_t tag_len);
  228. /**< SDP API interface: memcpy */
  229. hpm_stat_t (*memcpy)(sdp_dma_ctx_t *dma_ctx, void *dst, const void *src, uint32_t length);
  230. /**< SDP API interface: memset */
  231. hpm_stat_t (*memset)(sdp_dma_ctx_t *dma_ctx, void *dst, uint8_t pattern, uint32_t length);
  232. /**< SDP API interface: HASH initialization */
  233. hpm_stat_t (*hash_init)(sdp_hash_ctx_t *hash_ctx, sdp_hash_alg_t alg);
  234. /**< SDP API interface: HASH update */
  235. hpm_stat_t (*hash_update)(sdp_hash_ctx_t *hash_ctx, const uint8_t *data, uint32_t length);
  236. /**< SDP API interface: HASH finish */
  237. hpm_stat_t (*hash_finish)(sdp_hash_ctx_t *hash_ctx, uint8_t *digest);
  238. } sdp_driver_interface_t;
  239. typedef struct {
  240. /**< SM3 API version*/
  241. uint32_t version;
  242. /**< SM3 API itnerface: HASH Initialization */
  243. hpm_stat_t (*init)(sm3_context_t *ctx);
  244. /**< SM3 API interface: HASH update */
  245. hpm_stat_t (*update)(sm3_context_t *ctx, const void *input, uint32_t len);
  246. /**< SM3 API interface: HASH finish */
  247. hpm_stat_t (*finalize)(sm3_context_t *ctx, uint8_t output[32]);
  248. } sm3_api_interface_t;
  249. typedef struct {
  250. /**< SM4 API interface: Version */
  251. uint32_t version;
  252. /**< SM4 API interface: Set encryption key */
  253. void (*setkey_enc)(sm4_context_t *ctx, const uint8_t key[16]);
  254. /**< SM4 API interface: Set decryption key */
  255. void (*setkey_dec)(sm4_context_t *ctx, const uint8_t key[16]);
  256. /**< SM4 API interface: SM4 ECB operation */
  257. hpm_stat_t (*crypt_ecb)(sm4_context_t *ctx, uint32_t mode, uint32_t length, const uint8_t *input, uint8_t *output);
  258. /**< SM4 API interface: SM4 CBC operation */
  259. hpm_stat_t (*crypt_cbc)(sm4_context_t *ctx, uint32_t mode, uint32_t length, const uint8_t iv[16],
  260. const uint8_t *input, uint8_t *output);
  261. /**< SM4 API interface: SM4 CTR operation */
  262. hpm_stat_t (*crypt_ctr)(sm4_context_t *ctx, uint8_t *nonce_counter, const uint8_t *input,
  263. uint8_t *output, uint32_t length);
  264. /**< SM4 API interface: SM4 CCB encryption */
  265. hpm_stat_t (*ccm_gen_enc)(sm4_context_t *ctx, uint32_t input_len, const uint8_t *iv,
  266. uint32_t iv_len, const uint8_t *aad, uint32_t aad_len, const uint8_t *input,
  267. uint8_t *output, uint8_t *tag, uint32_t tag_len);
  268. /**< SM4 API interface: SM4 CCM Decryption and verifying */
  269. hpm_stat_t (*ccm_dec_verify)(sm4_context_t *ctx, uint32_t input_len, const uint8_t *iv,
  270. uint32_t iv_len, const uint8_t *aad, uint32_t aad_len, const uint8_t *input,
  271. uint8_t *output, const uint8_t *tag, uint32_t tag_len);
  272. } sm4_api_interface_t;
  273. /**
  274. * @brief Bootloader API table
  275. */
  276. typedef struct {
  277. /**< Bootloader API table: version */
  278. const uint32_t version;
  279. /**< Bootloader API table: copyright string address */
  280. const char *copyright;
  281. /**< Bootloader API table: run_bootloader API */
  282. const hpm_stat_t (*run_bootloader)(void *arg);
  283. /**< Bootloader API table: otp driver interface address */
  284. const otp_driver_interface_t *otp_driver_if;
  285. /**< Bootloader API table: xpi driver interface address */
  286. const xpi_driver_interface_t *xpi_driver_if;
  287. /**< Bootloader API table: xpi nor driver interface address */
  288. const xpi_nor_driver_interface_t *xpi_nor_driver_if;
  289. /**< Bootloader API table: xpi ram driver interface address */
  290. const xpi_ram_driver_interface_t *xpi_ram_driver_if;
  291. /**< Bootloader API table: sdp driver interface address */
  292. const sdp_driver_interface_t *sdp_driver_if;
  293. const uint32_t reserved0;
  294. const sm3_api_interface_t *sm3_api_if; /* SM3 driver interface address */
  295. const sm4_api_interface_t *sm4_api_if; /* SM4 driver itnerface address */
  296. } bootloader_api_table_t;
  297. /**< Bootloader API table Root */
  298. #define ROM_API_TABLE_ROOT ((const bootloader_api_table_t *)0x2001FF00U)
  299. #ifdef __cplusplus
  300. extern "C" {
  301. #endif
  302. /***********************************************************************************************************************
  303. *
  304. *
  305. * Enter bootloader Wrapper
  306. *
  307. *
  308. **********************************************************************************************************************/
  309. /**
  310. * @brief Eneter specified Boot mode
  311. * @param [in] ctx Enter bootloader context
  312. * @retval status_invalid Invalid parameters were deteced
  313. */
  314. static inline hpm_stat_t rom_enter_bootloader(void *ctx)
  315. {
  316. return ROM_API_TABLE_ROOT->run_bootloader(ctx);
  317. }
  318. /***********************************************************************************************************************
  319. *
  320. *
  321. * XPI NOR Driver Wrapper
  322. *
  323. *
  324. **********************************************************************************************************************/
  325. /**
  326. * @brief Get XPI NOR configuration via cfg_option
  327. * @param [in] base XPI base address
  328. * @param [out] nor_cfg XPI NOR configuration structure
  329. * @param [in] cfg_option XPI NOR configuration option
  330. * @return API execution status
  331. */
  332. static inline hpm_stat_t rom_xpi_nor_get_config(XPI_Type *base, xpi_nor_config_t *nor_cfg,
  333. xpi_nor_config_option_t *cfg_option)
  334. {
  335. return ROM_API_TABLE_ROOT->xpi_nor_driver_if->get_config(base, nor_cfg, cfg_option);
  336. }
  337. /**
  338. * @brief Initialize XPI NOR based on nor_config
  339. * @param [in] base XPI base address
  340. * @param[in] nor_config XPI NOR configuration
  341. * @return API execution status
  342. */
  343. static inline hpm_stat_t rom_xpi_nor_init(XPI_Type *base, xpi_nor_config_t *nor_config)
  344. {
  345. return ROM_API_TABLE_ROOT->xpi_nor_driver_if->init(base, nor_config);
  346. }
  347. /**
  348. * @brief Erase specified FLASH region
  349. * @param[in] base XPI base address
  350. * @param[in] channel XPI transfer channel
  351. * @param[in] nor_config XPI nOR configuration
  352. * @param[in] start Erase address start address
  353. * @param[in] length Region size to be erased
  354. * @return API execution status
  355. */
  356. static inline hpm_stat_t rom_xpi_nor_erase(XPI_Type *base, xpi_xfer_channel_t channel,
  357. const xpi_nor_config_t *nor_config,
  358. uint32_t start, uint32_t length)
  359. {
  360. hpm_stat_t status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase(base, channel, nor_config, start, length);
  361. fencei();
  362. return status;
  363. }
  364. /**
  365. * @brief Erase specified FLASH sector in blocking way
  366. * @param[in] base XPI base address
  367. * @param[in] channel XPI transfer channel
  368. * @param[in] nor_config XPI NOR configuration
  369. * @param[in] start Sector address
  370. * @return API execution status
  371. */
  372. static inline hpm_stat_t rom_xpi_nor_erase_sector(XPI_Type *base, xpi_xfer_channel_t channel,
  373. const xpi_nor_config_t *nor_config,
  374. uint32_t start)
  375. {
  376. hpm_stat_t status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_sector(base, channel, nor_config, start);
  377. fencei();
  378. return status;
  379. }
  380. /**
  381. * @brief Erase specified FLASH sector in non-blocking way
  382. * @param[in] base XPI base address
  383. * @param[in] channel XPI transfer channel
  384. * @param[in] nor_config XPI NOR configuration
  385. * @param[in] start Sector address
  386. * @return API execution status
  387. */
  388. static inline hpm_stat_t rom_xpi_nor_erase_sector_nonblocking(XPI_Type *base, xpi_xfer_channel_t channel,
  389. const xpi_nor_config_t *nor_config,
  390. uint32_t start)
  391. {
  392. return ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_sector_nonblocking(base, channel, nor_config, start);
  393. }
  394. /**
  395. * @brief Erase specified FLASH blcok in blocking way
  396. * @param[in] base XPI base address
  397. * @param[in] channel XPI transfer channel
  398. * @param[in] nor_config XPI NOR configuration
  399. * @param[in] start Block address
  400. * @return API execution status
  401. */
  402. static inline hpm_stat_t rom_xpi_nor_erase_block(XPI_Type *base, xpi_xfer_channel_t channel,
  403. const xpi_nor_config_t *nor_config,
  404. uint32_t start)
  405. {
  406. hpm_stat_t status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_block(base, channel, nor_config, start);
  407. fencei();
  408. return status;
  409. }
  410. /**
  411. * @brief Erase specified FLASH blcok in non-blocking way
  412. * @param[in] base XPI base address
  413. * @param[in] channel XPI transfer channel
  414. * @param[in] nor_config XPI NOR configuration
  415. * @param[in] start Block address
  416. * @return API execution status
  417. */
  418. static inline hpm_stat_t rom_xpi_nor_erase_block_nonblocking(XPI_Type *base, xpi_xfer_channel_t channel,
  419. const xpi_nor_config_t *nor_config,
  420. uint32_t start)
  421. {
  422. return ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_block_nonblocking(base, channel, nor_config, start);
  423. }
  424. /**
  425. * @brief Erase the whole FLASH in blocking way
  426. * @param[in] base XPI base address
  427. * @param[in] channel XPI transfer channel
  428. * @param[in] nor_config XPI NOR configuration
  429. * @return API execution status
  430. */
  431. static inline hpm_stat_t rom_xpi_nor_erase_chip(XPI_Type *base, xpi_xfer_channel_t channel,
  432. const xpi_nor_config_t *nor_config)
  433. {
  434. return ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_chip(base, channel, nor_config);
  435. }
  436. /**
  437. * @brief Erase the whole FLASH in non-blocking way
  438. * @param[in] base XPI base address
  439. * @param[in] channel XPI transfer channel
  440. * @param[in] nor_config XPI NOR configuration
  441. * @return API execution status
  442. */
  443. static inline hpm_stat_t rom_xpi_nor_erase_chip_nonblocking(XPI_Type *base, xpi_xfer_channel_t channel,
  444. const xpi_nor_config_t *nor_config)
  445. {
  446. hpm_stat_t status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_chip_nonblocking(base, channel, nor_config);
  447. fencei();
  448. return status;
  449. }
  450. /**
  451. * @brief Program data to specified FLASH address in blocking way
  452. * @param[in] base XPI base address
  453. * @param[in] channel XPI transfer channel
  454. * @param[in] nor_config XPI NOR configuration
  455. * @param[in] src data source address
  456. * @param[in] dst_addr Destination FLASH address
  457. * @param[in] length length of data to be programmed
  458. * @return API execution status
  459. */
  460. static inline hpm_stat_t rom_xpi_nor_program(XPI_Type *base, xpi_xfer_channel_t channel,
  461. const xpi_nor_config_t *nor_config,
  462. const uint32_t *src, uint32_t dst_addr, uint32_t length)
  463. {
  464. hpm_stat_t
  465. status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->program(base, channel, nor_config, src, dst_addr, length);
  466. fencei();
  467. return status;
  468. }
  469. /**
  470. * @brief Page-Program data to specified FLASH address in non-blocking way
  471. * @param[in] base XPI base address
  472. * @param[in] channel XPI transfer channel
  473. * @param[in] nor_config XPI NOR configuration
  474. * @param[in] src data source address
  475. * @param[in] dst_addr Destination FLASH address
  476. * @param[in] length length of data to be programmed
  477. * @return API execution status
  478. */
  479. static inline hpm_stat_t rom_xpi_nor_page_program_nonblocking(XPI_Type *base, xpi_xfer_channel_t channel,
  480. const xpi_nor_config_t *nor_config, const uint32_t *src,
  481. uint32_t dst_addr, uint32_t length)
  482. {
  483. return ROM_API_TABLE_ROOT->xpi_nor_driver_if->page_program_nonblocking(base, channel, nor_config, src, dst_addr,
  484. length);
  485. }
  486. /**
  487. * @brief Read data from specified FLASH address
  488. * @param [in] base XPI base address
  489. * @param [in] channel XPI transfer channel
  490. * @param [in] nor_config XPI NOR configuration
  491. * @param [in] dst Memory start address to store the data read out from FLASH
  492. * @param [in] start FLASH address for data read
  493. * @param [in] length length of data to be read out
  494. * @return API exection address
  495. */
  496. static inline hpm_stat_t rom_xpi_nor_read(XPI_Type *base, xpi_xfer_channel_t channel,
  497. const xpi_nor_config_t *nor_config,
  498. uint32_t *dst, uint32_t start, uint32_t length)
  499. {
  500. return ROM_API_TABLE_ROOT->xpi_nor_driver_if->read(base, channel, nor_config, dst, start, length);
  501. }
  502. /**
  503. * @brief Automatically configure XPI NOR based on cfg_option
  504. * @param [in] base XPI base address
  505. * @param [out] config XPI NOR configuration structure
  506. * @param [in] cfg_option XPI NOR configuration option
  507. * @return API execution status
  508. */
  509. static inline hpm_stat_t rom_xpi_nor_auto_config(XPI_Type *base, xpi_nor_config_t *config,
  510. xpi_nor_config_option_t *cfg_option)
  511. {
  512. return ROM_API_TABLE_ROOT->xpi_nor_driver_if->auto_config(base, config, cfg_option);
  513. }
  514. /**
  515. * @brief Get XPI NOR properties
  516. * @param [in] base XPI base address
  517. * @param [in] nor_cfg XPI NOR configuration structure
  518. * @param [in] property_id
  519. * @param [out] value property value retrieved by this API
  520. * @return API execution status
  521. */
  522. static inline hpm_stat_t rom_xpi_nor_get_property(XPI_Type *base, xpi_nor_config_t *nor_cfg, uint32_t property_id,
  523. uint32_t *value)
  524. {
  525. return ROM_API_TABLE_ROOT->xpi_nor_driver_if->get_property(base, nor_cfg, property_id, value);
  526. }
  527. /**
  528. * @brief Return the status register value on XPI NOR FLASH
  529. *
  530. * @param [in] base XPI base address
  531. * @param [in] channel XPI transfer channel
  532. * @param [in] nor_config XPI NOR configuration
  533. * @param [in] addr FLASH address offset
  534. * @param [out] out_status FLASH status register value
  535. * @return API execution status
  536. */
  537. static inline hpm_stat_t rom_xpi_nor_get_status(XPI_Type *base, xpi_xfer_channel_t channel,
  538. const xpi_nor_config_t *nor_config, uint32_t addr,
  539. uint16_t *out_status)
  540. {
  541. return ROM_API_TABLE_ROOT->xpi_nor_driver_if->get_status(base, channel, nor_config, addr, out_status);
  542. }
  543. /**
  544. * @brief Configure the XPI Address Remapping Logic
  545. * @param [in] base XPI base address
  546. * @param [in] start Start Address (memory mapped address)
  547. * @param [in] len Size for the remapping region
  548. * @param [in] offset Relative address based on parameter "start"
  549. * @retval true is all parameters are valid
  550. * @retval false if any parameter is invalid
  551. */
  552. ATTR_RAMFUNC
  553. static inline bool rom_xpi_nor_remap_config(XPI_Type *base, uint32_t start, uint32_t len, uint32_t offset)
  554. {
  555. if (((base != HPM_XPI0) && (base != HPM_XPI1)) || ((start & 0xFFF) != 0) || ((len & 0xFFF) != 0)
  556. || ((offset & 0xFFF) != 0)) {
  557. return false;
  558. }
  559. static const uint8_t k_mc_xpi_remap_config[] = {
  560. 0x2e, 0x96, 0x23, 0x22, 0xc5, 0x42, 0x23, 0x24,
  561. 0xd5, 0x42, 0x93, 0xe5, 0x15, 0x00, 0x23, 0x20,
  562. 0xb5, 0x42, 0x05, 0x45, 0x82, 0x80,
  563. };
  564. typedef bool (*remap_config_cb_t)(XPI_Type *, uint32_t, uint32_t, uint32_t);
  565. remap_config_cb_t cb = (remap_config_cb_t) &k_mc_xpi_remap_config;
  566. bool result = cb(base, start, len, offset);
  567. ROM_API_TABLE_ROOT->xpi_driver_if->software_reset(base);
  568. fencei();
  569. return result;
  570. }
  571. /**
  572. * @brief Disable XPI Remapping logic
  573. * @param [in] base XPI base address
  574. */
  575. ATTR_RAMFUNC
  576. static inline void rom_xpi_nor_remap_disable(XPI_Type *base)
  577. {
  578. static const uint8_t k_mc_xpi_remap_disable[] = {
  579. 0x83, 0x27, 0x05, 0x42, 0xf9, 0x9b, 0x23, 0x20,
  580. 0xf5, 0x42, 0x82, 0x80,
  581. };
  582. typedef void (*remap_disable_cb_t)(XPI_Type *);
  583. remap_disable_cb_t cb = (remap_disable_cb_t) &k_mc_xpi_remap_disable;
  584. cb(base);
  585. fencei();
  586. }
  587. /**
  588. * @brief Check whether XPI Remapping is enabled
  589. * @param [in] base XPI base address
  590. *
  591. * @retval true Remapping logic is enabled
  592. * @retval false Remapping logic is disabled
  593. */
  594. ATTR_RAMFUNC
  595. static inline bool rom_xpi_nor_is_remap_enabled(XPI_Type *base)
  596. {
  597. static const uint8_t k_mc_xpi_remap_enabled[] = {
  598. 0x03, 0x25, 0x05, 0x42, 0x05, 0x89, 0x82, 0x80,
  599. };
  600. typedef bool (*remap_chk_cb_t)(XPI_Type *);
  601. remap_chk_cb_t chk_cb = (remap_chk_cb_t) &k_mc_xpi_remap_enabled;
  602. return chk_cb(base);
  603. }
  604. /**
  605. * @brief Configure Specified EXiP Region
  606. * @param [in] base XPI base address
  607. * @param [in] index EXiP Region index
  608. * @param [in] param ExiP Region Parameter
  609. * @retval true All parameters are valid
  610. * @retval false Any parameter is invalid
  611. */
  612. ATTR_RAMFUNC
  613. static inline bool rom_xpi_nor_exip_region_config(XPI_Type *base, uint32_t index, exip_region_param_t *param)
  614. {
  615. if ((base != HPM_XPI0) && (base != HPM_XPI1)) {
  616. return false;
  617. }
  618. static const uint8_t k_mc_exip_region_config[] = {
  619. 0x18, 0x4a, 0x9a, 0x05, 0x2e, 0x95, 0x85, 0x67,
  620. 0xaa, 0x97, 0x23, 0xa4, 0xe7, 0xd0, 0x4c, 0x4a,
  621. 0x14, 0x42, 0x58, 0x42, 0x23, 0xa6, 0xb7, 0xd0,
  622. 0x4c, 0x46, 0x36, 0x97, 0x13, 0x77, 0x07, 0xc0,
  623. 0x23, 0xa2, 0xb7, 0xd0, 0x0c, 0x46, 0x13, 0x67,
  624. 0x37, 0x00, 0x05, 0x45, 0x23, 0xa0, 0xb7, 0xd0,
  625. 0x0c, 0x4e, 0x23, 0xaa, 0xb7, 0xd0, 0x50, 0x4e,
  626. 0x23, 0xa8, 0xc7, 0xd0, 0x23, 0xac, 0xd7, 0xd0,
  627. 0x23, 0xae, 0xe7, 0xd0, 0x82, 0x80,
  628. };
  629. typedef void (*exip_region_config_cb_t)(XPI_Type *, uint32_t, exip_region_param_t *);
  630. exip_region_config_cb_t cb = (exip_region_config_cb_t) &k_mc_exip_region_config;
  631. cb(base, index, param);
  632. ROM_API_TABLE_ROOT->xpi_driver_if->software_reset(base);
  633. fencei();
  634. return true;
  635. }
  636. /**
  637. * @brief Disable EXiP Feature on specified EXiP Region
  638. * @@param [in] base XPI base address
  639. * @param [in] index EXiP Region index
  640. */
  641. ATTR_RAMFUNC
  642. static inline void rom_xpi_nor_exip_region_disable(XPI_Type *base, uint32_t index)
  643. {
  644. static const uint8_t k_mc_exip_region_disable[] = {
  645. 0x9a, 0x05, 0x2e, 0x95, 0x85, 0x67, 0xaa, 0x97,
  646. 0x03, 0xa7, 0xc7, 0xd1, 0x75, 0x9b, 0x23, 0xae,
  647. 0xe7, 0xd0, 0x82, 0x80
  648. };
  649. typedef void (*exip_region_disable_cb_t)(XPI_Type *, uint32_t);
  650. exip_region_disable_cb_t cb = (exip_region_disable_cb_t) &k_mc_exip_region_disable;
  651. cb(base, index);
  652. ROM_API_TABLE_ROOT->xpi_driver_if->software_reset(base);
  653. fencei();
  654. }
  655. /**
  656. * @brief Enable global EXiP logic
  657. * @@param [in] base XPI base address
  658. */
  659. ATTR_RAMFUNC
  660. static inline void rom_xpi_nor_exip_enable(XPI_Type *base)
  661. {
  662. static const uint8_t k_mc_exip_enable[] = {
  663. 0x85, 0x67, 0x3e, 0x95, 0x83, 0x27, 0x05, 0xc0,
  664. 0x37, 0x07, 0x00, 0x80, 0xd9, 0x8f, 0x23, 0x20,
  665. 0xf5, 0xc0, 0x82, 0x80
  666. };
  667. typedef void (*exip_enable_cb_t)(XPI_Type *);
  668. exip_enable_cb_t cb = (exip_enable_cb_t) &k_mc_exip_enable;
  669. cb(base);
  670. }
  671. /**
  672. * @brief Disable global EXiP logic
  673. * @@param [in] base XPI base address
  674. */
  675. ATTR_RAMFUNC
  676. static inline void rom_xpi_nor_exip_disable(XPI_Type *base)
  677. {
  678. static const uint8_t k_mc_exip_disable[] = {
  679. 0x85, 0x67, 0x3e, 0x95, 0x83, 0x27, 0x05, 0xc0,
  680. 0x86, 0x07, 0x85, 0x83, 0x23, 0x20, 0xf5, 0xc0,
  681. 0x82, 0x80
  682. };
  683. typedef void (*exip_disable_cb_t)(XPI_Type *);
  684. exip_disable_cb_t cb = (exip_disable_cb_t) &k_mc_exip_disable;
  685. cb(base);
  686. ROM_API_TABLE_ROOT->xpi_driver_if->software_reset(base);
  687. fencei();
  688. }
  689. /***********************************************************************************************************************
  690. *
  691. *
  692. * XPI RAM Driver Wrapper
  693. *
  694. *
  695. **********************************************************************************************************************/
  696. /**
  697. * @brief Get XPI RAM configuration based on cfg_option
  698. * @param [in] base XPI base address
  699. * @param [out] ram_cfg XPI RAM configuration structure
  700. * @param [in] cfg_option XPI RAM configuration option
  701. * @return API execution status
  702. */
  703. static inline hpm_stat_t rom_xpi_ram_get_config(XPI_Type *base, xpi_ram_config_t *ram_cfg,
  704. xpi_ram_config_option_t *cfg_option)
  705. {
  706. return ROM_API_TABLE_ROOT->xpi_ram_driver_if->get_config(base, ram_cfg, cfg_option);
  707. }
  708. /**
  709. * @brief Initialize XPI RAM
  710. * @param [in] base XPI base address
  711. * @param [in] ram_cfg XPI ram configuration
  712. * @return API execution status
  713. */
  714. static inline hpm_stat_t rom_xpi_ram_init(XPI_Type *base, xpi_ram_config_t *ram_cfg)
  715. {
  716. return ROM_API_TABLE_ROOT->xpi_ram_driver_if->init(base, ram_cfg);
  717. }
  718. /***********************************************************************************************************************
  719. *
  720. *
  721. * SDP Driver Wrapper
  722. *
  723. *
  724. **********************************************************************************************************************/
  725. /**
  726. * @brief Initialize SDP IP
  727. */
  728. static inline void rom_sdp_init(void)
  729. {
  730. ROM_API_TABLE_ROOT->sdp_driver_if->sdp_ip_init();
  731. }
  732. /**
  733. * @brief De-initialize SDP IP
  734. */
  735. static inline void rom_sdp_deinit(void)
  736. {
  737. ROM_API_TABLE_ROOT->sdp_driver_if->sdp_ip_deinit();
  738. }
  739. /**
  740. * @brief Set AES key to SDP
  741. * @param [in] aes_ctx AES context
  742. * @param [in] key AES key buffer
  743. * @param [in] key_bits AES key-bit option
  744. * @param[in] key_idx AES key index
  745. * @return API execution status
  746. */
  747. static inline hpm_stat_t rom_sdp_aes_set_key(sdp_aes_ctx_t *aes_ctx, const uint8_t *key,
  748. sdp_aes_key_bits_t key_bits, uint32_t key_idx)
  749. {
  750. return ROM_API_TABLE_ROOT->sdp_driver_if->aes_set_key(aes_ctx, key, key_bits, key_idx);
  751. }
  752. /**
  753. * @brief SDP AES ECB crypto operation(Encrypt or Decrypt)
  754. * @param [in] aes_ctx AES context
  755. * @param [in] op AES operation: encrypt or decrypt
  756. * @param [in] len Data length for AES encryption/decryption
  757. * @param [in] in Input data
  758. * @param [out] out Output data
  759. * @return API execution status
  760. */
  761. static inline hpm_stat_t rom_sdp_aes_crypt_ecb(sdp_aes_ctx_t *aes_ctx, sdp_aes_op_t op,
  762. uint32_t len, const uint8_t *in, uint8_t *out)
  763. {
  764. return ROM_API_TABLE_ROOT->sdp_driver_if->aes_crypt_ecb(aes_ctx, op, len, in, out);
  765. }
  766. /**
  767. * @brief SDP AES ECB crypto operation(Encrypt or Decrypt)
  768. * @param [in] aes_ctx AES context
  769. * @param [in] op AES operation: encrypt or decrypt
  770. * @param [in] length Data length for AES encryption/decryption
  771. * @param [in] iv Initial vector/nonce
  772. * @param [in] in Input data
  773. * @param [out] out Output data
  774. * @return API execution status
  775. */
  776. static inline hpm_stat_t rom_sdp_aes_crypt_cbc(sdp_aes_ctx_t *aes_ctx, sdp_aes_op_t op, uint32_t length, uint8_t iv[16],
  777. const uint8_t *in, uint8_t *out)
  778. {
  779. return ROM_API_TABLE_ROOT->sdp_driver_if->aes_crypt_cbc(aes_ctx, op, length, iv, in, out);
  780. }
  781. /**
  782. * @brief HASH initialization
  783. * @param [in] hash_ctx HASH context
  784. * @param [in] alg HASH algorithm
  785. * @return API execution status
  786. */
  787. static inline hpm_stat_t rom_sdp_hash_init(sdp_hash_ctx_t *hash_ctx, sdp_hash_alg_t alg)
  788. {
  789. return ROM_API_TABLE_ROOT->sdp_driver_if->hash_init(hash_ctx, alg);
  790. }
  791. /**
  792. * @brief HASH Update
  793. * @param [in] hash_ctx HASH context
  794. * @param [in] data Data for HASH operation
  795. * @param [in] length of the data for HASH operation
  796. * @return API execution status
  797. */
  798. static inline hpm_stat_t rom_sdp_hash_update(sdp_hash_ctx_t *hash_ctx, const uint8_t *data, uint32_t length)
  799. {
  800. return ROM_API_TABLE_ROOT->sdp_driver_if->hash_update(hash_ctx, data, length);
  801. }
  802. /**
  803. * @brief HASH finialize
  804. * @param [in] hash_ctx HASH context
  805. * @param [out] digest the output digest
  806. * @return API execution status
  807. */
  808. static inline hpm_stat_t rom_sdp_hash_finish(sdp_hash_ctx_t *hash_ctx, uint8_t *digest)
  809. {
  810. return ROM_API_TABLE_ROOT->sdp_driver_if->hash_finish(hash_ctx, digest);
  811. }
  812. /**
  813. * @brief SDP memcpy operation
  814. * @param [in] dma_ctx DMA context
  815. * @param [out] dst Destination address for memcpy
  816. * @param [in] src Source address for memcpy
  817. * @param [in] length Size of data for memcpy operation
  818. * @return API execution status
  819. */
  820. static inline hpm_stat_t rom_sdp_memcpy(sdp_dma_ctx_t *dma_ctx, void *dst, const void *src, uint32_t length)
  821. {
  822. return ROM_API_TABLE_ROOT->sdp_driver_if->memcpy(dma_ctx, dst, src, length);
  823. }
  824. /**
  825. * @brief SDP memset operation
  826. * @param [in] dma_ctx DMA context
  827. * @param [out] dst Destination address for memset
  828. * @param [in] pattern pattern for memset
  829. * @param [in] length Size of data for memset operation
  830. * @return API execution status
  831. */
  832. static inline hpm_stat_t rom_sdp_memset(sdp_dma_ctx_t *dma_ctx, void *dst, uint8_t pattern, uint32_t length)
  833. {
  834. return ROM_API_TABLE_ROOT->sdp_driver_if->memset(dma_ctx, dst, pattern, length);
  835. }
  836. /***********************************************************************************************************************
  837. *
  838. *
  839. * SM3 Driver Wrapper
  840. *
  841. *
  842. **********************************************************************************************************************/
  843. /**
  844. * @brief SM4 initialization
  845. *
  846. * @param [in] ctx SM3 context
  847. * @return API execution status
  848. */
  849. static inline hpm_stat_t rom_sm3_init(sm3_context_t *ctx)
  850. {
  851. return ROM_API_TABLE_ROOT->sm3_api_if->init(ctx);
  852. }
  853. /**
  854. * @brief SM3 update operation
  855. *
  856. * @param [in,out] ctx SM3 context
  857. * @param [in] input Data for SM3 calculation
  858. * @param [in] len length of the data for SM3 calculation
  859. * @return API execution status
  860. */
  861. static inline hpm_stat_t rom_sm3_update(sm3_context_t *ctx, const void *input, uint32_t len)
  862. {
  863. return ROM_API_TABLE_ROOT->sm3_api_if->update(ctx, input, len);
  864. }
  865. /**
  866. * @brief SM3 finalize
  867. * Return the computing SM3 digest
  868. *
  869. * @param [in] ctx SM3 context
  870. * @param [out] output SM3 digest calculated by the above API
  871. * @return API execution status
  872. */
  873. static inline hpm_stat_t rom_sm3_finalize(sm3_context_t *ctx, uint8_t output[32])
  874. {
  875. return ROM_API_TABLE_ROOT->sm3_api_if->finalize(ctx, output);
  876. }
  877. /***********************************************************************************************************************
  878. *
  879. *
  880. * SM4 Driver Wrapper
  881. *
  882. *
  883. **********************************************************************************************************************/
  884. /**
  885. * @brief Set SM4 encryption key
  886. *
  887. * @param [in] ctx SM4 context
  888. * @param [in] key SM4 encryption key
  889. */
  890. static inline void rom_sm4_setkey_enc(sm4_context_t *ctx, const uint8_t key[16])
  891. {
  892. ROM_API_TABLE_ROOT->sm4_api_if->setkey_enc(ctx, key);
  893. }
  894. /**
  895. * @brief Set SM4 decryption key
  896. *
  897. * @param [in] ctx SM4 context
  898. * @param [in] key SM4 decryption key
  899. */
  900. static inline void rom_sm4_setkey_dec(sm4_context_t *ctx, const uint8_t key[16])
  901. {
  902. ROM_API_TABLE_ROOT->sm4_api_if->setkey_dec(ctx, key);
  903. }
  904. /**
  905. * @brief SM4 ECB crypto operation(Encrypt or Decrypt)
  906. * @param [in] ctx SM4 context
  907. * @param [in] mode SM4 operation: 1 - ENCRYPT, 0 - DECRYPT
  908. * @param [in] length Data length for SM4 encryption/decryption
  909. * @param [in] input Input data
  910. * @param [out] output Output data
  911. * @return API execution status
  912. */
  913. static inline hpm_stat_t rom_sm4_crypt_ecb(sm4_context_t *ctx, uint32_t mode, uint32_t length, const uint8_t *input,
  914. uint8_t *output)
  915. {
  916. return ROM_API_TABLE_ROOT->sm4_api_if->crypt_ecb(ctx, mode, length, input, output);
  917. }
  918. /**
  919. * @brief SM4 CBC crypto operation(Encrypt or Decrypt)
  920. * @param [in] ctx SM4 context
  921. * @param [in] mode SM4 operation: 1 - ENCRYPT, 0 - DECRYPT
  922. * @param [in] length Data length for SM4 encryption/decryption
  923. * @param [in] input Input data
  924. * @param [out] output Output data
  925. * @return API execution status
  926. */
  927. static inline hpm_stat_t rom_sm4_crypt_cbc(sm4_context_t *ctx, uint32_t mode, uint32_t length, const uint8_t iv[16],
  928. const uint8_t *input, uint8_t *output)
  929. {
  930. return ROM_API_TABLE_ROOT->sm4_api_if->crypt_cbc(ctx, mode, length, iv, input, output);
  931. }
  932. #ifdef __cplusplus
  933. }
  934. #endif
  935. /**
  936. * @}
  937. */
  938. #endif /* HPM_ROMAPI_H */