blob: 0a9eab372b96707fcef9722881b2e535c85379fe [file] [log] [blame]
developere1de5d42018-11-15 10:07:49 +08001/* 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 */
13
14/* Header for NOR/SD/eMMC */
15union gen_boot_header {
16 struct {
17 char name[12];
18 __le32 version;
19 __le32 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 */
30union nand_boot_header {
31 struct {
32 char name[12];
33 char version[4];
34 char id[8];
35 __le16 ioif;
36 __le16 pagesize;
37 __le16 addrcycles;
38 __le16 oobsize;
39 __le16 pages_of_block;
40 __le16 numblocks;
41 __le16 writesize_shift;
42 __le16 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 */
55struct brom_layout_header {
56 char name[8];
57 __le32 version;
58 __le32 header_size;
59 __le32 total_size;
60 __le32 magic;
61 __le32 type;
62 __le32 header_size_2;
63 __le32 total_size_2;
64 __le32 unused;
65};
66
67#define BRLYT_NAME "BRLYT"
68#define BRLYT_MAGIC 0x42424242
69
70enum 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 */
80struct 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 */
90struct gfh_common_header {
91 uint8_t magic[3];
92 uint8_t version;
93 __le16 size;
94 __le16 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
106struct gfh_file_info {
107 struct gfh_common_header gfh;
108 char name[12];
109 __le32 unused;
110 __le16 file_type;
111 uint8_t flash_type;
112 uint8_t sig_type;
113 __le32 load_addr;
114 __le32 total_size;
115 __le32 max_size;
116 __le32 hdr_size;
117 __le32 sig_size;
118 __le32 jump_offset;
119 __le32 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
130struct gfh_bl_info {
131 struct gfh_common_header gfh;
132 __le32 attr;
133};
134
135struct gfh_brom_cfg {
136 struct gfh_common_header gfh;
137 __le32 cfg_bits;
138 __le32 usbdl_by_auto_detect_timeout_ms;
139 uint8_t unused[0x48];
140 __le32 usbdl_by_kcol0_timeout_ms;
141 __le32 usbdl_by_flag_timeout_ms;
142 uint32_t pad;
143};
144
145#define GFH_BROM_CFG_USBDL_BY_AUTO_DETECT_TIMEOUT_EN 0x02
146#define GFH_BROM_CFG_USBDL_AUTO_DETECT_DIS 0x10
147#define GFH_BROM_CFG_USBDL_BY_KCOL0_TIMEOUT_EN 0x80
148#define GFH_BROM_CFG_USBDL_BY_FLAG_TIMEOUT_EN 0x100
149
150struct gfh_bl_sec_key {
151 struct gfh_common_header gfh;
152 uint8_t pad[0x20c];
153};
154
155struct gfh_anti_clone {
156 struct gfh_common_header gfh;
157 uint8_t ac_b2k;
158 uint8_t ac_b2c;
159 uint16_t pad;
160 __le32 ac_offset;
161 __le32 ac_len;
162};
163
164struct gfh_brom_sec_cfg {
165 struct gfh_common_header gfh;
166 __le32 cfg_bits;
167 char customer_name[0x20];
168 __le32 pad;
169};
170
171#define BROM_SEC_CFG_JTAG_EN 1
172#define BROM_SEC_CFG_UART_EN 2
173
174struct gfh_header {
175 struct gfh_file_info file_info;
176 struct gfh_bl_info bl_info;
177 struct gfh_brom_cfg brom_cfg;
178 struct gfh_bl_sec_key bl_sec_key;
179 struct gfh_anti_clone anti_clone;
180 struct gfh_brom_sec_cfg brom_sec_cfg;
181};
182
183/* LK image header */
184
185union lk_hdr {
186 struct {
187 __le32 magic;
188 __le32 size;
189 char name[32];
190 __le32 loadaddr;
191 __le32 mode;
192 };
193
194 uint8_t data[512];
195};
196
197#define LK_PART_MAGIC 0x58881688
198
199#endif /* _MTK_IMAGE_H */