HPM SDK
HPMicro Software Development Kit
hpm_romapi.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2024 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_ROMAPI_H
9 #define HPM_ROMAPI_H
10 
17 #include "hpm_common.h"
18 #include "hpm_otp_drv.h"
19 #include "hpm_romapi_xpi_def.h"
20 #include "hpm_romapi_xpi_soc_def.h"
21 #include "hpm_romapi_xpi_nor_def.h"
22 #include "hpm_romapi_xpi_ram_def.h"
23 #include "hpm_sdp_drv.h"
24 
25 /* XPI0 base address */
26 #define HPM_XPI0_BASE (0xF3040000UL)
27 /* XPI0 base pointer */
28 #define HPM_XPI0 ((XPI_Type *) HPM_XPI0_BASE)
29 /* XPI1 base address */
30 #define HPM_XPI1_BASE (0xF3044000UL)
31 /* XPI1 base pointer */
32 #define HPM_XPI1 ((XPI_Type *) HPM_XPI1_BASE)
35 /***********************************************************************************************************************
36  *
37  *
38  * Definitions
39  *
40  *
41  **********************************************************************************************************************/
45 typedef union {
46  uint32_t U;
47  struct {
48  uint32_t index: 8;
49  uint32_t peripheral: 8;
50  uint32_t src: 8;
51  uint32_t tag: 8;
52  };
54 
55 /*EXiP Region Parameter */
56 typedef struct {
57  uint32_t start;
58  uint32_t len;
59  uint8_t key[16];
60  uint8_t ctr[8];
62 
63 #define API_BOOT_TAG (0xEBU)
64 #define API_BOOT_SRC_OTP (0U)
65 #define API_BOOT_SRC_PRIMARY (1U)
66 #define API_BOOT_SRC_SERIAL_BOOT (2U)
67 #define API_BOOT_SRC_ISP (3U)
68 #define API_BOOT_PERIPH_AUTO (0U)
69 #define API_BOOT_PERIPH_UART (1U)
70 #define API_BOOT_PERIPH_USBHID (2U)
72 typedef struct {
73  uint32_t _internal[138];
75 
76 
77 #define SM4_ENCRYPT 1
78 #define SM4_DECRYPT 0
79 
80 typedef struct {
81  uint32_t mode;
82  uint32_t _internal[116];
84 
88 typedef struct {
90  uint32_t version;
92  void (*init)(void);
94  void (*deinit)(void);
96  uint32_t (*read_from_shadow)(uint32_t addr);
98  uint32_t (*read_from_ip)(uint32_t addr);
100  hpm_stat_t (*program)(uint32_t addr, const uint32_t *src, uint32_t num_of_words);
102  hpm_stat_t (*reload)(otp_region_t region);
104  hpm_stat_t (*lock)(uint32_t addr, otp_lock_option_t lock_option);
106  hpm_stat_t (*lock_shadow)(uint32_t addr, otp_lock_option_t lock_option);
108  hpm_stat_t (*set_configurable_region)(uint32_t start, uint32_t num_of_words);
110  hpm_stat_t (*write_shadow_register)(uint32_t addr, uint32_t data);
112 
116 typedef struct {
118  uint32_t version;
120  hpm_stat_t (*get_default_config)(xpi_config_t *xpi_config);
122  hpm_stat_t (*get_default_device_config)(xpi_device_config_t *dev_config);
124  hpm_stat_t (*init)(XPI_Type *base, xpi_config_t *xpi_config);
126  hpm_stat_t (*config_ahb_buffer)(XPI_Type *base, xpi_ahb_buffer_cfg_t *ahb_buf_cfg);
128  hpm_stat_t (*config_device)(XPI_Type *base, xpi_device_config_t *dev_cfg, xpi_channel_t channel);
130  hpm_stat_t (*update_instr_table)(XPI_Type *base, const uint32_t *inst_base, uint32_t seq_idx, uint32_t num);
132  hpm_stat_t (*transfer_blocking)(XPI_Type *base, xpi_xfer_ctx_t *xfer);
134  void (*software_reset)(XPI_Type *base);
136  bool (*is_idle)(XPI_Type *base);
138  void (*update_dllcr)(XPI_Type *base,
139  uint32_t serial_root_clk_freq,
140  uint32_t data_valid_time,
141  xpi_channel_t channel,
142  uint32_t dly_target);
144  hpm_stat_t
145  (*get_abs_apb_xfer_addr)(XPI_Type *base, xpi_xfer_channel_t channel, uint32_t in_addr, uint32_t *out_addr);
147 
151 typedef struct {
153  uint32_t version;
155  hpm_stat_t (*get_config)(XPI_Type *base, xpi_nor_config_t *nor_cfg, xpi_nor_config_option_t *cfg_option);
157  hpm_stat_t (*init)(XPI_Type *base, xpi_nor_config_t *nor_config);
159  hpm_stat_t
160  (*enable_write)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t addr);
162  hpm_stat_t (*get_status)(XPI_Type *base,
163  xpi_xfer_channel_t channel,
164  const xpi_nor_config_t *nor_config,
165  uint32_t addr,
166  uint16_t *out_status);
168  hpm_stat_t
169  (*wait_busy)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t addr);
171  hpm_stat_t (*erase)(XPI_Type *base,
172  xpi_xfer_channel_t channel,
173  const xpi_nor_config_t *nor_config,
174  uint32_t start,
175  uint32_t length);
177  hpm_stat_t (*erase_chip)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config);
179  hpm_stat_t
180  (*erase_sector)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t addr);
182  hpm_stat_t
183  (*erase_block)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t addr);
185  hpm_stat_t (*program)(XPI_Type *base,
186  xpi_xfer_channel_t channel,
187  const xpi_nor_config_t *nor_config,
188  const uint32_t *src,
189  uint32_t dst_addr,
190  uint32_t length);
192  hpm_stat_t (*read)(XPI_Type *base,
193  xpi_xfer_channel_t channel,
194  const xpi_nor_config_t *nor_config,
195  uint32_t *dst,
196  uint32_t start,
197  uint32_t length);
199  hpm_stat_t (*page_program_nonblocking)(XPI_Type *base,
200  xpi_xfer_channel_t channel,
201  const xpi_nor_config_t *nor_config,
202  const uint32_t *src,
203  uint32_t dst_addr,
204  uint32_t length);
206  hpm_stat_t (*erase_sector_nonblocking)(XPI_Type *base,
207  xpi_xfer_channel_t channel,
208  const xpi_nor_config_t *nor_config,
209  uint32_t addr);
211  hpm_stat_t (*erase_block_nonblocking)(XPI_Type *base,
212  xpi_xfer_channel_t channel,
213  const xpi_nor_config_t *nor_config,
214  uint32_t addr);
216  hpm_stat_t
217  (*erase_chip_nonblocking)(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config);
218 
219  uint32_t reserved0[3];
220 
222  hpm_stat_t (*auto_config)(XPI_Type *base, xpi_nor_config_t *nor_cfg, xpi_nor_config_option_t *cfg_option);
223 
225  hpm_stat_t (*get_property)(XPI_Type *base, xpi_nor_config_t *nor_cfg, uint32_t property_id, uint32_t *value);
226 
228 
232 typedef struct {
234  uint32_t version;
235 
237  hpm_stat_t (*get_config)(XPI_Type *base, xpi_ram_config_t *ram_cfg, xpi_ram_config_option_t *cfg_option);
238 
240  hpm_stat_t (*init)(XPI_Type *base, xpi_ram_config_t *ram_cfg);
242 
246 typedef struct {
248  uint32_t version;
250  hpm_stat_t (*sdp_ip_init)(void);
252  hpm_stat_t (*sdp_ip_deinit)(void);
254  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);
256  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);
258  hpm_stat_t (*aes_crypt_cbc)(sdp_aes_ctx_t *aes_ctx,
259  sdp_aes_op_t op,
260  uint32_t length,
261  uint8_t iv[16],
262  const uint8_t *input,
263  uint8_t *output);
265  hpm_stat_t
266  (*aes_crypt_ctr)(sdp_aes_ctx_t *aes_ctx, uint8_t *nonce_ctr, uint8_t *input, uint8_t *output, uint32_t length);
268  hpm_stat_t (*aes_ccm_gen_enc)(sdp_aes_ctx_t *aes_ctx,
269  uint32_t input_len,
270  const uint8_t *nonce,
271  uint32_t nonce_len,
272  const uint8_t *aad,
273  uint32_t aad_len,
274  const uint8_t *input,
275  uint8_t *output,
276  uint8_t *tag,
277  uint32_t tag_len);
279  hpm_stat_t (*aes_ccm_dec_verify)(sdp_aes_ctx_t *aes_ctx,
280  uint32_t input_len,
281  const uint8_t *nonce,
282  uint32_t nonce_len,
283  const uint8_t *aad,
284  uint32_t aad_len,
285  const uint8_t *input,
286  uint8_t *output,
287  const uint8_t *tag,
288  uint32_t tag_len);
290  hpm_stat_t (*memcpy)(sdp_dma_ctx_t *dma_ctx, void *dst, const void *src, uint32_t length);
292  hpm_stat_t (*memset)(sdp_dma_ctx_t *dma_ctx, void *dst, uint8_t pattern, uint32_t length);
294  hpm_stat_t (*hash_init)(sdp_hash_ctx_t *hash_ctx, sdp_hash_alg_t alg);
296  hpm_stat_t (*hash_update)(sdp_hash_ctx_t *hash_ctx, const uint8_t *data, uint32_t length);
298  hpm_stat_t (*hash_finish)(sdp_hash_ctx_t *hash_ctx, uint8_t *digest);
300 
301 typedef struct {
303  uint32_t version;
307  hpm_stat_t (*update)(sm3_context_t *ctx, const void *input, uint32_t len);
309  hpm_stat_t (*finalize)(sm3_context_t *ctx, uint8_t output[32]);
311 
312 typedef struct {
314  uint32_t version;
316  void (*setkey_enc)(sm4_context_t *ctx, const uint8_t key[16]);
318  void (*setkey_dec)(sm4_context_t *ctx, const uint8_t key[16]);
320  hpm_stat_t (*crypt_ecb)(sm4_context_t *ctx, uint32_t mode, uint32_t length, const uint8_t *input, uint8_t *output);
322  hpm_stat_t (*crypt_cbc)(sm4_context_t *ctx, uint32_t mode, uint32_t length, const uint8_t iv[16],
323  const uint8_t *input, uint8_t *output);
325  hpm_stat_t (*crypt_ctr)(sm4_context_t *ctx, uint8_t *nonce_counter, const uint8_t *input,
326  uint8_t *output, uint32_t length);
328  hpm_stat_t (*ccm_gen_enc)(sm4_context_t *ctx, uint32_t input_len, const uint8_t *iv,
329  uint32_t iv_len, const uint8_t *aad, uint32_t aad_len, const uint8_t *input,
330  uint8_t *output, uint8_t *tag, uint32_t tag_len);
332  hpm_stat_t (*ccm_dec_verify)(sm4_context_t *ctx, uint32_t input_len, const uint8_t *iv,
333  uint32_t iv_len, const uint8_t *aad, uint32_t aad_len, const uint8_t *input,
334  uint8_t *output, const uint8_t *tag, uint32_t tag_len);
336 
337 
341 typedef struct {
343  const uint32_t version;
345  const char *copyright;
347  hpm_stat_t (*run_bootloader)(void *arg);
349  const otp_driver_interface_t *otp_driver_if;
351  const xpi_driver_interface_t *xpi_driver_if;
353  const xpi_nor_driver_interface_t *xpi_nor_driver_if;
355  const xpi_ram_driver_interface_t *xpi_ram_driver_if;
357  const sdp_driver_interface_t *sdp_driver_if;
358  const uint32_t reserved0;
359  const sm3_api_interface_t *sm3_api_if; /* SM3 driver interface address */
360  const sm4_api_interface_t *sm4_api_if; /* SM4 driver itnerface address */
362 
364 #define ROM_API_TABLE_ROOT ((const bootloader_api_table_t*)0x2001FF00U)
365 
366 
367 #ifdef __cplusplus
368 extern "C" {
369 #endif
370 
371 /***********************************************************************************************************************
372  *
373  *
374  * Enter bootloader Wrapper
375  *
376  *
377  **********************************************************************************************************************/
378 
384 static inline hpm_stat_t rom_enter_bootloader(void *ctx)
385 {
386  return ROM_API_TABLE_ROOT->run_bootloader(ctx);
387 }
388 
389 /***********************************************************************************************************************
390  *
391  *
392  * XPI NOR Driver Wrapper
393  *
394  *
395  **********************************************************************************************************************/
396 
404 ATTR_RAMFUNC
406  xpi_nor_config_option_t *cfg_option)
407 {
408  hpm_stat_t status;
409  status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->get_config(base, nor_cfg, cfg_option);
410  fencei();
411  return status;
412 }
413 
420 ATTR_RAMFUNC
421 static inline hpm_stat_t rom_xpi_nor_init(XPI_Type *base, xpi_nor_config_t *nor_config)
422 {
423  hpm_stat_t status;
424  status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->init(base, nor_config);
425  fencei();
426  return status;
427 }
428 
438 ATTR_RAMFUNC
440  xpi_xfer_channel_t channel,
441  const xpi_nor_config_t *nor_config,
442  uint32_t start,
443  uint32_t length)
444 {
445  hpm_stat_t status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase(base, channel, nor_config, start, length);
446  fencei();
447  return status;
448 }
449 
458 ATTR_RAMFUNC
460  xpi_xfer_channel_t channel,
461  const xpi_nor_config_t *nor_config,
462  uint32_t start)
463 {
464  hpm_stat_t status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_sector(base, channel, nor_config, start);
465  fencei();
466  return status;
467 }
468 
477 ATTR_RAMFUNC
479  xpi_xfer_channel_t channel,
480  const xpi_nor_config_t *nor_config,
481  uint32_t start)
482 {
483  return ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_sector_nonblocking(base, channel, nor_config, start);
484 }
485 
494 ATTR_RAMFUNC
496  xpi_xfer_channel_t channel,
497  const xpi_nor_config_t *nor_config,
498  uint32_t start)
499 {
500  hpm_stat_t status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_block(base, channel, nor_config, start);
501  fencei();
502  return status;
503 }
504 
513 ATTR_RAMFUNC
515  xpi_xfer_channel_t channel,
516  const xpi_nor_config_t *nor_config,
517  uint32_t start)
518 {
519  return ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_block_nonblocking(base, channel, nor_config, start);
520 }
521 
529 ATTR_RAMFUNC
531  xpi_xfer_channel_t channel,
532  const xpi_nor_config_t *nor_config)
533 {
534  hpm_stat_t status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_chip(base, channel, nor_config);
535  fencei();
536  return status;
537 }
538 
546 ATTR_RAMFUNC
548  xpi_xfer_channel_t channel,
549  const xpi_nor_config_t *nor_config)
550 {
551  hpm_stat_t status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->erase_chip_nonblocking(base, channel, nor_config);
552  fencei();
553  return status;
554 }
555 
566 ATTR_RAMFUNC
568  xpi_xfer_channel_t channel,
569  const xpi_nor_config_t *nor_config,
570  const uint32_t *src,
571  uint32_t dst_addr,
572  uint32_t length)
573 {
574  hpm_stat_t status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->program(base, channel, nor_config, src, dst_addr, length);
575  fencei();
576  return status;
577 }
578 
589 ATTR_RAMFUNC
591  xpi_xfer_channel_t channel,
592  const xpi_nor_config_t *nor_config,
593  const uint32_t *src,
594  uint32_t dst_addr,
595  uint32_t length)
596 {
597  return ROM_API_TABLE_ROOT->xpi_nor_driver_if
598  ->page_program_nonblocking(base, channel, nor_config, src, dst_addr, length);
599 }
600 
612  xpi_xfer_channel_t channel,
613  const xpi_nor_config_t *nor_config,
614  uint32_t *dst,
615  uint32_t start,
616  uint32_t length)
617 {
618  return ROM_API_TABLE_ROOT->xpi_nor_driver_if->read(base, channel, nor_config, dst, start, length);
619 }
620 
628 ATTR_RAMFUNC
630  xpi_nor_config_option_t *cfg_option)
631 {
632  hpm_stat_t status;
633  status = ROM_API_TABLE_ROOT->xpi_nor_driver_if->auto_config(base, config, cfg_option);
634  fencei();
635  return status;
636 }
637 
647  xpi_nor_config_t *nor_cfg,
648  uint32_t property_id,
649  uint32_t *value)
650 {
651  return ROM_API_TABLE_ROOT->xpi_nor_driver_if->get_property(base, nor_cfg, property_id, value);
652 }
653 
665  xpi_xfer_channel_t channel,
666  const xpi_nor_config_t *nor_config,
667  uint32_t addr,
668  uint16_t *out_status)
669 {
670  return ROM_API_TABLE_ROOT->xpi_nor_driver_if->get_status(base, channel, nor_config, addr, out_status);
671 }
672 
682 ATTR_RAMFUNC
683 static inline bool rom_xpi_nor_remap_config(XPI_Type *base, uint32_t start, uint32_t len, uint32_t offset)
684 {
685  if (((base != HPM_XPI0) && (base != HPM_XPI1)) || ((start & 0xFFF) != 0) || ((len & 0xFFF) != 0)
686  || ((offset & 0xFFF) != 0)) {
687  return false;
688  }
689  static const uint8_t k_mc_xpi_remap_config[] = {
690  0x2e, 0x96, 0x23, 0x22, 0xc5, 0x42, 0x23, 0x24,
691  0xd5, 0x42, 0x93, 0xe5, 0x15, 0x00, 0x23, 0x20,
692  0xb5, 0x42, 0x05, 0x45, 0x82, 0x80,
693  };
694  typedef bool (*remap_config_cb_t)(XPI_Type *, uint32_t, uint32_t, uint32_t);
695  remap_config_cb_t cb = (remap_config_cb_t) &k_mc_xpi_remap_config;
696  bool result = cb(base, start, len, offset);
697  ROM_API_TABLE_ROOT->xpi_driver_if->software_reset(base);
698  fencei();
699  return result;
700 }
701 
706 ATTR_RAMFUNC
707 static inline void rom_xpi_nor_remap_disable(XPI_Type *base)
708 {
709  static const uint8_t k_mc_xpi_remap_disable[] = {
710  0x83, 0x27, 0x05, 0x42, 0xf9, 0x9b, 0x23, 0x20,
711  0xf5, 0x42, 0x82, 0x80,
712  };
713  typedef void (*remap_disable_cb_t)(XPI_Type *);
714  remap_disable_cb_t cb = (remap_disable_cb_t) &k_mc_xpi_remap_disable;
715  cb(base);
716  fencei();
717 }
718 
726 ATTR_RAMFUNC
727 static inline bool rom_xpi_nor_is_remap_enabled(XPI_Type *base)
728 {
729  static const uint8_t k_mc_xpi_remap_enabled[] = {
730  0x03, 0x25, 0x05, 0x42, 0x05, 0x89, 0x82, 0x80,
731  };
732  typedef bool (*remap_chk_cb_t)(XPI_Type *);
733  remap_chk_cb_t chk_cb = (remap_chk_cb_t) &k_mc_xpi_remap_enabled;
734  return chk_cb(base);
735 }
736 
745 ATTR_RAMFUNC
746 static inline bool rom_xpi_nor_exip_region_config(XPI_Type *base, uint32_t index, exip_region_param_t *param)
747 {
748  if (base != HPM_XPI0) {
749  return false;
750  }
751  static const uint8_t k_mc_exip_region_config[] = {
752  0x18, 0x4a, 0x9a, 0x05, 0x2e, 0x95, 0x85, 0x67,
753  0xaa, 0x97, 0x23, 0xa4, 0xe7, 0xd0, 0x4c, 0x4a,
754  0x14, 0x42, 0x58, 0x42, 0x23, 0xa6, 0xb7, 0xd0,
755  0x4c, 0x46, 0x36, 0x97, 0x13, 0x77, 0x07, 0xc0,
756  0x23, 0xa2, 0xb7, 0xd0, 0x0c, 0x46, 0x13, 0x67,
757  0x37, 0x00, 0x05, 0x45, 0x23, 0xa0, 0xb7, 0xd0,
758  0x0c, 0x4e, 0x23, 0xaa, 0xb7, 0xd0, 0x50, 0x4e,
759  0x23, 0xa8, 0xc7, 0xd0, 0x23, 0xac, 0xd7, 0xd0,
760  0x23, 0xae, 0xe7, 0xd0, 0x82, 0x80,
761  };
762  typedef void (*exip_region_config_cb_t)(XPI_Type *, uint32_t, exip_region_param_t *);
763  exip_region_config_cb_t cb = (exip_region_config_cb_t) &k_mc_exip_region_config;
764  cb(base, index, param);
765  ROM_API_TABLE_ROOT->xpi_driver_if->software_reset(base);
766  fencei();
767  return true;
768 }
769 
775 ATTR_RAMFUNC
776 static inline void rom_xpi_nor_exip_region_disable(XPI_Type *base, uint32_t index)
777 {
778  static const uint8_t k_mc_exip_region_disable[] = {
779  0x9a, 0x05, 0x2e, 0x95, 0x85, 0x67, 0xaa, 0x97,
780  0x03, 0xa7, 0xc7, 0xd1, 0x75, 0x9b, 0x23, 0xae,
781  0xe7, 0xd0, 0x82, 0x80
782  };
783  typedef void (*exip_region_disable_cb_t)(XPI_Type *, uint32_t);
784  exip_region_disable_cb_t cb = (exip_region_disable_cb_t) &k_mc_exip_region_disable;
785  cb(base, index);
786  ROM_API_TABLE_ROOT->xpi_driver_if->software_reset(base);
787  fencei();
788 }
789 
794 ATTR_RAMFUNC
795 static inline void rom_xpi_nor_exip_enable(XPI_Type *base)
796 {
797  static const uint8_t k_mc_exip_enable[] = {
798  0x85, 0x67, 0x3e, 0x95, 0x83, 0x27, 0x05, 0xc0,
799  0x37, 0x07, 0x00, 0x80, 0xd9, 0x8f, 0x23, 0x20,
800  0xf5, 0xc0, 0x82, 0x80
801  };
802  typedef void (*exip_enable_cb_t)(XPI_Type *);
803  exip_enable_cb_t cb = (exip_enable_cb_t) &k_mc_exip_enable;
804  cb(base);
805 }
806 
811 ATTR_RAMFUNC
812 static inline void rom_xpi_nor_exip_disable(XPI_Type *base)
813 {
814  static const uint8_t k_mc_exip_disable[] = {
815  0x85, 0x67, 0x3e, 0x95, 0x83, 0x27, 0x05, 0xc0,
816  0x86, 0x07, 0x85, 0x83, 0x23, 0x20, 0xf5, 0xc0,
817  0x82, 0x80
818  };
819  typedef void (*exip_disable_cb_t)(XPI_Type *);
820  exip_disable_cb_t cb = (exip_disable_cb_t) &k_mc_exip_disable;
821  cb(base);
822  ROM_API_TABLE_ROOT->xpi_driver_if->software_reset(base);
823  fencei();
824 }
825 
826 /***********************************************************************************************************************
827  *
828  *
829  * XPI RAM Driver Wrapper
830  *
831  *
832  **********************************************************************************************************************/
841  xpi_ram_config_t *ram_cfg,
842  xpi_ram_config_option_t *cfg_option)
843 {
844  return ROM_API_TABLE_ROOT->xpi_ram_driver_if->get_config(base, ram_cfg, cfg_option);
845 }
846 
853 static inline hpm_stat_t rom_xpi_ram_init(XPI_Type *base, xpi_ram_config_t *ram_cfg)
854 {
855  return ROM_API_TABLE_ROOT->xpi_ram_driver_if->init(base, ram_cfg);
856 }
857 
858 /***********************************************************************************************************************
859  *
860  *
861  * SDP Driver Wrapper
862  *
863  *
864  **********************************************************************************************************************/
868 static inline void rom_sdp_init(void)
869 {
870  ROM_API_TABLE_ROOT->sdp_driver_if->sdp_ip_init();
871 }
872 
876 static inline void rom_sdp_deinit(void)
877 {
878  ROM_API_TABLE_ROOT->sdp_driver_if->sdp_ip_deinit();
879 }
880 
890  const uint8_t *key,
891  sdp_aes_key_bits_t key_bits,
892  uint32_t key_idx)
893 {
894  return ROM_API_TABLE_ROOT->sdp_driver_if->aes_set_key(aes_ctx, key, key_bits, key_idx);
895 }
896 
907  sdp_aes_op_t op,
908  uint32_t len,
909  const uint8_t *in,
910  uint8_t *out)
911 {
912  return ROM_API_TABLE_ROOT->sdp_driver_if->aes_crypt_ecb(aes_ctx, op, len, in, out);
913 }
914 
926  sdp_aes_op_t op,
927  uint32_t length,
928  uint8_t iv[16],
929  const uint8_t *in,
930  uint8_t *out)
931 {
932  return ROM_API_TABLE_ROOT->sdp_driver_if->aes_crypt_cbc(aes_ctx, op, length, iv, in, out);
933 }
934 
942 {
943  return ROM_API_TABLE_ROOT->sdp_driver_if->hash_init(hash_ctx, alg);
944 }
945 
953 static inline hpm_stat_t rom_sdp_hash_update(sdp_hash_ctx_t *hash_ctx, const uint8_t *data, uint32_t length)
954 {
955  return ROM_API_TABLE_ROOT->sdp_driver_if->hash_update(hash_ctx, data, length);
956 }
957 
964 static inline hpm_stat_t rom_sdp_hash_finish(sdp_hash_ctx_t *hash_ctx, uint8_t *digest)
965 {
966  return ROM_API_TABLE_ROOT->sdp_driver_if->hash_finish(hash_ctx, digest);
967 }
968 
977 static inline hpm_stat_t rom_sdp_memcpy(sdp_dma_ctx_t *dma_ctx, void *dst, const void *src, uint32_t length)
978 {
979  return ROM_API_TABLE_ROOT->sdp_driver_if->memcpy(dma_ctx, dst, src, length);
980 }
981 
990 static inline hpm_stat_t rom_sdp_memset(sdp_dma_ctx_t *dma_ctx, void *dst, uint8_t pattern, uint32_t length)
991 {
992  return ROM_API_TABLE_ROOT->sdp_driver_if->memset(dma_ctx, dst, pattern, length);
993 }
994 
995 
996 /***********************************************************************************************************************
997  *
998  *
999  * SM3 Driver Wrapper
1000  *
1001  *
1002  **********************************************************************************************************************/
1003 
1011 {
1012  return ROM_API_TABLE_ROOT->sm3_api_if->init(ctx);
1013 }
1014 
1023 static inline hpm_stat_t rom_sm3_update(sm3_context_t *ctx, const void *input, uint32_t len)
1024 {
1025  return ROM_API_TABLE_ROOT->sm3_api_if->update(ctx, input, len);
1026 }
1027 
1036 static inline hpm_stat_t rom_sm3_finalize(sm3_context_t *ctx, uint8_t output[32])
1037 {
1038  return ROM_API_TABLE_ROOT->sm3_api_if->finalize(ctx, output);
1039 }
1040 
1041 /***********************************************************************************************************************
1042  *
1043  *
1044  * SM4 Driver Wrapper
1045  *
1046  *
1047  **********************************************************************************************************************/
1054 static inline void rom_sm4_setkey_enc(sm4_context_t *ctx, const uint8_t key[16])
1055 {
1056  ROM_API_TABLE_ROOT->sm4_api_if->setkey_enc(ctx, key);
1057 }
1058 
1065 static inline void rom_sm4_setkey_dec(sm4_context_t *ctx, const uint8_t key[16])
1066 {
1067  ROM_API_TABLE_ROOT->sm4_api_if->setkey_dec(ctx, key);
1068 }
1069 
1079 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)
1080 {
1081  return ROM_API_TABLE_ROOT->sm4_api_if->crypt_ecb(ctx, mode, length, input, output);
1082 }
1083 
1094 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)
1095 {
1096  return ROM_API_TABLE_ROOT->sm4_api_if->crypt_cbc(ctx, mode, length, iv, input, output);
1097 }
1098 
1099 
1100 
1101 #ifdef __cplusplus
1102 }
1103 #endif
1104 
1110 #endif /* HPM_ROMAPI_H */
static hpm_stat_t rom_sdp_memset(sdp_dma_ctx_t *dma_ctx, void *dst, uint8_t pattern, uint32_t length)
SDP memset operation.
Definition: hpm_romapi.h:990
static 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], const uint8_t *in, uint8_t *out)
SDP AES ECB crypto operation(Encrypt or Decrypt)
Definition: hpm_romapi.h:925
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_auto_config(XPI_Type *base, xpi_nor_config_t *config, xpi_nor_config_option_t *cfg_option)
Automatically configure XPI NOR based on cfg_option.
Definition: hpm_romapi.h:629
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_init(XPI_Type *base, xpi_nor_config_t *nor_config)
Initialize XPI NOR based on nor_config.
Definition: hpm_romapi.h:421
static hpm_stat_t rom_xpi_nor_read(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t *dst, uint32_t start, uint32_t length)
Read data from specified FLASH address.
Definition: hpm_romapi.h:611
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_erase_chip_nonblocking(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config)
Erase the whole FLASH in non-blocking way.
Definition: hpm_romapi.h:547
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_erase_chip(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config)
Erase the whole FLASH in blocking way.
Definition: hpm_romapi.h:530
static hpm_stat_t rom_sdp_memcpy(sdp_dma_ctx_t *dma_ctx, void *dst, const void *src, uint32_t length)
SDP memcpy operation.
Definition: hpm_romapi.h:977
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_erase_block(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t start)
Erase specified FLASH blcok in blocking way.
Definition: hpm_romapi.h:495
static ATTR_RAMFUNC bool rom_xpi_nor_remap_config(XPI_Type *base, uint32_t start, uint32_t len, uint32_t offset)
Configure the XPI Address Remapping Logic.
Definition: hpm_romapi.h:683
static ATTR_RAMFUNC bool rom_xpi_nor_exip_region_config(XPI_Type *base, uint32_t index, exip_region_param_t *param)
Configure Specified EXiP Region.
Definition: hpm_romapi.h:746
static ATTR_RAMFUNC void rom_xpi_nor_exip_enable(XPI_Type *base)
Enable global EXiP logic.
Definition: hpm_romapi.h:795
static void rom_sdp_init(void)
Initialize SDP IP.
Definition: hpm_romapi.h:868
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_page_program_nonblocking(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, const uint32_t *src, uint32_t dst_addr, uint32_t length)
Page-Program data to specified FLASH address in non-blocking way.
Definition: hpm_romapi.h:590
static ATTR_RAMFUNC void rom_xpi_nor_exip_region_disable(XPI_Type *base, uint32_t index)
Disable EXiP Feature on specified EXiP Region.
Definition: hpm_romapi.h:776
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_erase_sector_nonblocking(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t start)
Erase specified FLASH sector in non-blocking way.
Definition: hpm_romapi.h:478
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_erase(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t start, uint32_t length)
Erase specified FLASH region.
Definition: hpm_romapi.h:439
static hpm_stat_t rom_enter_bootloader(void *ctx)
Eneter specified Boot mode.
Definition: hpm_romapi.h:384
static ATTR_RAMFUNC void rom_xpi_nor_remap_disable(XPI_Type *base)
Disable XPI Remapping logic.
Definition: hpm_romapi.h:707
static hpm_stat_t rom_sdp_aes_set_key(sdp_aes_ctx_t *aes_ctx, const uint8_t *key, sdp_aes_key_bits_t key_bits, uint32_t key_idx)
Set AES key to SDP.
Definition: hpm_romapi.h:889
static void rom_sdp_deinit(void)
De-initialize SDP IP.
Definition: hpm_romapi.h:876
static hpm_stat_t rom_xpi_ram_get_config(XPI_Type *base, xpi_ram_config_t *ram_cfg, xpi_ram_config_option_t *cfg_option)
Get XPI RAM configuration based on cfg_option.
Definition: hpm_romapi.h:840
static hpm_stat_t rom_xpi_ram_init(XPI_Type *base, xpi_ram_config_t *ram_cfg)
Initialize XPI RAM.
Definition: hpm_romapi.h:853
static hpm_stat_t rom_xpi_nor_get_status(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t addr, uint16_t *out_status)
Return the status register value on XPI NOR FLASH.
Definition: hpm_romapi.h:664
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_erase_block_nonblocking(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t start)
Erase specified FLASH blcok in non-blocking way.
Definition: hpm_romapi.h:514
static ATTR_RAMFUNC void rom_xpi_nor_exip_disable(XPI_Type *base)
Disable global EXiP logic.
Definition: hpm_romapi.h:812
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_program(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, const uint32_t *src, uint32_t dst_addr, uint32_t length)
Program data to specified FLASH address in blocking way.
Definition: hpm_romapi.h:567
static ATTR_RAMFUNC bool rom_xpi_nor_is_remap_enabled(XPI_Type *base)
Check whether XPI Remapping is enabled.
Definition: hpm_romapi.h:727
static hpm_stat_t rom_sdp_hash_finish(sdp_hash_ctx_t *hash_ctx, uint8_t *digest)
HASH finialize.
Definition: hpm_romapi.h:964
static hpm_stat_t rom_sdp_hash_update(sdp_hash_ctx_t *hash_ctx, const uint8_t *data, uint32_t length)
HASH Update.
Definition: hpm_romapi.h:953
static hpm_stat_t rom_sdp_aes_crypt_ecb(sdp_aes_ctx_t *aes_ctx, sdp_aes_op_t op, uint32_t len, const uint8_t *in, uint8_t *out)
SDP AES ECB crypto operation(Encrypt or Decrypt)
Definition: hpm_romapi.h:906
static hpm_stat_t rom_xpi_nor_get_property(XPI_Type *base, xpi_nor_config_t *nor_cfg, uint32_t property_id, uint32_t *value)
Get XPI NOR properties.
Definition: hpm_romapi.h:646
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_get_config(XPI_Type *base, xpi_nor_config_t *nor_cfg, xpi_nor_config_option_t *cfg_option)
Get XPI NOR configuration via cfg_option.
Definition: hpm_romapi.h:405
static hpm_stat_t rom_sdp_hash_init(sdp_hash_ctx_t *hash_ctx, sdp_hash_alg_t alg)
HASH initialization.
Definition: hpm_romapi.h:941
static ATTR_RAMFUNC hpm_stat_t rom_xpi_nor_erase_sector(XPI_Type *base, xpi_xfer_channel_t channel, const xpi_nor_config_t *nor_config, uint32_t start)
Erase specified FLASH sector in blocking way.
Definition: hpm_romapi.h:459
static void init(hpm_panel_t *panel)
Definition: cc10128007.c:86
uint32_t hpm_stat_t
Definition: hpm_common.h:123
otp_region_t
OTP region definitions.
Definition: hpm_otp_drv.h:24
otp_lock_option_t
OTP lock options.
Definition: hpm_otp_drv.h:34
static hpm_stat_t rom_sm3_init(sm3_context_t *ctx)
SM4 initialization.
Definition: hpm_romapi.h:1010
static void rom_sm4_setkey_enc(sm4_context_t *ctx, const uint8_t key[16])
Set SM4 encryption key.
Definition: hpm_romapi.h:1054
static hpm_stat_t rom_sm3_finalize(sm3_context_t *ctx, uint8_t output[32])
SM3 finalize Return the computing SM3 digest.
Definition: hpm_romapi.h:1036
static hpm_stat_t rom_sm3_update(sm3_context_t *ctx, const void *input, uint32_t len)
SM3 update operation.
Definition: hpm_romapi.h:1023
#define HPM_XPI0
Definition: hpm_romapi.h:28
#define ROM_API_TABLE_ROOT
Definition: hpm_romapi.h:364
static void rom_sm4_setkey_dec(sm4_context_t *ctx, const uint8_t key[16])
Set SM4 decryption key.
Definition: hpm_romapi.h:1065
#define HPM_XPI1
Definition: hpm_romapi.h:32
static hpm_stat_t rom_sm4_crypt_ecb(sm4_context_t *ctx, uint32_t mode, uint32_t length, const uint8_t *input, uint8_t *output)
SM4 ECB crypto operation(Encrypt or Decrypt)
Definition: hpm_romapi.h:1079
static 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)
SM4 CBC crypto operation(Encrypt or Decrypt)
Definition: hpm_romapi.h:1094
sdp_crypto_op_t
Crypto operation option.
Definition: hpm_sdp_drv.h:44
sdp_crypto_key_bits_t
SDP AES key bit options.
Definition: hpm_sdp_drv.h:29
sdp_hash_alg_t
SDP HASH algorithm definitions.
Definition: hpm_sdp_drv.h:102
xpi_xfer_channel_t
XPI Transfer Channel type definitions.
Definition: hpm_romapi_xpi_def.h:53
uint32_t XPI_Type
XPI_Type definitions for.
Definition: hpm_romapi_xpi_def.h:22
xpi_channel_t
XPI Channel definitions.
Definition: hpm_romapi_xpi_def.h:64
static hpm_stat_t read(void *ops, hpm_serial_nor_transfer_seq_t *cmd_seq)
Definition: hpm_serial_nor_host_spi.c:309
#define fencei()
execute fence.i
Definition: riscv_core.h:88
Bootloader API table.
Definition: hpm_romapi.h:243
const sm3_api_interface_t * sm3_api_if
Definition: hpm_romapi.h:359
const sm4_api_interface_t * sm4_api_if
Definition: hpm_romapi.h:360
Definition: hpm_romapi.h:52
OTP driver interface.
Definition: hpm_romapi.h:82
SDP AES context structure.
Definition: hpm_sdp_drv.h:159
SDP DMA context.
Definition: hpm_sdp_drv.h:179
SDP API interface.
Definition: hpm_romapi.h:243
SDP HASH context.
Definition: hpm_sdp_drv.h:186
Definition: hpm_romapi.h:301
uint32_t version
Definition: hpm_romapi.h:303
Definition: hpm_romapi.h:72
Definition: hpm_romapi.h:312
uint32_t version
Definition: hpm_romapi.h:314
Definition: hpm_romapi.h:80
uint32_t mode
Definition: hpm_romapi.h:81
Definition: hpm_romapi_xpi_soc_def.h:28
XPI configuration structure.
Definition: hpm_romapi_xpi_def.h:160
XPI Device Configuration structure.
Definition: hpm_romapi_xpi_def.h:173
XPI driver interface.
Definition: hpm_romapi.h:110
XPI NOR configuration option The ROM SW can detect the FLASH configuration based on the following str...
Definition: hpm_romapi_xpi_nor_def.h:136
XPI NOR configuration structure.
Definition: hpm_romapi_xpi_nor_def.h:261
XPI NOR driver interface.
Definition: hpm_romapi.h:145
XPI RAM configuration option The ROM SW can detect the FLASH configuration based on the following str...
Definition: hpm_romapi_xpi_ram_def.h:39
XPI RAM configuration structure.
Definition: hpm_romapi_xpi_ram_def.h:152
XPI RAM driver interface.
Definition: hpm_romapi.h:215
XPI Xfer context.
Definition: hpm_romapi_xpi_def.h:93
Enter Bootloader API argument.
Definition: hpm_romapi.h:41