csf_hdr.h 3.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * Copyright 2017-2020 NXP
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */

#ifndef CSF_HDR_H
#define CSF_HDR_H

#include "caam.h"
#include "hash.h"
#include "rsa.h"

/* Barker code size in bytes */
#define CSF_BARKER_LEN	4	/* barker code length in ESBC uboot client */
				/* header */

#ifdef CSF_HDR_CH3
struct csf_hdr {
	uint8_t barker[CSF_BARKER_LEN];	/* 0x00 Barker code */
	uint32_t srk_tbl_off;		/* 0x04 SRK Table Offset */

	struct {
		uint8_t num_srk;	/* 0x08 No. of keys */
		uint8_t srk_sel;	/*  Key no. to be used */
		uint8_t reserve;	/* 0x0a rseerved */
	} len_kr;
	uint8_t ie_flag;

	uint32_t uid_flag;

	uint32_t psign;			/* 0x10 signature offset */
	uint32_t sign_len;			/* 0x14 length of signature */

	union {
		struct {
			uint32_t sg_table_offset; /* 0x18 SG Table Offset */
			uint32_t sg_entries;	  /* 0x1c no of entries in SG */
		} sg_isbc;
		uint64_t img_addr;	/* 64 bit pointer to ESBC Image */
	};

	union {
		struct {
			uint32_t img_size;   /* ESBC client img size in bytes */
			uint32_t ie_key_sel;
		} img;
		uint64_t entry_point;	  /* 0x20-0x24 ESBC entry point */
	};

	uint32_t fsl_uid_0;			/* 0x28 Freescale unique id 0 */
	uint32_t fsl_uid_1;			/* 0x2c Freescale unique id 1 */
	uint32_t oem_uid_0;			/* 0x30 OEM unique id 0 */
	uint32_t oem_uid_1;			/* 0x34 OEM unique id 1 */
	uint32_t oem_uid_2;			/* 0x38 OEM unique id 2 */
	uint32_t oem_uid_3;			/* 0x3c OEM unique id 3 */
	uint32_t oem_uid_4;			/* 0x40 OEM unique id 4 */

	uint32_t reserved[3];		/* 0x44 - 0x4f */
};

/* Srk table and key revocation check */
#define UNREVOCABLE_KEY	8
#define REVOC_KEY_ALIGN 7
#define MAX_KEY_ENTRIES 8

#else

/* CSF header for Chassis 2 */
struct csf_hdr {
	uint8_t barker[CSF_BARKER_LEN];	/* barker code */
	union {
		uint32_t pkey;		/* public key offset */
		uint32_t srk_tbl_off;
	};

	union {
		uint32_t key_len;		/* pub key length in bytes */
		struct {
			uint32_t srk_table_flag:8;
			uint32_t srk_sel:8;
			uint32_t num_srk:16;
		} len_kr;
	};

	uint32_t psign;		/* signature offset */
	uint32_t sign_len;		/* length of the signature in bytes */

	/* SG Table used by ISBC header */
	union {
		struct {
			uint32_t sg_table_offset; /* 0x14 SG Table Offset */
			uint32_t sg_entries;	/* no of entries in SG table */
		} sg_isbc;
		struct {
			uint32_t reserved1;	/* Reserved field */
			uint32_t img_size;	/* ESBC img size in bytes */
		} img;
	};

	uint32_t entry_point;		/* ESBC client entry point */
	uint32_t reserved2;		/* Scatter gather flag */
	uint32_t uid_flag;
	uint32_t fsl_uid_0;
	uint32_t oem_uid_0;
	uint32_t reserved3[2];
	uint32_t fsl_uid_1;
	uint32_t oem_uid_1;

	/* The entries below aren't present in ISBC header */
	uint64_t img_addr;	/* 64 bit pointer to ESBC Image */
	uint32_t ie_flag;
	uint32_t ie_key_sel;
};

/* Srk table and key revocation check */
#define UNREVOCABLE_KEY	4
#define REVOC_KEY_ALIGN 3
#define MAX_KEY_ENTRIES 4

#endif

struct srk_table {
	uint32_t key_len;
	uint8_t pkey[2 * RSA_4K_KEY_SZ_BYTES];
};

/*
 * This struct contains the following fields
 * length of the segment
 * Destination Target ID
 * source address
 * destination address
 */
struct sg_table {
	uint32_t len;			/* Length of Image */
	uint32_t res1;
	union {
		uint64_t src_addr;	/* SRC Address of Image */
		struct {
			uint32_t src_addr;
			uint32_t dst_addr;
		} img;
	};
};

int validate_esbc_header(void *img_hdr, void **img_key, uint32_t *key_len,
			 void **img_sign, uint32_t *sign_len,
			 enum sig_alg *algo);

int calc_img_hash(struct csf_hdr *hdr, void *img_addr, uint32_t img_size,
		  uint8_t *img_hash, uint32_t *hash_len);

#endif