hpm_romapi.h 42 KB

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