developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 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 | |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 12 | /* Device header definitions, all fields are little-endian */ |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 13 | |
| 14 | /* Header for NOR/SD/eMMC */ |
| 15 | union gen_boot_header { |
| 16 | struct { |
| 17 | char name[12]; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 18 | uint32_t version; |
| 19 | uint32_t size; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 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]; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 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; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 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]; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 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; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 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; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 93 | uint16_t size; |
| 94 | uint16_t type; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 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]; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 109 | uint32_t unused; |
| 110 | uint16_t file_type; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 111 | uint8_t flash_type; |
| 112 | uint8_t sig_type; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 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; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 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; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 132 | uint32_t attr; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | struct gfh_brom_cfg { |
| 136 | struct gfh_common_header gfh; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 137 | uint32_t cfg_bits; |
| 138 | uint32_t usbdl_by_auto_detect_timeout_ms; |
Fabien Parent | 541f6d3 | 2020-10-16 19:52:37 +0200 | [diff] [blame] | 139 | uint8_t unused[0x45]; |
| 140 | uint8_t jump_bl_arm64; |
| 141 | uint8_t unused2[2]; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 142 | uint32_t usbdl_by_kcol0_timeout_ms; |
| 143 | uint32_t usbdl_by_flag_timeout_ms; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 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 |
Fabien Parent | 541f6d3 | 2020-10-16 19:52:37 +0200 | [diff] [blame] | 151 | #define GFH_BROM_CFG_JUMP_BL_ARM64_EN 0x1000 |
| 152 | #define GFH_BROM_CFG_JUMP_BL_ARM64 0x64 |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 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; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 164 | uint32_t ac_offset; |
| 165 | uint32_t ac_len; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | struct gfh_brom_sec_cfg { |
| 169 | struct gfh_common_header gfh; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 170 | uint32_t cfg_bits; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 171 | char customer_name[0x20]; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 172 | uint32_t pad; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 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 { |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 191 | uint32_t magic; |
| 192 | uint32_t size; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 193 | char name[32]; |
Bin Meng | 3495f98 | 2019-10-27 05:19:41 -0700 | [diff] [blame] | 194 | uint32_t loadaddr; |
| 195 | uint32_t mode; |
developer | e1de5d4 | 2018-11-15 10:07:49 +0800 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | uint8_t data[512]; |
| 199 | }; |
| 200 | |
| 201 | #define LK_PART_MAGIC 0x58881688 |
| 202 | |
| 203 | #endif /* _MTK_IMAGE_H */ |