hab.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (C) 2012-2015 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. *
  6. */
  7. #ifndef __SECURE_MX6Q_H__
  8. #define __SECURE_MX6Q_H__
  9. #include <linux/types.h>
  10. /*
  11. * IVT header definitions
  12. * Security Reference Manual for i.MX 7Dual and 7Solo Applications Processors,
  13. * Rev. 0, 03/2017
  14. * Section : 6.7.1.1
  15. */
  16. #define IVT_HEADER_MAGIC 0xD1
  17. #define IVT_TOTAL_LENGTH 0x20
  18. #define IVT_HEADER_V1 0x40
  19. #define IVT_HEADER_V2 0x41
  20. struct ivt_header {
  21. uint8_t magic;
  22. uint16_t length;
  23. uint8_t version;
  24. } __attribute__((packed));
  25. struct ivt {
  26. struct ivt_header hdr; /* IVT header above */
  27. uint32_t entry; /* Absolute address of first instruction */
  28. uint32_t reserved1; /* Reserved should be zero */
  29. uint32_t dcd; /* Absolute address of the image DCD */
  30. uint32_t boot; /* Absolute address of the boot data */
  31. uint32_t self; /* Absolute address of the IVT */
  32. uint32_t csf; /* Absolute address of the CSF */
  33. uint32_t reserved2; /* Reserved should be zero */
  34. };
  35. /* -------- start of HAB API updates ------------*/
  36. /* The following are taken from HAB4 SIS */
  37. /* Status definitions */
  38. enum hab_status {
  39. HAB_STS_ANY = 0x00,
  40. HAB_FAILURE = 0x33,
  41. HAB_WARNING = 0x69,
  42. HAB_SUCCESS = 0xf0
  43. };
  44. /* Security Configuration definitions */
  45. enum hab_config {
  46. HAB_CFG_RETURN = 0x33, /* < Field Return IC */
  47. HAB_CFG_OPEN = 0xf0, /* < Non-secure IC */
  48. HAB_CFG_CLOSED = 0xcc /* < Secure IC */
  49. };
  50. /* State definitions */
  51. enum hab_state {
  52. HAB_STATE_INITIAL = 0x33, /* Initialising state (transitory) */
  53. HAB_STATE_CHECK = 0x55, /* Check state (non-secure) */
  54. HAB_STATE_NONSECURE = 0x66, /* Non-secure state */
  55. HAB_STATE_TRUSTED = 0x99, /* Trusted state */
  56. HAB_STATE_SECURE = 0xaa, /* Secure state */
  57. HAB_STATE_FAIL_SOFT = 0xcc, /* Soft fail state */
  58. HAB_STATE_FAIL_HARD = 0xff, /* Hard fail state (terminal) */
  59. HAB_STATE_NONE = 0xf0, /* No security state machine */
  60. HAB_STATE_MAX
  61. };
  62. enum hab_reason {
  63. HAB_RSN_ANY = 0x00, /* Match any reason */
  64. HAB_ENG_FAIL = 0x30, /* Engine failure */
  65. HAB_INV_ADDRESS = 0x22, /* Invalid address: access denied */
  66. HAB_INV_ASSERTION = 0x0c, /* Invalid assertion */
  67. HAB_INV_CALL = 0x28, /* Function called out of sequence */
  68. HAB_INV_CERTIFICATE = 0x21, /* Invalid certificate */
  69. HAB_INV_COMMAND = 0x06, /* Invalid command: command malformed */
  70. HAB_INV_CSF = 0x11, /* Invalid csf */
  71. HAB_INV_DCD = 0x27, /* Invalid dcd */
  72. HAB_INV_INDEX = 0x0f, /* Invalid index: access denied */
  73. HAB_INV_IVT = 0x05, /* Invalid ivt */
  74. HAB_INV_KEY = 0x1d, /* Invalid key */
  75. HAB_INV_RETURN = 0x1e, /* Failed callback function */
  76. HAB_INV_SIGNATURE = 0x18, /* Invalid signature */
  77. HAB_INV_SIZE = 0x17, /* Invalid data size */
  78. HAB_MEM_FAIL = 0x2e, /* Memory failure */
  79. HAB_OVR_COUNT = 0x2b, /* Expired poll count */
  80. HAB_OVR_STORAGE = 0x2d, /* Exhausted storage region */
  81. HAB_UNS_ALGORITHM = 0x12, /* Unsupported algorithm */
  82. HAB_UNS_COMMAND = 0x03, /* Unsupported command */
  83. HAB_UNS_ENGINE = 0x0a, /* Unsupported engine */
  84. HAB_UNS_ITEM = 0x24, /* Unsupported configuration item */
  85. HAB_UNS_KEY = 0x1b, /* Unsupported key type/parameters */
  86. HAB_UNS_PROTOCOL = 0x14, /* Unsupported protocol */
  87. HAB_UNS_STATE = 0x09, /* Unsuitable state */
  88. HAB_RSN_MAX
  89. };
  90. enum hab_context {
  91. HAB_CTX_ANY = 0x00, /* Match any context */
  92. HAB_CTX_FAB = 0xff, /* Event logged in hab_fab_test() */
  93. HAB_CTX_ENTRY = 0xe1, /* Event logged in hab_rvt.entry() */
  94. HAB_CTX_TARGET = 0x33, /* Event logged in hab_rvt.check_target() */
  95. HAB_CTX_AUTHENTICATE = 0x0a,/* Logged in hab_rvt.authenticate_image() */
  96. HAB_CTX_DCD = 0xdd, /* Event logged in hab_rvt.run_dcd() */
  97. HAB_CTX_CSF = 0xcf, /* Event logged in hab_rvt.run_csf() */
  98. HAB_CTX_COMMAND = 0xc0, /* Event logged executing csf/dcd command */
  99. HAB_CTX_AUT_DAT = 0xdb, /* Authenticated data block */
  100. HAB_CTX_ASSERT = 0xa0, /* Event logged in hab_rvt.assert() */
  101. HAB_CTX_EXIT = 0xee, /* Event logged in hab_rvt.exit() */
  102. HAB_CTX_MAX
  103. };
  104. enum hab_target {
  105. HAB_TGT_MEMORY = 0x0f,
  106. HAB_TGT_PERIPHERAL = 0xf0,
  107. HAB_TGT_ANY = 0x55,
  108. };
  109. struct imx_sec_config_fuse_t {
  110. int bank;
  111. int word;
  112. };
  113. #if defined(CONFIG_SECURE_BOOT)
  114. extern struct imx_sec_config_fuse_t const imx_sec_config_fuse;
  115. #endif
  116. /*Function prototype description*/
  117. typedef enum hab_status hab_rvt_report_event_t(enum hab_status, uint32_t,
  118. uint8_t* , size_t*);
  119. typedef enum hab_status hab_rvt_report_status_t(enum hab_config *,
  120. enum hab_state *);
  121. typedef enum hab_status hab_loader_callback_f_t(void**, size_t*, const void*);
  122. typedef enum hab_status hab_rvt_entry_t(void);
  123. typedef enum hab_status hab_rvt_exit_t(void);
  124. typedef void *hab_rvt_authenticate_image_t(uint8_t, ptrdiff_t,
  125. void **, size_t *, hab_loader_callback_f_t);
  126. typedef enum hab_status hab_rvt_check_target_t(enum hab_target, const void *,
  127. size_t);
  128. typedef void hab_rvt_failsafe_t(void);
  129. typedef void hapi_clock_init_t(void);
  130. #define HAB_ENG_ANY 0x00 /* Select first compatible engine */
  131. #define HAB_ENG_SCC 0x03 /* Security controller */
  132. #define HAB_ENG_RTIC 0x05 /* Run-time integrity checker */
  133. #define HAB_ENG_SAHARA 0x06 /* Crypto accelerator */
  134. #define HAB_ENG_CSU 0x0a /* Central Security Unit */
  135. #define HAB_ENG_SRTC 0x0c /* Secure clock */
  136. #define HAB_ENG_DCP 0x1b /* Data Co-Processor */
  137. #define HAB_ENG_CAAM 0x1d /* CAAM */
  138. #define HAB_ENG_SNVS 0x1e /* Secure Non-Volatile Storage */
  139. #define HAB_ENG_OCOTP 0x21 /* Fuse controller */
  140. #define HAB_ENG_DTCP 0x22 /* DTCP co-processor */
  141. #define HAB_ENG_ROM 0x36 /* Protected ROM area */
  142. #define HAB_ENG_HDCP 0x24 /* HDCP co-processor */
  143. #define HAB_ENG_RTL 0x77 /* RTL simulation engine */
  144. #define HAB_ENG_SW 0xff /* Software engine */
  145. #ifdef CONFIG_ROM_UNIFIED_SECTIONS
  146. #define HAB_RVT_BASE 0x00000100
  147. #else
  148. #define HAB_RVT_BASE 0x00000094
  149. #endif
  150. #define HAB_RVT_ENTRY (*(uint32_t *)(HAB_RVT_BASE + 0x04))
  151. #define HAB_RVT_EXIT (*(uint32_t *)(HAB_RVT_BASE + 0x08))
  152. #define HAB_RVT_CHECK_TARGET (*(uint32_t *)(HAB_RVT_BASE + 0x0C))
  153. #define HAB_RVT_AUTHENTICATE_IMAGE (*(uint32_t *)(HAB_RVT_BASE + 0x10))
  154. #define HAB_RVT_REPORT_EVENT (*(uint32_t *)(HAB_RVT_BASE + 0x20))
  155. #define HAB_RVT_REPORT_STATUS (*(uint32_t *)(HAB_RVT_BASE + 0x24))
  156. #define HAB_RVT_FAILSAFE (*(uint32_t *)(HAB_RVT_BASE + 0x28))
  157. #define HAB_RVT_REPORT_EVENT_NEW (*(uint32_t *)0x000000B8)
  158. #define HAB_RVT_REPORT_STATUS_NEW (*(uint32_t *)0x000000BC)
  159. #define HAB_RVT_AUTHENTICATE_IMAGE_NEW (*(uint32_t *)0x000000A8)
  160. #define HAB_RVT_ENTRY_NEW (*(uint32_t *)0x0000009C)
  161. #define HAB_RVT_EXIT_NEW (*(uint32_t *)0x000000A0)
  162. #define HAB_CID_ROM 0 /**< ROM Caller ID */
  163. #define HAB_CID_UBOOT 1 /**< UBOOT Caller ID*/
  164. #define IVT_SIZE 0x20
  165. #define CSF_PAD_SIZE 0x2000
  166. /* ----------- end of HAB API updates ------------*/
  167. int imx_hab_authenticate_image(uint32_t ddr_start, uint32_t image_size,
  168. uint32_t ivt_offset);
  169. bool imx_hab_is_enabled(void);
  170. #endif