1 /* SPDX-License-Identifier: GPL-2.0+ */
5 * Peng Fan <peng.fan@nxp.com>
13 #include "imagetool.h"
15 #define __packed __attribute__((packed))
18 #define HASH_MAX_LEN 64
19 #define MAX_NUM_IMGS 6
20 #define MAX_NUM_SRK_RECORDS 4
22 #define IVT_HEADER_TAG_B0 0x87
23 #define IVT_VERSION_B0 0x00
25 #define IMG_FLAG_HASH_SHA256 0x000
26 #define IMG_FLAG_HASH_SHA384 0x100
27 #define IMG_FLAG_HASH_SHA512 0x200
29 #define IMG_FLAG_ENCRYPTED_MASK 0x400
30 #define IMG_FLAG_ENCRYPTED_SHIFT 0x0A
32 #define IMG_FLAG_BOOTFLAGS_MASK 0xFFFF0000
33 #define IMG_FLAG_BOOTFLAGS_SHIFT 0x10
35 #define IMG_ARRAY_ENTRY_SIZE 128
36 #define HEADER_IMG_ARRAY_OFFSET 0x10
38 #define HASH_TYPE_SHA_256 256
39 #define HASH_TYPE_SHA_384 384
40 #define HASH_TYPE_SHA_512 512
42 #define IMAGE_HASH_ALGO_DEFAULT 384
43 #define IMAGE_PADDING_DEFAULT 0x1000
45 #define DCD_ENTRY_ADDR_IN_SCFW 0x240
47 #define CONTAINER_ALIGNMENT 0x400
48 #define CONTAINER_FLAGS_DEFAULT 0x10
49 #define CONTAINER_FUSE_DEFAULT 0x0
51 #define SIGNATURE_BLOCK_HEADER_LENGTH 0x10
53 #define MAX_NUM_OF_CONTAINER 2
55 #define FIRST_CONTAINER_HEADER_LENGTH 0x400
57 #define BOOT_IMG_META_MU_RID_SHIFT 10
58 #define BOOT_IMG_META_PART_ID_SHIFT 20
60 #define IMAGE_A35_DEFAULT_META(PART) (((PART == 0) ? \
61 PARTITION_ID_AP : PART) << \
62 BOOT_IMG_META_PART_ID_SHIFT | \
64 BOOT_IMG_META_MU_RID_SHIFT | \
67 #define IMAGE_A53_DEFAULT_META(PART) (((PART == 0) ? \
68 PARTITION_ID_AP : PART) << \
69 BOOT_IMG_META_PART_ID_SHIFT | \
71 BOOT_IMG_META_MU_RID_SHIFT | \
74 #define IMAGE_A72_DEFAULT_META(PART) (((PART == 0) ? \
75 PARTITION_ID_AP : PART) << \
76 BOOT_IMG_META_PART_ID_SHIFT | \
78 BOOT_IMG_META_MU_RID_SHIFT | \
81 #define IMAGE_M4_0_DEFAULT_META(PART) (((PART == 0) ? \
82 PARTITION_ID_M4 : PART) << \
83 BOOT_IMG_META_PART_ID_SHIFT | \
85 BOOT_IMG_META_MU_RID_SHIFT | \
88 #define IMAGE_M4_1_DEFAULT_META(PART) (((PART == 0) ? \
89 PARTITION_ID_M4 : PART) << \
90 BOOT_IMG_META_PART_ID_SHIFT | \
92 BOOT_IMG_META_MU_RID_SHIFT | \
95 #define CONTAINER_IMAGE_ARRAY_START_OFFSET 0x2000
101 uint16_t srk_table_offset;
102 uint16_t cert_offset;
103 uint16_t blob_offset;
104 uint16_t signature_offset;
106 } __packed sig_blk_hdr_t;
115 uint8_t hash[HASH_MAX_LEN];
116 uint8_t iv[IV_MAX_LEN];
117 } __packed boot_img_t;
125 uint8_t fuse_version;
127 uint16_t sig_blk_offset;
129 boot_img_t img[MAX_NUM_IMGS];
130 sig_blk_hdr_t sig_blk_hdr;
131 uint32_t sigblk_size;
133 } __packed flash_header_v3_t;
136 flash_header_v3_t fhdr[MAX_NUM_OF_CONTAINER];
137 } __packed imx_header_v3_t;
141 unsigned int core_type;
142 unsigned int core_id;
143 unsigned int load_addr;
162 enum imx8image_core_type {
173 enum imx8image_fld_types {
181 typedef enum SOC_TYPE {
189 typedef enum option_type {
213 option_type_t option;
229 #define CORE_ULP_CM33 0x1
230 #define CORE_ULP_CA35 0x2
231 #define CORE_ULP_UPOWER 0x4
232 #define CORE_ULP_SENTINEL 0x6
234 #define SC_R_OTP 357U
235 #define SC_R_DEBUG 354U
236 #define SC_R_ROM_0 236U
238 #define MSG_DEBUG_EN SC_R_DEBUG
239 #define MSG_FUSE SC_R_OTP
240 #define MSG_FIELD SC_R_ROM_0
242 #define IMG_TYPE_CSF 0x01 /* CSF image type */
243 #define IMG_TYPE_SCD 0x02 /* SCD image type */
244 #define IMG_TYPE_EXEC 0x03 /* Executable image type */
245 #define IMG_TYPE_DATA 0x04 /* Data image type */
246 #define IMG_TYPE_DCD_DDR 0x05 /* DCD/DDR image type */
247 #define IMG_TYPE_SECO 0x06 /* SECO image type */
248 #define IMG_TYPE_SENTINEL 0x06 /* SENTINEL image type */
249 #define IMG_TYPE_PROV 0x07 /* Provisioning image type */
250 #define IMG_TYPE_DEK 0x08 /* DEK validation type */
252 #define IMG_TYPE_SHIFT 0
253 #define IMG_TYPE_MASK 0x1f
254 #define IMG_TYPE(x) (((x) & IMG_TYPE_MASK) >> IMG_TYPE_SHIFT)
256 #define BOOT_IMG_FLAGS_CORE_MASK 0xF
257 #define BOOT_IMG_FLAGS_CORE_SHIFT 0x04
258 #define BOOT_IMG_FLAGS_CPU_RID_MASK 0x3FF0
259 #define BOOT_IMG_FLAGS_CPU_RID_SHIFT 4
260 #define BOOT_IMG_FLAGS_MU_RID_MASK 0xFFC000
261 #define BOOT_IMG_FLAGS_MU_RID_SHIFT 14
262 #define BOOT_IMG_FLAGS_PARTITION_ID_MASK 0x1F000000
263 #define BOOT_IMG_FLAGS_PARTITION_ID_SHIFT 24
265 /* Resource id used in scfw */
266 #define SC_R_A35_0 508
269 #define SC_R_MU_0A 213
270 #define SC_R_M4_0_PID0 278
271 #define SC_R_M4_0_MU_1A 297
272 #define SC_R_M4_1_PID0 298
273 #define SC_R_M4_1_MU_1A 317
274 #define PARTITION_ID_M4 0
275 #define PARTITION_ID_AP 1
277 #define IMG_STACK_SIZE 32
279 #define append(p, s, l) do { \
280 memcpy((p), (uint8_t *)(s), (l)); (p) += (l); \