fsl_validate.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright 2015 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef _FSL_VALIDATE_H_
  7. #define _FSL_VALIDATE_H_
  8. #include <fsl_sec.h>
  9. #include <fsl_sec_mon.h>
  10. #include <command.h>
  11. #include <linux/types.h>
  12. #define WORD_SIZE 4
  13. /* Minimum and maximum size of RSA signature length in bits */
  14. #define KEY_SIZE 4096
  15. #define KEY_SIZE_BYTES (KEY_SIZE/8)
  16. #define KEY_SIZE_WORDS (KEY_SIZE_BYTES/(WORD_SIZE))
  17. extern struct jobring jr;
  18. /* Barker code size in bytes */
  19. #define ESBC_BARKER_LEN 4 /* barker code length in ESBC uboot client */
  20. /* header */
  21. /* No-error return values */
  22. #define ESBC_VALID_HDR 0 /* header is valid */
  23. /* Maximum number of SG entries allowed */
  24. #define MAX_SG_ENTRIES 8
  25. /* Different Header Struct for LS-CH3 */
  26. #ifdef CONFIG_ESBC_HDR_LS
  27. struct fsl_secboot_img_hdr {
  28. u8 barker[ESBC_BARKER_LEN]; /* barker code */
  29. u32 srk_tbl_off;
  30. struct {
  31. u8 num_srk;
  32. u8 srk_sel;
  33. u8 reserve;
  34. u8 ie_flag;
  35. } len_kr;
  36. u32 uid_flag;
  37. u32 psign; /* signature offset */
  38. u32 sign_len; /* length of the signature in bytes */
  39. u64 pimg64; /* 64 bit pointer to ESBC Image */
  40. u32 img_size; /* ESBC client image size in bytes */
  41. u32 ie_key_sel;
  42. u32 fsl_uid_0;
  43. u32 fsl_uid_1;
  44. u32 oem_uid_0;
  45. u32 oem_uid_1;
  46. u32 oem_uid_2;
  47. u32 oem_uid_3;
  48. u32 oem_uid_4;
  49. u32 reserved1[3];
  50. };
  51. #ifdef CONFIG_KEY_REVOCATION
  52. /* Srk table and key revocation check */
  53. #define UNREVOCABLE_KEY 8
  54. #define ALIGN_REVOC_KEY 7
  55. #define MAX_KEY_ENTRIES 8
  56. #endif
  57. #else /* CONFIG_ESBC_HDR_LS */
  58. /*
  59. * ESBC uboot client header structure.
  60. * The struct contain the following fields
  61. * barker code
  62. * public key offset
  63. * pub key length
  64. * signature offset
  65. * length of the signature
  66. * ptr to SG table
  67. * no of entries in SG table
  68. * esbc ptr
  69. * size of esbc
  70. * esbc entry point
  71. * Scatter gather flag
  72. * UID flag
  73. * FSL UID
  74. * OEM UID
  75. * Here, pub key is modulus concatenated with exponent
  76. * of equal length
  77. */
  78. struct fsl_secboot_img_hdr {
  79. u8 barker[ESBC_BARKER_LEN]; /* barker code */
  80. union {
  81. u32 pkey; /* public key offset */
  82. #ifdef CONFIG_KEY_REVOCATION
  83. u32 srk_tbl_off;
  84. #endif
  85. };
  86. union {
  87. u32 key_len; /* pub key length in bytes */
  88. #ifdef CONFIG_KEY_REVOCATION
  89. struct {
  90. u32 srk_table_flag:8;
  91. u32 srk_sel:8;
  92. u32 num_srk:16;
  93. } len_kr;
  94. #endif
  95. };
  96. u32 psign; /* signature offset */
  97. u32 sign_len; /* length of the signature in bytes */
  98. union {
  99. u32 psgtable; /* ptr to SG table */
  100. #ifndef CONFIG_ESBC_ADDR_64BIT
  101. u32 pimg; /* ptr to ESBC client image */
  102. #endif
  103. };
  104. union {
  105. u32 sg_entries; /* no of entries in SG table */
  106. u32 img_size; /* ESBC client image size in bytes */
  107. };
  108. u32 img_start; /* ESBC client entry point */
  109. u32 sg_flag; /* Scatter gather flag */
  110. u32 uid_flag;
  111. u32 fsl_uid_0;
  112. u32 oem_uid_0;
  113. u32 reserved1[2];
  114. u32 fsl_uid_1;
  115. u32 oem_uid_1;
  116. union {
  117. u32 reserved2[2];
  118. #ifdef CONFIG_ESBC_ADDR_64BIT
  119. u64 pimg64; /* 64 bit pointer to ESBC Image */
  120. #endif
  121. };
  122. u32 ie_flag;
  123. u32 ie_key_sel;
  124. };
  125. #ifdef CONFIG_KEY_REVOCATION
  126. /* Srk table and key revocation check */
  127. #define SRK_FLAG 0x01
  128. #define UNREVOCABLE_KEY 4
  129. #define ALIGN_REVOC_KEY 3
  130. #define MAX_KEY_ENTRIES 4
  131. #endif
  132. #endif /* CONFIG_ESBC_HDR_LS */
  133. #if defined(CONFIG_FSL_ISBC_KEY_EXT)
  134. struct ie_key_table {
  135. u32 key_len;
  136. u8 pkey[2 * KEY_SIZE_BYTES];
  137. };
  138. struct ie_key_info {
  139. uint32_t key_revok;
  140. uint32_t num_keys;
  141. struct ie_key_table ie_key_tbl[32];
  142. };
  143. #endif
  144. #ifdef CONFIG_KEY_REVOCATION
  145. struct srk_table {
  146. u32 key_len;
  147. u8 pkey[2 * KEY_SIZE_BYTES];
  148. };
  149. #endif
  150. /*
  151. * SG table.
  152. */
  153. #if defined(CONFIG_FSL_TRUST_ARCH_v1) && defined(CONFIG_FSL_CORENET)
  154. /*
  155. * This struct contains the following fields
  156. * length of the segment
  157. * source address
  158. */
  159. struct fsl_secboot_sg_table {
  160. u32 len; /* length of the segment in bytes */
  161. u32 src_addr; /* ptr to the data segment */
  162. };
  163. #else
  164. /*
  165. * This struct contains the following fields
  166. * length of the segment
  167. * Destination Target ID
  168. * source address
  169. * destination address
  170. */
  171. struct fsl_secboot_sg_table {
  172. u32 len;
  173. u32 trgt_id;
  174. u32 src_addr;
  175. u32 dst_addr;
  176. };
  177. #endif
  178. /*
  179. * ESBC private structure.
  180. * Private structure used by ESBC to store following fields
  181. * ESBC client key
  182. * ESBC client key hash
  183. * ESBC client Signature
  184. * Encoded hash recovered from signature
  185. * Encoded hash of ESBC client header plus ESBC client image
  186. */
  187. struct fsl_secboot_img_priv {
  188. uint32_t hdr_location;
  189. u32 ie_addr;
  190. u32 key_len;
  191. struct fsl_secboot_img_hdr hdr;
  192. u8 img_key[2 * KEY_SIZE_BYTES]; /* ESBC client key */
  193. u8 img_key_hash[32]; /* ESBC client key hash */
  194. #ifdef CONFIG_KEY_REVOCATION
  195. struct srk_table srk_tbl[MAX_KEY_ENTRIES];
  196. #endif
  197. u8 img_sign[KEY_SIZE_BYTES]; /* ESBC client signature */
  198. u8 img_encoded_hash[KEY_SIZE_BYTES]; /* EM wrt RSA PKCSv1.5 */
  199. /* Includes hash recovered after
  200. * signature verification
  201. */
  202. u8 img_encoded_hash_second[KEY_SIZE_BYTES];/* EM' wrt RSA PKCSv1.5 */
  203. /* Includes hash of
  204. * ESBC client header plus
  205. * ESBC client image
  206. */
  207. struct fsl_secboot_sg_table sgtbl[MAX_SG_ENTRIES]; /* SG table */
  208. uintptr_t ehdrloc; /* ESBC Header location */
  209. uintptr_t *img_addr_ptr; /* ESBC Image Location */
  210. uint32_t img_size; /* ESBC Image Size */
  211. };
  212. int do_esbc_halt(cmd_tbl_t *cmdtp, int flag, int argc,
  213. char * const argv[]);
  214. int fsl_secboot_validate(uintptr_t haddr, char *arg_hash_str,
  215. uintptr_t *img_addr_ptr);
  216. int fsl_secboot_blob_encap(cmd_tbl_t *cmdtp, int flag, int argc,
  217. char * const argv[]);
  218. int fsl_secboot_blob_decap(cmd_tbl_t *cmdtp, int flag, int argc,
  219. char * const argv[]);
  220. int fsl_check_boot_mode_secure(void);
  221. int fsl_setenv_chain_of_trust(void);
  222. /*
  223. * This function is used to validate the main U-boot binary from
  224. * SPL just before passing control to it using QorIQ Trust
  225. * Architecture header (appended to U-boot image).
  226. */
  227. void spl_validate_uboot(uint32_t hdr_addr, uintptr_t img_addr);
  228. #endif