1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright 2015 Freescale Semiconductor, Inc.
6 #ifndef _FSL_VALIDATE_H_
7 #define _FSL_VALIDATE_H_
10 #include <fsl_sec_mon.h>
11 #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
72 #if defined(CONFIG_FSL_ISBC_KEY_EXT)
73 #define IE_FLAG_MASK 0x1
74 #define SCRATCH_IE_LOW_ADR 13
75 #define SCRATCH_IE_HIGH_ADR 14
78 #else /* CONFIG_ESBC_HDR_LS */
81 * ESBC uboot client header structure.
82 * The struct contain the following fields
87 * length of the signature
89 * no of entries in SG table
97 * Here, pub key is modulus concatenated with exponent
100 struct fsl_secboot_img_hdr {
101 u8 barker[ESBC_BARKER_LEN]; /* barker code */
103 u32 pkey; /* public key offset */
104 #ifdef CONFIG_KEY_REVOCATION
110 u32 key_len; /* pub key length in bytes */
111 #ifdef CONFIG_KEY_REVOCATION
113 u32 srk_table_flag:8;
120 u32 psign; /* signature offset */
121 u32 sign_len; /* length of the signature in bytes */
123 u32 psgtable; /* ptr to SG table */
124 #ifndef CONFIG_ESBC_ADDR_64BIT
125 u32 pimg; /* ptr to ESBC client image */
129 u32 sg_entries; /* no of entries in SG table */
130 u32 img_size; /* ESBC client image size in bytes */
132 u32 img_start; /* ESBC client entry point */
133 u32 sg_flag; /* Scatter gather flag */
142 #ifdef CONFIG_ESBC_ADDR_64BIT
143 u64 pimg64; /* 64 bit pointer to ESBC Image */
150 #ifdef CONFIG_KEY_REVOCATION
151 /* Srk table and key revocation check */
152 #define SRK_FLAG 0x01
153 #define UNREVOCABLE_KEY 4
154 #define ALIGN_REVOC_KEY 3
155 #define MAX_KEY_ENTRIES 4
158 #if defined(CONFIG_FSL_ISBC_KEY_EXT)
159 #define IE_FLAG_MASK 0xFFFFFFFF
162 #endif /* CONFIG_ESBC_HDR_LS */
165 #if defined(CONFIG_FSL_ISBC_KEY_EXT)
166 struct ie_key_table {
168 u8 pkey[2 * KEY_SIZE_BYTES];
174 struct ie_key_table ie_key_tbl[32];
178 #ifdef CONFIG_KEY_REVOCATION
181 u8 pkey[2 * KEY_SIZE_BYTES];
188 #if defined(CONFIG_FSL_TRUST_ARCH_v1) && defined(CONFIG_FSL_CORENET)
190 * This struct contains the following fields
191 * length of the segment
194 struct fsl_secboot_sg_table {
195 u32 len; /* length of the segment in bytes */
196 u32 src_addr; /* ptr to the data segment */
200 * This struct contains the following fields
201 * length of the segment
202 * Destination Target ID
204 * destination address
206 struct fsl_secboot_sg_table {
214 /* ESBC global structure.
215 * Data to be used across verification of different images.
216 * Stores following Data:
219 struct fsl_secboot_glb {
220 #if defined(CONFIG_FSL_ISBC_KEY_EXT)
222 struct ie_key_info ie_tbl;
226 * ESBC private structure.
227 * Private structure used by ESBC to store following fields
229 * ESBC client key hash
230 * ESBC client Signature
231 * Encoded hash recovered from signature
232 * Encoded hash of ESBC client header plus ESBC client image
234 struct fsl_secboot_img_priv {
235 uint32_t hdr_location;
238 struct fsl_secboot_img_hdr hdr;
240 u8 img_key[2 * KEY_SIZE_BYTES]; /* ESBC client key */
241 u8 img_key_hash[32]; /* ESBC client key hash */
243 #ifdef CONFIG_KEY_REVOCATION
244 struct srk_table srk_tbl[MAX_KEY_ENTRIES];
246 u8 img_sign[KEY_SIZE_BYTES]; /* ESBC client signature */
248 u8 img_encoded_hash[KEY_SIZE_BYTES]; /* EM wrt RSA PKCSv1.5 */
249 /* Includes hash recovered after
250 * signature verification
253 u8 img_encoded_hash_second[KEY_SIZE_BYTES];/* EM' wrt RSA PKCSv1.5 */
255 * ESBC client header plus
259 struct fsl_secboot_sg_table sgtbl[MAX_SG_ENTRIES]; /* SG table */
260 uintptr_t ehdrloc; /* ESBC Header location */
261 uintptr_t *img_addr_ptr; /* ESBC Image Location */
262 uint32_t img_size; /* ESBC Image Size */
265 int do_esbc_halt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
267 int fsl_secboot_validate(uintptr_t haddr, char *arg_hash_str,
268 uintptr_t *img_addr_ptr);
269 int fsl_secboot_blob_encap(struct cmd_tbl *cmdtp, int flag, int argc,
271 int fsl_secboot_blob_decap(struct cmd_tbl *cmdtp, int flag, int argc,
274 int fsl_check_boot_mode_secure(void);
275 int fsl_setenv_chain_of_trust(void);
278 * This function is used to validate the main U-boot binary from
279 * SPL just before passing control to it using QorIQ Trust
280 * Architecture header (appended to U-boot image).
282 void spl_validate_uboot(uint32_t hdr_addr, uintptr_t img_addr);