/src/barebox/include/mach/imx/imx-header.h
Line | Count | Source |
1 | | /* SPDX-License-Identifier: GPL-2.0-only */ |
2 | | |
3 | | #ifndef __IMX_HEADER_H__ |
4 | | #define __IMX_HEADER_H__ |
5 | | |
6 | | #include <linux/types.h> |
7 | | |
8 | | #define HEADER_LEN 0x1000 /* length of the blank area + IVT + DCD */ |
9 | | #define CSF_LEN 0x2000 /* length of the CSF (needed for HAB) */ |
10 | | #define FLEXSPI_HEADER_LEN HEADER_LEN |
11 | | |
12 | | #define DEK_BLOB_HEADER 8 /* length of DEK blob header */ |
13 | | #define DEK_BLOB_KEY 32 /* length of DEK blob AES-256 key */ |
14 | | #define DEK_BLOB_MAC 16 /* length of DEK blob MAC */ |
15 | | |
16 | | /* DEK blob length excluding DEK itself */ |
17 | | #define DEK_BLOB_OVERHEAD (DEK_BLOB_HEADER + DEK_BLOB_KEY + DEK_BLOB_MAC) |
18 | | |
19 | | /* |
20 | | * ============================================================================ |
21 | | * i.MX flash header v1 handling. Found on i.MX35 and i.MX51 |
22 | | * ============================================================================ |
23 | | */ |
24 | 475 | #define DCD_BARKER 0xb17219e9 |
25 | | |
26 | | struct imx_flash_header { |
27 | | uint32_t app_code_jump_vector; |
28 | | uint32_t app_code_barker; |
29 | | uint32_t app_code_csf; |
30 | | uint32_t dcd_ptr_ptr; |
31 | | uint32_t super_root_key; |
32 | | uint32_t dcd; |
33 | | uint32_t app_dest; |
34 | | uint32_t dcd_barker; |
35 | | uint32_t dcd_block_len; |
36 | | } __attribute__((packed)); |
37 | | |
38 | | struct imx_boot_data { |
39 | | uint32_t start; |
40 | | uint32_t size; |
41 | | uint32_t plugin; |
42 | | } __attribute__((packed)); |
43 | | |
44 | | struct imx_dcd_rec_v1 { |
45 | | uint32_t type; |
46 | | uint32_t addr; |
47 | | uint32_t val; |
48 | | } __attribute__((packed)); |
49 | | |
50 | 946 | #define TAG_IVT_HEADER 0xd1 |
51 | 498 | #define IVT_VERSION 0x40 |
52 | | #define TAG_DCD_HEADER 0xd2 |
53 | | #define DCD_VERSION 0x40 |
54 | | #define TAG_UNLOCK 0xb2 |
55 | | #define TAG_NOP 0xc0 |
56 | | #define TAG_WRITE 0xcc |
57 | | #define TAG_CHECK 0xcf |
58 | | #define PARAMETER_FLAG_MASK (1 << 3) |
59 | | #define PARAMETER_FLAG_SET (1 << 4) |
60 | | |
61 | | #define PLUGIN_HDMI_IMAGE 0x0002 |
62 | | |
63 | | /* |
64 | | * As per Table 6-22 "eMMC/SD BOOT layout", in Normal Boot layout HDMI |
65 | | * firmware image starts at LBA# 64 and ends at LBA# 271 |
66 | | */ |
67 | | #define PLUGIN_HDMI_SIZE ((271 - 64 + 1) * 512) |
68 | | |
69 | | struct imx_ivt_header { |
70 | | uint8_t tag; |
71 | | uint16_t length; |
72 | | uint8_t version; |
73 | | } __attribute__((packed)); |
74 | | |
75 | | struct imx_flash_header_v2 { |
76 | | struct imx_ivt_header header; |
77 | | |
78 | | uint32_t entry; |
79 | | uint32_t reserved1; |
80 | | uint32_t dcd_ptr; |
81 | | uint32_t boot_data_ptr; |
82 | | uint32_t self; |
83 | | uint32_t csf; |
84 | | uint32_t reserved2; |
85 | | |
86 | | struct imx_boot_data boot_data; |
87 | | struct imx_ivt_header dcd_header; |
88 | | } __attribute__((packed)); |
89 | | |
90 | | static inline bool is_imx_flash_header_v2(const void *blob) |
91 | 473 | { |
92 | 473 | const struct imx_flash_header_v2 *hdr = blob; |
93 | | |
94 | 473 | return hdr->header.tag == TAG_IVT_HEADER && |
95 | 25 | hdr->header.version >= IVT_VERSION; |
96 | 473 | } |
97 | | |
98 | | struct config_data { |
99 | | uint32_t image_load_addr; |
100 | | uint32_t image_ivt_offset; |
101 | | uint32_t image_flexspi_ivt_offset; |
102 | | uint32_t image_flexspi_fcfb_offset; |
103 | | uint32_t image_size; |
104 | | uint32_t max_load_size; |
105 | | uint32_t load_size; |
106 | | uint32_t pbl_code_size; |
107 | | char *outfile; |
108 | | char *srkfile; |
109 | | int header_version; |
110 | | off_t header_gap; |
111 | | uint32_t first_opcode; |
112 | | int cpu_type; |
113 | | int (*check)(const struct config_data *data, uint32_t cmd, |
114 | | uint32_t addr, uint32_t mask); |
115 | | int (*write_mem)(const struct config_data *data, uint32_t addr, |
116 | | uint32_t val, int width, int set_bits, int clear_bits); |
117 | | int (*nop)(const struct config_data *data); |
118 | | int (*get_dcd_length)(void); |
119 | | char *csf; |
120 | | char *flexspi_csf; |
121 | | int sign_image; |
122 | | char *signed_hdmi_firmware_file; |
123 | | int encrypt_image; |
124 | | size_t dek_size; |
125 | | bool hab_qspi_support; |
126 | | bool dcd_usb_image; |
127 | | }; |
128 | | |
129 | | #define MAX_RECORDS_DCD_V2 1024 |
130 | | struct imx_dcd_v2_write_rec { |
131 | | uint32_t addr; |
132 | | uint32_t val; |
133 | | } __attribute__((packed)); |
134 | | |
135 | | struct imx_dcd_v2_write { |
136 | | uint8_t tag; |
137 | | uint16_t length; |
138 | | uint8_t param; |
139 | | struct imx_dcd_v2_write_rec data[MAX_RECORDS_DCD_V2]; |
140 | | } __attribute__((packed)); |
141 | | |
142 | | struct imx_dcd_v2_check { |
143 | | uint8_t tag; |
144 | | uint16_t length; |
145 | | uint8_t param; |
146 | | uint32_t addr; |
147 | | uint32_t mask; |
148 | | uint32_t count; |
149 | | } __attribute__((packed)); |
150 | | |
151 | | enum imx_dcd_v2_check_cond { |
152 | | until_all_bits_clear = 0, /* until ((*address & mask) == 0) { ...} */ |
153 | | until_any_bit_clear = 1, /* until ((*address & mask) != mask) { ...} */ |
154 | | until_all_bits_set = 2, /* until ((*address & mask) == mask) { ...} */ |
155 | | until_any_bit_set = 3, /* until ((*address & mask) != 0) { ...} */ |
156 | | } __attribute__((packed)); |
157 | | |
158 | | /* FlexSPI conifguration block FCFB */ |
159 | | #define FCFB_HEAD_TAG 0x46434642 /* "FCFB" */ |
160 | | #define FCFB_VERSION 0x56010000 /* V<major><minor><bugfix> = V100 */ |
161 | | #define FCFB_SAMLPE_CLK_SRC_INTERNAL 0 |
162 | | #define FCFB_DEVTYPE_SERIAL_NOR 1 |
163 | | #define FCFB_SFLASH_PADS_SINGLE 1 |
164 | | #define FCFB_SFLASH_PADS_DUAL 2 |
165 | | #define FCFB_SFLASH_PADS_QUAD 4 |
166 | | #define FCFB_SFLASH_PADS_OCTAL 8 |
167 | | #define FCFB_SERIAL_CLK_FREQ_30MHZ 1 |
168 | | #define FCFB_SERIAL_CLK_FREQ_50MHZ 2 |
169 | | #define FCFB_SERIAL_CLK_FREQ_60MHZ 3 |
170 | | #define FCFB_SERIAL_CLK_FREQ_75MHZ 4 |
171 | | #define FCFB_SERIAL_CLK_FREQ_80MHZ 5 |
172 | | #define FCFB_SERIAL_CLK_FREQ_100MHZ 6 |
173 | | #define FCFB_SERIAL_CLK_FREQ_133MHZ 7 |
174 | | #define FCFB_SERIAL_CLK_FREQ_166MHZ 8 |
175 | | |
176 | | /* Instruction set for the LUT register. */ |
177 | | #define LUT_STOP 0x00 |
178 | | #define LUT_CMD 0x01 |
179 | | #define LUT_ADDR 0x02 |
180 | | #define LUT_CADDR_SDR 0x03 |
181 | | #define LUT_MODE 0x04 |
182 | | #define LUT_MODE2 0x05 |
183 | | #define LUT_MODE4 0x06 |
184 | | #define LUT_MODE8 0x07 |
185 | | #define LUT_NXP_WRITE 0x08 |
186 | | #define LUT_NXP_READ 0x09 |
187 | | #define LUT_LEARN_SDR 0x0A |
188 | | #define LUT_DATSZ_SDR 0x0B |
189 | | #define LUT_DUMMY 0x0C |
190 | | #define LUT_DUMMY_RWDS_SDR 0x0D |
191 | | #define LUT_JMP_ON_CS 0x1F |
192 | | #define LUT_CMD_DDR 0x21 |
193 | | #define LUT_ADDR_DDR 0x22 |
194 | | #define LUT_CADDR_DDR 0x23 |
195 | | #define LUT_MODE_DDR 0x24 |
196 | | #define LUT_MODE2_DDR 0x25 |
197 | | #define LUT_MODE4_DDR 0x26 |
198 | | #define LUT_MODE8_DDR 0x27 |
199 | | #define LUT_WRITE_DDR 0x28 |
200 | | #define LUT_READ_DDR 0x29 |
201 | | #define LUT_LEARN_DDR 0x2A |
202 | | #define LUT_DATSZ_DDR 0x2B |
203 | | #define LUT_DUMMY_DDR 0x2C |
204 | | #define LUT_DUMMY_RWDS_DDR 0x2D |
205 | | |
206 | | /* |
207 | | * Macro for constructing the LUT entries with the following |
208 | | * register layout: |
209 | | * |
210 | | * ----------------------- |
211 | | * | INSTR | PAD | OPRND | |
212 | | * ----------------------- |
213 | | */ |
214 | | #define PAD_SHIFT 8 |
215 | | #define INSTR_SHIFT 10 |
216 | | #define OPRND_SHIFT 16 |
217 | | |
218 | | /* Macros for constructing the LUT register. */ |
219 | | #define LUT_DEF(ins, pad, opr) \ |
220 | | (((ins) << INSTR_SHIFT) | ((pad) << PAD_SHIFT) | (opr)) |
221 | | |
222 | | struct imx_fcfb_common { |
223 | | uint32_t tag; |
224 | | uint32_t version; |
225 | | uint32_t reserved1; |
226 | | uint8_t read_sample; |
227 | | uint8_t datahold; |
228 | | uint8_t datasetup; |
229 | | uint8_t coladdrwidth; |
230 | | uint8_t devcfgenable; |
231 | | uint8_t reserved2[3]; |
232 | | uint32_t devmodeseq; |
233 | | uint32_t devmodearg; |
234 | | uint8_t cmd_enable; |
235 | | uint8_t reserved3[3]; |
236 | | uint32_t cmd_seq[4]; |
237 | | uint32_t cmd_arg[4]; |
238 | | uint32_t controllermisc; |
239 | | uint8_t dev_type; |
240 | | uint8_t sflash_pad; |
241 | | uint8_t serial_clk; |
242 | | uint8_t lut_custom; |
243 | | uint32_t reserved4[2]; |
244 | | uint32_t sflashA1; |
245 | | uint32_t sflashA2; |
246 | | uint32_t sflashB1; |
247 | | uint32_t sflashB2; |
248 | | uint32_t cspadover; |
249 | | uint32_t sclkpadover; |
250 | | uint32_t datapadover; |
251 | | uint32_t dqspadover; |
252 | | uint32_t timeout_ms; |
253 | | uint32_t commandInt_ns; |
254 | | uint32_t datavalid_ns; |
255 | | uint16_t busyoffset; |
256 | | uint16_t busybitpolarity; |
257 | | struct { |
258 | | struct { |
259 | | uint16_t instr[8]; |
260 | | } seq[16]; |
261 | | } lut; |
262 | | uint16_t lut_custom_seq[24]; |
263 | | uint8_t reserved5[16]; |
264 | | } __attribute__((packed)); |
265 | | |
266 | | struct imx_fcfb_nor { |
267 | | struct imx_fcfb_common memcfg; |
268 | | uint32_t page_sz; |
269 | | uint32_t sector_sz; |
270 | | uint32_t ipcmd_serial_clk; |
271 | | uint8_t reserved[52]; |
272 | | } __attribute__((packed)); |
273 | | |
274 | | #endif |