xref: /openbmc/u-boot/tools/zynqmpimage.h (revision 57a72d0560eb7693a35a891f43587bcd6786dc04)
1*57a72d05STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
2e384cdf8SAlexander Graf /*
3e384cdf8SAlexander Graf  * Copyright (C) 2016 Michal Simek <michals@xilinx.com>
4e384cdf8SAlexander Graf  * Copyright (C) 2015 Nathan Rossi <nathan@nathanrossi.com>
5e384cdf8SAlexander Graf  *
6e384cdf8SAlexander Graf  * The following Boot Header format/structures and values are defined in the
7e384cdf8SAlexander Graf  * following documents:
8e384cdf8SAlexander Graf  *   * ug1085 ZynqMP TRM doc v1.4 (Chapter 11, Table 11-4)
9e384cdf8SAlexander Graf  *   * ug1137 ZynqMP Software Developer Guide v6.0 (Chapter 16)
10e384cdf8SAlexander Graf  */
11e384cdf8SAlexander Graf 
12e384cdf8SAlexander Graf #ifndef _ZYNQMPIMAGE_H_
13e384cdf8SAlexander Graf #define _ZYNQMPIMAGE_H_
14e384cdf8SAlexander Graf 
15e384cdf8SAlexander Graf #include <stdint.h>
16e384cdf8SAlexander Graf 
17e384cdf8SAlexander Graf #define HEADER_INTERRUPT_DEFAULT (cpu_to_le32(0xeafffffe))
18e384cdf8SAlexander Graf #define HEADER_REGINIT_NULL (cpu_to_le32(0xffffffff))
19e384cdf8SAlexander Graf #define HEADER_WIDTHDETECTION (cpu_to_le32(0xaa995566))
20e384cdf8SAlexander Graf #define HEADER_IMAGEIDENTIFIER (cpu_to_le32(0x584c4e58))
216915dcf3SAlexander Graf #define HEADER_CPU_SELECT_MASK		(0x3 << 10)
226915dcf3SAlexander Graf #define HEADER_CPU_SELECT_R5_SINGLE	(0x0 << 10)
236915dcf3SAlexander Graf #define HEADER_CPU_SELECT_A53_32BIT	(0x1 << 10)
24e384cdf8SAlexander Graf #define HEADER_CPU_SELECT_A53_64BIT	(0x2 << 10)
256915dcf3SAlexander Graf #define HEADER_CPU_SELECT_R5_DUAL	(0x3 << 10)
26e384cdf8SAlexander Graf 
27e384cdf8SAlexander Graf enum {
28e384cdf8SAlexander Graf 	ENCRYPTION_EFUSE = 0xa5c3c5a3,
29e384cdf8SAlexander Graf 	ENCRYPTION_OEFUSE = 0xa5c3c5a7,
30e384cdf8SAlexander Graf 	ENCRYPTION_BBRAM = 0x3a5c3c5a,
31e384cdf8SAlexander Graf 	ENCRYPTION_OBBRAM = 0xa35c7ca5,
32e384cdf8SAlexander Graf 	ENCRYPTION_NONE = 0x0,
33e384cdf8SAlexander Graf };
34e384cdf8SAlexander Graf 
35e384cdf8SAlexander Graf struct zynqmp_reginit {
36e384cdf8SAlexander Graf 	uint32_t address;
37e384cdf8SAlexander Graf 	uint32_t data;
38e384cdf8SAlexander Graf };
39e384cdf8SAlexander Graf 
40e384cdf8SAlexander Graf #define HEADER_INTERRUPT_VECTORS	8
41e384cdf8SAlexander Graf #define HEADER_REGINITS			256
42e384cdf8SAlexander Graf 
43e384cdf8SAlexander Graf struct image_header_table {
44e384cdf8SAlexander Graf 	uint32_t version;		  /* 0x00 */
45e384cdf8SAlexander Graf 	uint32_t nr_parts;		  /* 0x04 */
46e384cdf8SAlexander Graf 	uint32_t partition_header_offset; /* 0x08, divided by 4 */
47e384cdf8SAlexander Graf 	uint32_t image_header_offset;	  /* 0x0c, divided by 4 */
48e384cdf8SAlexander Graf 	uint32_t auth_certificate_offset; /* 0x10 */
49e384cdf8SAlexander Graf 	uint32_t boot_device;		  /* 0x14 */
50e384cdf8SAlexander Graf 	uint32_t __reserved1[9];	  /* 0x18 - 0x38 */
51e384cdf8SAlexander Graf 	uint32_t checksum;		  /* 0x3c */
52e384cdf8SAlexander Graf };
53e384cdf8SAlexander Graf 
54e384cdf8SAlexander Graf #define PART_ATTR_VEC_LOCATION		0x800000
55e384cdf8SAlexander Graf #define PART_ATTR_BS_BLOCK_SIZE_MASK	0x700000
56e384cdf8SAlexander Graf #define     PART_ATTR_BS_BLOCK_SIZE_DEFAULT	0x000000
57e384cdf8SAlexander Graf #define     PART_ATTR_BS_BLOCK_SIZE_8MB		0x400000
58e384cdf8SAlexander Graf #define PART_ATTR_BIG_ENDIAN		0x040000
59e384cdf8SAlexander Graf #define PART_ATTR_PART_OWNER_MASK	0x030000
60e384cdf8SAlexander Graf #define     PART_ATTR_PART_OWNER_FSBL		0x000000
61e384cdf8SAlexander Graf #define     PART_ATTR_PART_OWNER_UBOOT		0x010000
62e384cdf8SAlexander Graf #define PART_ATTR_RSA_SIG		0x008000
63e384cdf8SAlexander Graf #define PART_ATTR_CHECKSUM_MASK		0x007000
64e384cdf8SAlexander Graf #define    PART_ATTR_CHECKSUM_NONE		0x000000
65e384cdf8SAlexander Graf #define    PART_ATTR_CHECKSUM_MD5		0x001000
66e384cdf8SAlexander Graf #define    PART_ATTR_CHECKSUM_SHA2		0x002000
67e384cdf8SAlexander Graf #define    PART_ATTR_CHECKSUM_SHA3		0x003000
68e384cdf8SAlexander Graf #define PART_ATTR_DEST_CPU_SHIFT	8
69e384cdf8SAlexander Graf #define PART_ATTR_DEST_CPU_MASK		0x000f00
70e384cdf8SAlexander Graf #define    PART_ATTR_DEST_CPU_NONE		0x000000
71e384cdf8SAlexander Graf #define    PART_ATTR_DEST_CPU_A53_0		0x000100
72e384cdf8SAlexander Graf #define    PART_ATTR_DEST_CPU_A53_1		0x000200
73e384cdf8SAlexander Graf #define    PART_ATTR_DEST_CPU_A53_2		0x000300
74e384cdf8SAlexander Graf #define    PART_ATTR_DEST_CPU_A53_3		0x000400
75e384cdf8SAlexander Graf #define    PART_ATTR_DEST_CPU_R5_0		0x000500
76e384cdf8SAlexander Graf #define    PART_ATTR_DEST_CPU_R5_1		0x000600
77e384cdf8SAlexander Graf #define    PART_ATTR_DEST_CPU_R5_L		0x000700
78e384cdf8SAlexander Graf #define    PART_ATTR_DEST_CPU_PMU		0x000800
79e384cdf8SAlexander Graf #define PART_ATTR_ENCRYPTED		0x000080
80e384cdf8SAlexander Graf #define PART_ATTR_DEST_DEVICE_SHIFT	4
81e384cdf8SAlexander Graf #define PART_ATTR_DEST_DEVICE_MASK	0x000070
82e384cdf8SAlexander Graf #define    PART_ATTR_DEST_DEVICE_NONE		0x000000
83e384cdf8SAlexander Graf #define    PART_ATTR_DEST_DEVICE_PS		0x000010
84e384cdf8SAlexander Graf #define    PART_ATTR_DEST_DEVICE_PL		0x000020
85e384cdf8SAlexander Graf #define    PART_ATTR_DEST_DEVICE_PMU		0x000030
86e384cdf8SAlexander Graf #define    PART_ATTR_DEST_DEVICE_XIP		0x000040
87e384cdf8SAlexander Graf #define PART_ATTR_A53_EXEC_AARCH32	0x000008
88e384cdf8SAlexander Graf #define PART_ATTR_TARGET_EL_SHIFT	1
89e384cdf8SAlexander Graf #define PART_ATTR_TARGET_EL_MASK	0x000006
90e384cdf8SAlexander Graf #define PART_ATTR_TZ_SECURE		0x000001
91e384cdf8SAlexander Graf 
92e384cdf8SAlexander Graf static const char *dest_cpus[0x10] = {
93e384cdf8SAlexander Graf 	"none", "a5x-0", "a5x-1", "a5x-2", "a5x-3", "r5-0", "r5-1",
94e384cdf8SAlexander Graf 	"r5-lockstep", "pmu", "unknown", "unknown", "unknown", "unknown",
95e384cdf8SAlexander Graf 	"unknown", "unknown", "unknown"
96e384cdf8SAlexander Graf };
97e384cdf8SAlexander Graf 
98e384cdf8SAlexander Graf struct partition_header {
99e384cdf8SAlexander Graf 	uint32_t len_enc;		  /* 0x00, divided by 4 */
100e384cdf8SAlexander Graf 	uint32_t len_unenc;		  /* 0x04, divided by 4 */
101e384cdf8SAlexander Graf 	uint32_t len;			  /* 0x08, divided by 4 */
102e384cdf8SAlexander Graf 	uint32_t next_partition_offset;   /* 0x0c */
103e384cdf8SAlexander Graf 	uint64_t entry_point;		  /* 0x10 */
104e384cdf8SAlexander Graf 	uint64_t load_address;		  /* 0x18 */
105e384cdf8SAlexander Graf 	uint32_t offset;		  /* 0x20, divided by 4 */
106e384cdf8SAlexander Graf 	uint32_t attributes;		  /* 0x24 */
107e384cdf8SAlexander Graf 	uint32_t __reserved1;		  /* 0x28 */
108e384cdf8SAlexander Graf 	uint32_t checksum_offset;	  /* 0x2c, divided by 4 */
109e384cdf8SAlexander Graf 	uint32_t __reserved2;		  /* 0x30 */
110e384cdf8SAlexander Graf 	uint32_t auth_certificate_offset; /* 0x34 */
111e384cdf8SAlexander Graf 	uint32_t __reserved3;		  /* 0x38 */
112e384cdf8SAlexander Graf 	uint32_t checksum;		  /* 0x3c */
113e384cdf8SAlexander Graf };
114e384cdf8SAlexander Graf 
115e384cdf8SAlexander Graf struct zynqmp_header {
116e384cdf8SAlexander Graf 	uint32_t interrupt_vectors[HEADER_INTERRUPT_VECTORS]; /* 0x0 */
117e384cdf8SAlexander Graf 	uint32_t width_detection; /* 0x20 */
118e384cdf8SAlexander Graf 	uint32_t image_identifier; /* 0x24 */
119e384cdf8SAlexander Graf 	uint32_t encryption; /* 0x28 */
120e384cdf8SAlexander Graf 	uint32_t image_load; /* 0x2c */
121e384cdf8SAlexander Graf 	uint32_t image_offset; /* 0x30 */
122e384cdf8SAlexander Graf 	uint32_t pfw_image_length; /* 0x34 */
123e384cdf8SAlexander Graf 	uint32_t total_pfw_image_length; /* 0x38 */
124e384cdf8SAlexander Graf 	uint32_t image_size; /* 0x3c */
125e384cdf8SAlexander Graf 	uint32_t image_stored_size; /* 0x40 */
126e384cdf8SAlexander Graf 	uint32_t image_attributes; /* 0x44 */
127e384cdf8SAlexander Graf 	uint32_t checksum; /* 0x48 */
128e384cdf8SAlexander Graf 	uint32_t __reserved1[19]; /* 0x4c */
129e384cdf8SAlexander Graf 	uint32_t image_header_table_offset; /* 0x98 */
130e384cdf8SAlexander Graf 	uint32_t __reserved2[7]; /* 0x9c */
131e384cdf8SAlexander Graf 	struct zynqmp_reginit register_init[HEADER_REGINITS]; /* 0xb8 */
132e384cdf8SAlexander Graf 	uint32_t __reserved4[66]; /* 0x9c0 */
133e384cdf8SAlexander Graf };
134e384cdf8SAlexander Graf 
1356915dcf3SAlexander Graf void zynqmpimage_default_header(struct zynqmp_header *ptr);
1366915dcf3SAlexander Graf void zynqmpimage_print_header(const void *ptr);
1376915dcf3SAlexander Graf 
138e384cdf8SAlexander Graf #endif /* _ZYNQMPIMAGE_H_ */
139