1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * MediaTek BootROM header definitions
4  *
5  * Copyright (C) 2018 MediaTek Inc.
6  * Author: Weijie Gao <weijie.gao@mediatek.com>
7  */
8 
9 #ifndef _MTK_IMAGE_H
10 #define _MTK_IMAGE_H
11 
12 /* Device header definitions, all fields are little-endian */
13 
14 /* Header for NOR/SD/eMMC */
15 union gen_boot_header {
16 	struct {
17 		char name[12];
18 		uint32_t version;
19 		uint32_t size;
20 	};
21 
22 	uint8_t pad[0x200];
23 };
24 
25 #define EMMC_BOOT_NAME		"EMMC_BOOT"
26 #define SF_BOOT_NAME		"SF_BOOT"
27 #define SDMMC_BOOT_NAME		"SDMMC_BOOT"
28 
29 /* Header for NAND */
30 union nand_boot_header {
31 	struct {
32 		char name[12];
33 		char version[4];
34 		char id[8];
35 		uint16_t ioif;
36 		uint16_t pagesize;
37 		uint16_t addrcycles;
38 		uint16_t oobsize;
39 		uint16_t pages_of_block;
40 		uint16_t numblocks;
41 		uint16_t writesize_shift;
42 		uint16_t erasesize_shift;
43 		uint8_t dummy[60];
44 		uint8_t ecc_parity[28];
45 	};
46 
47 	uint8_t data[0x80];
48 };
49 
50 #define NAND_BOOT_NAME		"BOOTLOADER!"
51 #define NAND_BOOT_VERSION	"V006"
52 #define NAND_BOOT_ID		"NFIINFO"
53 
54 /* BootROM layout header */
55 struct brom_layout_header {
56 	char name[8];
57 	uint32_t version;
58 	uint32_t header_size;
59 	uint32_t total_size;
60 	uint32_t magic;
61 	uint32_t type;
62 	uint32_t header_size_2;
63 	uint32_t total_size_2;
64 	uint32_t unused;
65 };
66 
67 #define BRLYT_NAME		"BRLYT"
68 #define BRLYT_MAGIC		0x42424242
69 
70 enum brlyt_img_type {
71 	BRLYT_TYPE_INVALID = 0,
72 	BRLYT_TYPE_NAND = 0x10002,
73 	BRLYT_TYPE_EMMC = 0x10005,
74 	BRLYT_TYPE_NOR = 0x10007,
75 	BRLYT_TYPE_SDMMC = 0x10008,
76 	BRLYT_TYPE_SNAND = 0x10009
77 };
78 
79 /* Combined device header for NOR/SD/eMMC */
80 struct gen_device_header {
81 	union gen_boot_header boot;
82 
83 	union {
84 		struct brom_layout_header brlyt;
85 		uint8_t brlyt_pad[0x400];
86 	};
87 };
88 
89 /* BootROM header definitions */
90 struct gfh_common_header {
91 	uint8_t magic[3];
92 	uint8_t version;
93 	uint16_t size;
94 	uint16_t type;
95 };
96 
97 #define GFH_HEADER_MAGIC	"MMM"
98 
99 #define GFH_TYPE_FILE_INFO	0
100 #define GFH_TYPE_BL_INFO	1
101 #define GFH_TYPE_BROM_CFG	7
102 #define GFH_TYPE_BL_SEC_KEY	3
103 #define GFH_TYPE_ANTI_CLONE	2
104 #define GFH_TYPE_BROM_SEC_CFG	8
105 
106 struct gfh_file_info {
107 	struct gfh_common_header gfh;
108 	char name[12];
109 	uint32_t unused;
110 	uint16_t file_type;
111 	uint8_t flash_type;
112 	uint8_t sig_type;
113 	uint32_t load_addr;
114 	uint32_t total_size;
115 	uint32_t max_size;
116 	uint32_t hdr_size;
117 	uint32_t sig_size;
118 	uint32_t jump_offset;
119 	uint32_t processed;
120 };
121 
122 #define GFH_FILE_INFO_NAME	"FILE_INFO"
123 
124 #define GFH_FLASH_TYPE_GEN	5
125 #define GFH_FLASH_TYPE_NAND	2
126 
127 #define GFH_SIG_TYPE_NONE	0
128 #define GFH_SIG_TYPE_SHA256	1
129 
130 struct gfh_bl_info {
131 	struct gfh_common_header gfh;
132 	uint32_t attr;
133 };
134 
135 struct gfh_brom_cfg {
136 	struct gfh_common_header gfh;
137 	uint32_t cfg_bits;
138 	uint32_t usbdl_by_auto_detect_timeout_ms;
139 	uint8_t unused[0x45];
140 	uint8_t jump_bl_arm64;
141 	uint8_t unused2[2];
142 	uint32_t usbdl_by_kcol0_timeout_ms;
143 	uint32_t usbdl_by_flag_timeout_ms;
144 	uint32_t pad;
145 };
146 
147 #define GFH_BROM_CFG_USBDL_BY_AUTO_DETECT_TIMEOUT_EN	0x02
148 #define GFH_BROM_CFG_USBDL_AUTO_DETECT_DIS		0x10
149 #define GFH_BROM_CFG_USBDL_BY_KCOL0_TIMEOUT_EN		0x80
150 #define GFH_BROM_CFG_USBDL_BY_FLAG_TIMEOUT_EN		0x100
151 #define GFH_BROM_CFG_JUMP_BL_ARM64_EN			0x1000
152 #define GFH_BROM_CFG_JUMP_BL_ARM64			0x64
153 
154 struct gfh_bl_sec_key {
155 	struct gfh_common_header gfh;
156 	uint8_t pad[0x20c];
157 };
158 
159 struct gfh_anti_clone {
160 	struct gfh_common_header gfh;
161 	uint8_t ac_b2k;
162 	uint8_t ac_b2c;
163 	uint16_t pad;
164 	uint32_t ac_offset;
165 	uint32_t ac_len;
166 };
167 
168 struct gfh_brom_sec_cfg {
169 	struct gfh_common_header gfh;
170 	uint32_t cfg_bits;
171 	char customer_name[0x20];
172 	uint32_t pad;
173 };
174 
175 #define BROM_SEC_CFG_JTAG_EN	1
176 #define BROM_SEC_CFG_UART_EN	2
177 
178 struct gfh_header {
179 	struct gfh_file_info file_info;
180 	struct gfh_bl_info bl_info;
181 	struct gfh_brom_cfg brom_cfg;
182 	struct gfh_bl_sec_key bl_sec_key;
183 	struct gfh_anti_clone anti_clone;
184 	struct gfh_brom_sec_cfg brom_sec_cfg;
185 };
186 
187 /* LK image header */
188 
189 union lk_hdr {
190 	struct {
191 		uint32_t magic;
192 		uint32_t size;
193 		char name[32];
194 		uint32_t loadaddr;
195 		uint32_t mode;
196 	};
197 
198 	uint8_t data[512];
199 };
200 
201 #define LK_PART_MAGIC		0x58881688
202 
203 #endif /* _MTK_IMAGE_H */
204