1 /* SPDX-License-Identifier: GPL-2.0+ */
5 * Peng Fan <peng.fan@nxp.com>
13 #include "imagetool.h"
14 #include "linux/kernel.h"
16 #define __packed __attribute__((packed))
19 #define HASH_MAX_LEN 64
20 #define MAX_NUM_IMGS 6
21 #define MAX_NUM_SRK_RECORDS 4
23 #define IVT_HEADER_TAG_B0 0x87
24 #define IVT_VERSION_B0 0x00
26 #define IMG_FLAG_HASH_SHA256 0x000
27 #define IMG_FLAG_HASH_SHA384 0x100
28 #define IMG_FLAG_HASH_SHA512 0x200
30 #define IMG_FLAG_ENCRYPTED_MASK 0x400
31 #define IMG_FLAG_ENCRYPTED_SHIFT 0x0A
33 #define IMG_FLAG_BOOTFLAGS_MASK 0xFFFF0000
34 #define IMG_FLAG_BOOTFLAGS_SHIFT 0x10
36 #define IMG_ARRAY_ENTRY_SIZE 128
37 #define HEADER_IMG_ARRAY_OFFSET 0x10
39 #define HASH_TYPE_SHA_256 256
40 #define HASH_TYPE_SHA_384 384
41 #define HASH_TYPE_SHA_512 512
43 #define IMAGE_HASH_ALGO_DEFAULT 384
44 #define IMAGE_PADDING_DEFAULT 0x1000
46 #define DCD_ENTRY_ADDR_IN_SCFW 0x240
48 #define CONTAINER_ALIGNMENT 0x400
49 #define CONTAINER_FLAGS_DEFAULT 0x10
50 #define CONTAINER_FUSE_DEFAULT 0x0
52 #define SIGNATURE_BLOCK_HEADER_LENGTH 0x10
54 #define MAX_NUM_OF_CONTAINER 2
56 #define FIRST_CONTAINER_HEADER_LENGTH 0x400
58 #define BOOT_IMG_META_MU_RID_SHIFT 10
59 #define BOOT_IMG_META_PART_ID_SHIFT 20
61 #define IMAGE_A35_DEFAULT_META(PART) (((PART == 0) ? \
62 PARTITION_ID_AP : PART) << \
63 BOOT_IMG_META_PART_ID_SHIFT | \
65 BOOT_IMG_META_MU_RID_SHIFT | \
68 #define IMAGE_A53_DEFAULT_META(PART) (((PART == 0) ? \
69 PARTITION_ID_AP : PART) << \
70 BOOT_IMG_META_PART_ID_SHIFT | \
72 BOOT_IMG_META_MU_RID_SHIFT | \
75 #define IMAGE_A72_DEFAULT_META(PART) (((PART == 0) ? \
76 PARTITION_ID_AP : PART) << \
77 BOOT_IMG_META_PART_ID_SHIFT | \
79 BOOT_IMG_META_MU_RID_SHIFT | \
82 #define IMAGE_M4_0_DEFAULT_META(PART) (((PART == 0) ? \
83 PARTITION_ID_M4 : PART) << \
84 BOOT_IMG_META_PART_ID_SHIFT | \
86 BOOT_IMG_META_MU_RID_SHIFT | \
89 #define IMAGE_M4_1_DEFAULT_META(PART) (((PART == 0) ? \
90 PARTITION_ID_M4 : PART) << \
91 BOOT_IMG_META_PART_ID_SHIFT | \
93 BOOT_IMG_META_MU_RID_SHIFT | \
96 #define CONTAINER_IMAGE_ARRAY_START_OFFSET 0x2000
102 uint16_t srk_table_offset;
103 uint16_t cert_offset;
104 uint16_t blob_offset;
105 uint16_t signature_offset;
107 } __packed sig_blk_hdr_t;
116 uint8_t hash[HASH_MAX_LEN];
117 uint8_t iv[IV_MAX_LEN];
118 } __packed boot_img_t;
126 uint8_t fuse_version;
128 uint16_t sig_blk_offset;
130 boot_img_t img[MAX_NUM_IMGS];
131 sig_blk_hdr_t sig_blk_hdr;
132 uint32_t sigblk_size;
134 } __packed flash_header_v3_t;
137 flash_header_v3_t fhdr[MAX_NUM_OF_CONTAINER];
138 } __packed imx_header_v3_t;
142 unsigned int core_type;
143 unsigned int core_id;
144 unsigned int load_addr;
163 enum imx8image_core_type {
173 enum imx8image_fld_types {
181 typedef enum SOC_TYPE {
187 typedef enum option_type {
209 option_type_t option;
225 #define SC_R_OTP 357U
226 #define SC_R_DEBUG 354U
227 #define SC_R_ROM_0 236U
229 #define MSG_DEBUG_EN SC_R_DEBUG
230 #define MSG_FUSE SC_R_OTP
231 #define MSG_FIELD SC_R_ROM_0
233 #define IMG_TYPE_CSF 0x01 /* CSF image type */
234 #define IMG_TYPE_SCD 0x02 /* SCD image type */
235 #define IMG_TYPE_EXEC 0x03 /* Executable image type */
236 #define IMG_TYPE_DATA 0x04 /* Data image type */
237 #define IMG_TYPE_DCD_DDR 0x05 /* DCD/DDR image type */
238 #define IMG_TYPE_SECO 0x06 /* SECO image type */
239 #define IMG_TYPE_PROV 0x07 /* Provisioning image type */
240 #define IMG_TYPE_DEK 0x08 /* DEK validation type */
242 #define IMG_TYPE_SHIFT 0
243 #define IMG_TYPE_MASK 0x1f
244 #define IMG_TYPE(x) (((x) & IMG_TYPE_MASK) >> IMG_TYPE_SHIFT)
246 #define BOOT_IMG_FLAGS_CORE_MASK 0xF
247 #define BOOT_IMG_FLAGS_CORE_SHIFT 0x04
248 #define BOOT_IMG_FLAGS_CPU_RID_MASK 0x3FF0
249 #define BOOT_IMG_FLAGS_CPU_RID_SHIFT 4
250 #define BOOT_IMG_FLAGS_MU_RID_MASK 0xFFC000
251 #define BOOT_IMG_FLAGS_MU_RID_SHIFT 14
252 #define BOOT_IMG_FLAGS_PARTITION_ID_MASK 0x1F000000
253 #define BOOT_IMG_FLAGS_PARTITION_ID_SHIFT 24
255 /* Resource id used in scfw */
256 #define SC_R_A35_0 508
259 #define SC_R_MU_0A 213
260 #define SC_R_M4_0_PID0 278
261 #define SC_R_M4_0_MU_1A 297
262 #define SC_R_M4_1_PID0 298
263 #define SC_R_M4_1_MU_1A 317
264 #define PARTITION_ID_M4 0
265 #define PARTITION_ID_AP 1
267 #define IMG_STACK_SIZE 32
269 #define append(p, s, l) do { \
270 memcpy((p), (uint8_t *)(s), (l)); (p) += (l); \