hal_rom_api.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Copyright (C) 2017 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _HAL_ROM_API_H_
  13. #define _HAL_ROM_API_H_
  14. #include "osi_compiler.h"
  15. OSI_EXTERN_C_BEGIN
  16. /**
  17. * \brief parameter for loader entry
  18. *
  19. * This is pre-defined loader parameters. For example, when FDL1 can
  20. * support download from multiple devices, the parameter will indicate
  21. * the download device. So, FDL1 will known the download device.
  22. */
  23. enum
  24. {
  25. ROM_LOADPAR_NORMAL = 0,
  26. ROM_LOADPAR_DOWNLOAD_UART1 = 0x01,
  27. ROM_LOADPAR_DOWNLOAD_UART2 = 0x02,
  28. ROM_LOADPAR_DOWNLOAD_UART3 = 0x03,
  29. ROM_LOADPAR_DOWNLOAD_UART4 = 0x04,
  30. ROM_LOADPAR_DOWNLOAD_UART5 = 0x05,
  31. ROM_LOADPAR_DOWNLOAD_UART6 = 0x06,
  32. ROM_LOADPAR_DOWNLOAD_USERIAL = 0x08,
  33. ROM_LOADPAR_FROM_BOOT2 = 0x10,
  34. ROM_LOADPAR_FROM_SDCARD = 0x11,
  35. };
  36. typedef struct
  37. {
  38. uintptr_t block_start;
  39. uintptr_t block_end;
  40. unsigned req_size;
  41. unsigned alloc_size;
  42. unsigned req_size_max;
  43. unsigned alloc_size_max;
  44. unsigned high_mark;
  45. } halRomMemPool_t;
  46. typedef struct
  47. {
  48. uint8_t *in;
  49. uint32_t len;
  50. uint8_t *out;
  51. uint8_t *key;
  52. uint8_t *iv;
  53. bool key_from_kce;
  54. } sym_dec_t;
  55. bool halRomApiInit(void);
  56. void halRomSetLogPrintf(void *fn);
  57. halRomMemPool_t *halRomGetMemPool(void);
  58. bool halRomSetMemPool(void *mem, unsigned size);
  59. void *halRomMalloc(unsigned size);
  60. void halRomFree(void *ptr);
  61. typedef struct halRomSha256Context halRomSha256Context_t;
  62. unsigned halRomSha256ContextSize(void);
  63. void halRomSha256Init(halRomSha256Context_t *ctx);
  64. void halRomSha256Update(halRomSha256Context_t *ctx, const void *input, unsigned size);
  65. void halRomSha256Final(halRomSha256Context_t *ctx, void *output);
  66. void halRomSha256Calc(const void *input, unsigned size, void *output);
  67. typedef struct halRomSm3Context halRomSm3Context_t;
  68. unsigned halRomSm3ContextSize(void);
  69. void halRomSm3Init(halRomSm3Context_t *ctx);
  70. void halRomSm3Update(halRomSm3Context_t *ctx, const void *input, unsigned size);
  71. void halRomSm3Final(halRomSm3Context_t *ctx, void *output);
  72. void halRomSm3Calc(const void *input, unsigned size, void *output);
  73. bool halRomRsaVerify(unsigned nbytes, unsigned e, const void *n,
  74. unsigned padtype, const void *sigdata, unsigned sigbytes,
  75. const void *hash, unsigned hashbytes);
  76. bool halRomEccVerify(unsigned curve, const void *ecp_x, unsigned xbytes,
  77. const void *ecp_y, unsigned ybytes,
  78. const void *sig_r, unsigned rbytes,
  79. const void *sig_s, unsigned sbytes,
  80. const void *hash, unsigned hashbytes);
  81. bool halRomSm2Verify(const void *ecp_x, const void *ecp_y,
  82. const void *sig_r, const void *sig_s,
  83. const void *hash, unsigned hashbytes);
  84. bool halRomSm4Decrypt(sym_dec_t *param);
  85. bool halRomAesDecrypt(sym_dec_t *param);
  86. typedef struct simageHeader simageHeader_t;
  87. bool halRomSimageSignVerify(const simageHeader_t *header,
  88. const osiBits256_t *rotpk,
  89. const osiBits64_t *soc_raw_id,
  90. unsigned min_secure_version);
  91. bool halRomSimageDataDecrypt(simageHeader_t *header);
  92. bool halRomSimageHeaderValid(const simageHeader_t *header, unsigned max_size);
  93. bool halRomSimagePayloadValid(const simageHeader_t *header);
  94. bool halRomSimageValid(const simageHeader_t *header, unsigned max_size);
  95. void *halRomGetUserial(void);
  96. void halRomUserialOpen(void *ser);
  97. int halRomUserialGetChar(void *ser);
  98. int halRomUserialPutChar(void *ser, uint8_t ch);
  99. void halRomUserialPoll(void *ser);
  100. void halRomUserialFlush(void *ser);
  101. void *getEfuseContent(void);
  102. OSI_EXTERN_C_END
  103. #endif