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 #ifdef CONFIG_KEY_REVOCATION
25 /* Srk table and key revocation check */
27 #define UNREVOCABLE_KEY 4
28 #define ALIGN_REVOC_KEY 3
29 #define MAX_KEY_ENTRIES 4
32 /* Barker code size in bytes */
33 #define ESBC_BARKER_LEN 4 /* barker code length in ESBC uboot client */
36 /* No-error return values */
37 #define ESBC_VALID_HDR 0 /* header is valid */
39 /* Maximum number of SG entries allowed */
40 #define MAX_SG_ENTRIES 8
43 * ESBC uboot client header structure.
44 * The struct contain the following fields
49 * length of the signature
51 * no of entries in SG table
59 * Here, pub key is modulus concatenated with exponent
62 struct fsl_secboot_img_hdr {
63 u8 barker[ESBC_BARKER_LEN]; /* barker code */
65 u32 pkey; /* public key offset */
66 #ifdef CONFIG_KEY_REVOCATION
72 u32 key_len; /* pub key length in bytes */
73 #ifdef CONFIG_KEY_REVOCATION
82 u32 psign; /* signature offset */
83 u32 sign_len; /* length of the signature in bytes */
85 u32 psgtable; /* ptr to SG table */
86 #ifndef CONFIG_ESBC_ADDR_64BIT
87 u32 pimg; /* ptr to ESBC client image */
91 u32 sg_entries; /* no of entries in SG table */
92 u32 img_size; /* ESBC client image size in bytes */
94 u32 img_start; /* ESBC client entry point */
95 u32 sg_flag; /* Scatter gather flag */
104 #ifdef CONFIG_ESBC_ADDR_64BIT
105 u64 pimg64; /* 64 bit pointer to ESBC Image */
112 #if defined(CONFIG_FSL_ISBC_KEY_EXT)
113 struct ie_key_table {
115 u8 pkey[2 * KEY_SIZE_BYTES];
121 struct ie_key_table ie_key_tbl[32];
125 #ifdef CONFIG_KEY_REVOCATION
128 u8 pkey[2 * KEY_SIZE_BYTES];
135 #if defined(CONFIG_FSL_TRUST_ARCH_v1) && defined(CONFIG_FSL_CORENET)
137 * This struct contains the following fields
138 * length of the segment
141 struct fsl_secboot_sg_table {
142 u32 len; /* length of the segment in bytes */
143 u32 src_addr; /* ptr to the data segment */
147 * This struct contains the following fields
148 * length of the segment
149 * Destination Target ID
151 * destination address
153 struct fsl_secboot_sg_table {
162 * ESBC private structure.
163 * Private structure used by ESBC to store following fields
165 * ESBC client key hash
166 * ESBC client Signature
167 * Encoded hash recovered from signature
168 * Encoded hash of ESBC client header plus ESBC client image
170 struct fsl_secboot_img_priv {
171 uint32_t hdr_location;
174 struct fsl_secboot_img_hdr hdr;
176 u8 img_key[2 * KEY_SIZE_BYTES]; /* ESBC client key */
177 u8 img_key_hash[32]; /* ESBC client key hash */
179 #ifdef CONFIG_KEY_REVOCATION
180 struct srk_table srk_tbl[MAX_KEY_ENTRIES];
182 u8 img_sign[KEY_SIZE_BYTES]; /* ESBC client signature */
184 u8 img_encoded_hash[KEY_SIZE_BYTES]; /* EM wrt RSA PKCSv1.5 */
185 /* Includes hash recovered after
186 * signature verification
189 u8 img_encoded_hash_second[KEY_SIZE_BYTES];/* EM' wrt RSA PKCSv1.5 */
191 * ESBC client header plus
195 struct fsl_secboot_sg_table sgtbl[MAX_SG_ENTRIES]; /* SG table */
196 uintptr_t ehdrloc; /* ESBC Header location */
197 uintptr_t img_addr; /* ESBC Image Location */
198 uint32_t img_size; /* ESBC Image Size */
201 int fsl_secboot_validate(uintptr_t haddr, char *arg_hash_str,
203 int fsl_secboot_blob_encap(cmd_tbl_t *cmdtp, int flag, int argc,
204 char * const argv[]);
205 int fsl_secboot_blob_decap(cmd_tbl_t *cmdtp, int flag, int argc,
206 char * const argv[]);
208 int fsl_check_boot_mode_secure(void);
209 int fsl_setenv_chain_of_trust(void);