2 * Copyright 2015 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
7 #ifndef _FSL_VALIDATE_H_
8 #define _FSL_VALIDATE_H_
11 #include <fsl_sec_mon.h>
13 #include <linux/types.h>
17 /* Minimum and maximum size of RSA signature length in bits */
19 #define KEY_SIZE_BYTES (KEY_SIZE/8)
20 #define KEY_SIZE_WORDS (KEY_SIZE_BYTES/(WORD_SIZE))
22 extern struct jobring jr;
24 /* Barker code size in bytes */
25 #define ESBC_BARKER_LEN 4 /* barker code length in ESBC uboot client */
28 /* No-error return values */
29 #define ESBC_VALID_HDR 0 /* header is valid */
31 /* Maximum number of SG entries allowed */
32 #define MAX_SG_ENTRIES 8
34 /* Different Header Struct for LS-CH3 */
35 #ifdef CONFIG_ESBC_HDR_LS
36 struct fsl_secboot_img_hdr {
37 u8 barker[ESBC_BARKER_LEN]; /* barker code */
48 u32 psign; /* signature offset */
49 u32 sign_len; /* length of the signature in bytes */
51 u64 pimg64; /* 64 bit pointer to ESBC Image */
52 u32 img_size; /* ESBC client image size in bytes */
65 #ifdef CONFIG_KEY_REVOCATION
66 /* Srk table and key revocation check */
67 #define UNREVOCABLE_KEY 8
68 #define ALIGN_REVOC_KEY 7
69 #define MAX_KEY_ENTRIES 8
73 #else /* CONFIG_ESBC_HDR_LS */
76 * ESBC uboot client header structure.
77 * The struct contain the following fields
82 * length of the signature
84 * no of entries in SG table
92 * Here, pub key is modulus concatenated with exponent
95 struct fsl_secboot_img_hdr {
96 u8 barker[ESBC_BARKER_LEN]; /* barker code */
98 u32 pkey; /* public key offset */
99 #ifdef CONFIG_KEY_REVOCATION
105 u32 key_len; /* pub key length in bytes */
106 #ifdef CONFIG_KEY_REVOCATION
108 u32 srk_table_flag:8;
115 u32 psign; /* signature offset */
116 u32 sign_len; /* length of the signature in bytes */
118 u32 psgtable; /* ptr to SG table */
119 #ifndef CONFIG_ESBC_ADDR_64BIT
120 u32 pimg; /* ptr to ESBC client image */
124 u32 sg_entries; /* no of entries in SG table */
125 u32 img_size; /* ESBC client image size in bytes */
127 u32 img_start; /* ESBC client entry point */
128 u32 sg_flag; /* Scatter gather flag */
137 #ifdef CONFIG_ESBC_ADDR_64BIT
138 u64 pimg64; /* 64 bit pointer to ESBC Image */
145 #ifdef CONFIG_KEY_REVOCATION
146 /* Srk table and key revocation check */
147 #define SRK_FLAG 0x01
148 #define UNREVOCABLE_KEY 4
149 #define ALIGN_REVOC_KEY 3
150 #define MAX_KEY_ENTRIES 4
153 #endif /* CONFIG_ESBC_HDR_LS */
156 #if defined(CONFIG_FSL_ISBC_KEY_EXT)
157 struct ie_key_table {
159 u8 pkey[2 * KEY_SIZE_BYTES];
165 struct ie_key_table ie_key_tbl[32];
169 #ifdef CONFIG_KEY_REVOCATION
172 u8 pkey[2 * KEY_SIZE_BYTES];
179 #if defined(CONFIG_FSL_TRUST_ARCH_v1) && defined(CONFIG_FSL_CORENET)
181 * This struct contains the following fields
182 * length of the segment
185 struct fsl_secboot_sg_table {
186 u32 len; /* length of the segment in bytes */
187 u32 src_addr; /* ptr to the data segment */
191 * This struct contains the following fields
192 * length of the segment
193 * Destination Target ID
195 * destination address
197 struct fsl_secboot_sg_table {
206 * ESBC private structure.
207 * Private structure used by ESBC to store following fields
209 * ESBC client key hash
210 * ESBC client Signature
211 * Encoded hash recovered from signature
212 * Encoded hash of ESBC client header plus ESBC client image
214 struct fsl_secboot_img_priv {
215 uint32_t hdr_location;
218 struct fsl_secboot_img_hdr hdr;
220 u8 img_key[2 * KEY_SIZE_BYTES]; /* ESBC client key */
221 u8 img_key_hash[32]; /* ESBC client key hash */
223 #ifdef CONFIG_KEY_REVOCATION
224 struct srk_table srk_tbl[MAX_KEY_ENTRIES];
226 u8 img_sign[KEY_SIZE_BYTES]; /* ESBC client signature */
228 u8 img_encoded_hash[KEY_SIZE_BYTES]; /* EM wrt RSA PKCSv1.5 */
229 /* Includes hash recovered after
230 * signature verification
233 u8 img_encoded_hash_second[KEY_SIZE_BYTES];/* EM' wrt RSA PKCSv1.5 */
235 * ESBC client header plus
239 struct fsl_secboot_sg_table sgtbl[MAX_SG_ENTRIES]; /* SG table */
240 uintptr_t ehdrloc; /* ESBC Header location */
241 uintptr_t *img_addr_ptr; /* ESBC Image Location */
242 uint32_t img_size; /* ESBC Image Size */
245 int do_esbc_halt(cmd_tbl_t *cmdtp, int flag, int argc,
246 char * const argv[]);
248 int fsl_secboot_validate(uintptr_t haddr, char *arg_hash_str,
249 uintptr_t *img_addr_ptr);
250 int fsl_secboot_blob_encap(cmd_tbl_t *cmdtp, int flag, int argc,
251 char * const argv[]);
252 int fsl_secboot_blob_decap(cmd_tbl_t *cmdtp, int flag, int argc,
253 char * const argv[]);
255 int fsl_check_boot_mode_secure(void);
256 int fsl_setenv_chain_of_trust(void);
259 * This function is used to validate the main U-boot binary from
260 * SPL just before passing control to it using QorIQ Trust
261 * Architecture header (appended to U-boot image).
263 void spl_validate_uboot(uint32_t hdr_addr, uintptr_t img_addr);