Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 2 | /* |
| 3 | * This is from the Android Project, |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 4 | * Repository: https://android.googlesource.com/platform/system/tools/mkbootimg |
| 5 | * File: include/bootimg/bootimg.h |
| 6 | * Commit: e55998a0f2b61b685d5eb4a486ca3a0c680b1a2f |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 7 | * |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 8 | * Copyright (C) 2007 The Android Open Source Project |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #ifndef _ANDROID_IMAGE_H_ |
| 12 | #define _ANDROID_IMAGE_H_ |
| 13 | |
Sam Protsenko | 35e9983 | 2019-08-09 15:31:29 +0300 | [diff] [blame] | 14 | #include <linux/compiler.h> |
| 15 | #include <linux/types.h> |
| 16 | |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 17 | #define ANDR_BOOT_MAGIC "ANDROID!" |
| 18 | #define ANDR_BOOT_MAGIC_SIZE 8 |
| 19 | #define ANDR_BOOT_NAME_SIZE 16 |
| 20 | #define ANDR_BOOT_ARGS_SIZE 512 |
Alex Deymo | 210a717 | 2017-04-02 01:49:47 -0700 | [diff] [blame] | 21 | #define ANDR_BOOT_EXTRA_ARGS_SIZE 1024 |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 22 | |
Bo Lv | 4a46502 | 2023-02-28 05:51:47 +0000 | [diff] [blame] | 23 | #ifndef CONFIG_AMLOGIC_MODIFY |
| 24 | |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 25 | /* The bootloader expects the structure of andr_img_hdr with header |
| 26 | * version 0 to be as follows: */ |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 27 | struct andr_img_hdr { |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 28 | /* Must be ANDR_BOOT_MAGIC. */ |
| 29 | char magic[ANDR_BOOT_MAGIC_SIZE]; |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 30 | |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 31 | u32 kernel_size; /* size in bytes */ |
| 32 | u32 kernel_addr; /* physical load addr */ |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 33 | |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 34 | u32 ramdisk_size; /* size in bytes */ |
| 35 | u32 ramdisk_addr; /* physical load addr */ |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 36 | |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 37 | u32 second_size; /* size in bytes */ |
| 38 | u32 second_addr; /* physical load addr */ |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 39 | |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 40 | u32 tags_addr; /* physical addr for kernel tags */ |
| 41 | u32 page_size; /* flash page size we assume */ |
Alex Deymo | 210a717 | 2017-04-02 01:49:47 -0700 | [diff] [blame] | 42 | |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 43 | /* Version of the boot image header. */ |
| 44 | u32 header_version; |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 45 | |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 46 | /* Operating system version and security patch level. |
| 47 | * For version "A.B.C" and patch level "Y-M-D": |
| 48 | * (7 bits for each of A, B, C; 7 bits for (Y-2000), 4 bits for M) |
| 49 | * os_version = A[31:25] B[24:18] C[17:11] (Y-2000)[10:4] M[3:0] */ |
| 50 | u32 os_version; |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 51 | |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 52 | char name[ANDR_BOOT_NAME_SIZE]; /* asciiz product name */ |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 53 | |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 54 | char cmdline[ANDR_BOOT_ARGS_SIZE]; |
Alex Deymo | 210a717 | 2017-04-02 01:49:47 -0700 | [diff] [blame] | 55 | |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 56 | u32 id[8]; /* timestamp / checksum / sha1 / etc */ |
| 57 | |
| 58 | /* Supplemental command line data; kept here to maintain |
| 59 | * binary compatibility with older versions of mkbootimg. */ |
| 60 | char extra_cmdline[ANDR_BOOT_EXTRA_ARGS_SIZE]; |
| 61 | |
| 62 | /* Fields in boot_img_hdr_v1 and newer. */ |
| 63 | u32 recovery_dtbo_size; /* size in bytes for recovery DTBO/ACPIO image */ |
| 64 | u64 recovery_dtbo_offset; /* offset to recovery dtbo/acpio in boot image */ |
| 65 | u32 header_size; |
| 66 | |
| 67 | /* Fields in boot_img_hdr_v2 and newer. */ |
| 68 | u32 dtb_size; /* size in bytes for DTB image */ |
| 69 | u64 dtb_addr; /* physical load address for DTB image */ |
Alex Deymo | 210a717 | 2017-04-02 01:49:47 -0700 | [diff] [blame] | 70 | } __attribute__((packed)); |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 71 | |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 72 | /* When a boot header is of version 0, the structure of boot image is as |
| 73 | * follows: |
| 74 | * |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 75 | * +-----------------+ |
| 76 | * | boot header | 1 page |
| 77 | * +-----------------+ |
| 78 | * | kernel | n pages |
| 79 | * +-----------------+ |
| 80 | * | ramdisk | m pages |
| 81 | * +-----------------+ |
| 82 | * | second stage | o pages |
| 83 | * +-----------------+ |
| 84 | * |
| 85 | * n = (kernel_size + page_size - 1) / page_size |
| 86 | * m = (ramdisk_size + page_size - 1) / page_size |
| 87 | * o = (second_size + page_size - 1) / page_size |
| 88 | * |
| 89 | * 0. all entities are page_size aligned in flash |
| 90 | * 1. kernel and ramdisk are required (size != 0) |
| 91 | * 2. second is optional (second_size == 0 -> no second) |
| 92 | * 3. load each element (kernel, ramdisk, second) at |
| 93 | * the specified physical address (kernel_addr, etc) |
| 94 | * 4. prepare tags at tag_addr. kernel_args[] is |
| 95 | * appended to the kernel commandline in the tags. |
| 96 | * 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr |
| 97 | * 6. if second_size != 0: jump to second_addr |
| 98 | * else: jump to kernel_addr |
| 99 | */ |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 100 | |
| 101 | /* When the boot image header has a version of 2, the structure of the boot |
| 102 | * image is as follows: |
| 103 | * |
| 104 | * +---------------------+ |
| 105 | * | boot header | 1 page |
| 106 | * +---------------------+ |
| 107 | * | kernel | n pages |
| 108 | * +---------------------+ |
| 109 | * | ramdisk | m pages |
| 110 | * +---------------------+ |
| 111 | * | second stage | o pages |
| 112 | * +---------------------+ |
| 113 | * | recovery dtbo/acpio | p pages |
| 114 | * +---------------------+ |
| 115 | * | dtb | q pages |
| 116 | * +---------------------+ |
Sam Protsenko | 35e9983 | 2019-08-09 15:31:29 +0300 | [diff] [blame] | 117 | * |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 118 | * n = (kernel_size + page_size - 1) / page_size |
| 119 | * m = (ramdisk_size + page_size - 1) / page_size |
| 120 | * o = (second_size + page_size - 1) / page_size |
| 121 | * p = (recovery_dtbo_size + page_size - 1) / page_size |
| 122 | * q = (dtb_size + page_size - 1) / page_size |
| 123 | * |
| 124 | * 0. all entities are page_size aligned in flash |
| 125 | * 1. kernel, ramdisk and DTB are required (size != 0) |
| 126 | * 2. recovery_dtbo/recovery_acpio is required for recovery.img in non-A/B |
| 127 | * devices(recovery_dtbo_size != 0) |
| 128 | * 3. second is optional (second_size == 0 -> no second) |
| 129 | * 4. load each element (kernel, ramdisk, second, dtb) at |
| 130 | * the specified physical address (kernel_addr, etc) |
| 131 | * 5. If booting to recovery mode in a non-A/B device, extract recovery |
| 132 | * dtbo/acpio and apply the correct set of overlays on the base device tree |
| 133 | * depending on the hardware/product revision. |
| 134 | * 6. prepare tags at tag_addr. kernel_args[] is |
| 135 | * appended to the kernel commandline in the tags. |
| 136 | * 7. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr |
| 137 | * 8. if second_size != 0: jump to second_addr |
| 138 | * else: jump to kernel_addr |
| 139 | */ |
Bo Lv | 4a46502 | 2023-02-28 05:51:47 +0000 | [diff] [blame] | 140 | #else |
| 141 | |
| 142 | #define _BA1_(cond, line) \ |
| 143 | extern int __build_assertion_ ## line[1 - 2*!(cond)] \ |
| 144 | __attribute__ ((unused)) |
| 145 | #define _BA0_(c, x) _BA1_(c, x) |
| 146 | #define BUILD_ASSERT(cond) _BA0_(cond, __LINE__) |
| 147 | |
Bo Lv | 65d8679 | 2024-08-30 11:02:03 +0800 | [diff] [blame] | 148 | #define KERNEL_HIGH_DEC_ADDR 0x10000000 |
| 149 | #define KERNEL_DECOMPRESS_MAX_SIZE 0x1800000 |
Bo Lv | da8d5b7 | 2023-07-31 14:58:21 +0800 | [diff] [blame] | 150 | #define IOTRACE_LOAD_ADDR 0x4F00000 |
| 151 | #define KERNEL_LOAD_HIGH_ADDR 0xD000000 |
| 152 | #define KERNEL_DEFAULT_LOAD_ADDR 0x3000000 |
| 153 | #define DTB_LOAD_ADDR 0x1000000 |
| 154 | #define LOAD_ADDR_ALIGN_LENGTH 0x100000 |
| 155 | |
Bo Lv | 4a46502 | 2023-02-28 05:51:47 +0000 | [diff] [blame] | 156 | #define BOOT_IMG_HDR_SIZE (0x800) |
| 157 | #define BOOT_IMG_V3_HDR_SIZE (0x1000) |
| 158 | #define VENDOR_BOOT_IMG_HDR_SIZE (0x1000) |
| 159 | |
| 160 | #define BOOT_MAGIC "ANDROID!" |
| 161 | #define BOOT_MAGIC_SIZE (8) |
| 162 | #define BOOT_NAME_SIZE (16) |
| 163 | #define BOOT_ARGS_SIZE (512) |
| 164 | #define BOOT_EXTRA_ARGS_SIZE (1024) |
| 165 | |
| 166 | #define VENDOR_BOOT_MAGIC "VNDRBOOT" |
| 167 | #define VENDOR_BOOT_MAGIC_SIZE (8) |
| 168 | #define VENDOR_BOOT_ARGS_SIZE (2048) |
| 169 | #define VENDOR_BOOT_NAME_SIZE (16) |
| 170 | |
| 171 | #define VENDOR_RAMDISK_TYPE_NONE 0 |
| 172 | #define VENDOR_RAMDISK_TYPE_PLATFORM 1 |
| 173 | #define VENDOR_RAMDISK_TYPE_RECOVERY 2 |
| 174 | #define VENDOR_RAMDISK_TYPE_DLKM 3 |
| 175 | #define VENDOR_RAMDISK_NAME_SIZE 32 |
| 176 | #define VENDOR_RAMDISK_TABLE_ENTRY_BOARD_ID_SIZE 16 |
| 177 | |
| 178 | /* Before android R boot.img header structure */ |
| 179 | struct andr_img_hdr { |
| 180 | char magic[BOOT_MAGIC_SIZE]; /*"ANDROID!"*/ |
| 181 | |
| 182 | u32 kernel_size; /* size in bytes */ |
| 183 | u32 kernel_addr; /* physical load addr */ |
| 184 | |
| 185 | u32 ramdisk_size; /* size in bytes */ |
| 186 | u32 ramdisk_addr; /* physical load addr */ |
| 187 | |
| 188 | u32 second_size; /* size in bytes */ |
| 189 | u32 second_addr; /* physical load addr */ |
| 190 | |
| 191 | u32 tags_addr; /* physical addr for kernel tags */ |
| 192 | u32 page_size; /* flash page size we assume */ |
| 193 | |
| 194 | u32 header_version; /* highest byte: 1 = boot, 2 = recovery; |
| 195 | low three bytes: kernel version */ |
| 196 | |
| 197 | /* operating system version and security patch level; for |
| 198 | * version "A.B.C" and patch level "Y-M-D": |
| 199 | * ver = A << 14 | B << 7 | C (7 bits for each of A, B, C) |
| 200 | * lvl = ((Y - 2000) & 127) << 4 | M (7 bits for Y, 4 bits for M) |
| 201 | * os_version = ver << 11 | lvl */ |
| 202 | uint32_t os_version; |
| 203 | |
| 204 | char name[BOOT_NAME_SIZE]; /* asciiz product name */ |
| 205 | |
| 206 | char cmdline[BOOT_ARGS_SIZE]; |
| 207 | |
| 208 | u32 id[8]; /* timestamp / checksum / sha1 / etc */ |
| 209 | |
| 210 | /* Supplemental command line data; kept here to maintain |
| 211 | binary compatibility with older versions of mkbootimg. |
| 212 | */ |
| 213 | uint8_t extra_cmdline[BOOT_EXTRA_ARGS_SIZE]; |
| 214 | unsigned char szReserved[BOOT_IMG_HDR_SIZE - 1632]; /*align to 2KB header,1632 is size before this*/ |
| 215 | }; |
| 216 | |
| 217 | typedef struct andr_img_hdr boot_img_hdr_t; |
| 218 | typedef struct andr_img_hdr *p_boot_img_hdr_t; |
| 219 | |
| 220 | /*compile check*/ |
| 221 | BUILD_ASSERT(sizeof(boot_img_hdr_t) == BOOT_IMG_HDR_SIZE); |
| 222 | |
| 223 | #if 0 |
| 224 | typedef struct { |
| 225 | boot_img_hdr_t hdr; |
| 226 | unsigned char szData[1]; |
| 227 | }boot_img_t, * p_boot_img_t; |
| 228 | #endif |
| 229 | |
| 230 | /* When the boot image header has a version of 3, the structure of the boot |
| 231 | * image is as follows: |
| 232 | * |
| 233 | * +-----------------+ |
| 234 | * | boot header | 1 page |
| 235 | * +-----------------+ |
| 236 | * | kernel | n pages |
| 237 | * +-----------------+ |
| 238 | * | ramdisk | m pages |
| 239 | * +-----------------+ |
| 240 | * | second stage | o pages |
| 241 | * +-----------------+ |
| 242 | * |
| 243 | * n = (kernel_size + page_size - 1) / page_size |
| 244 | * m = (ramdisk_size + page_size - 1) / page_size |
| 245 | * o = (second_size + page_size - 1) / page_size |
| 246 | * |
| 247 | * 0. all entities are page_size aligned in flash |
| 248 | * 1. kernel and ramdisk are required (size != 0) |
| 249 | * 2. second is optional (second_size == 0 -> no second) |
| 250 | * 3. load each element (kernel, ramdisk, second) at |
| 251 | * the specified physical address (kernel_addr, etc) |
| 252 | * 4. prepare tags at tag_addr. kernel_args[] is |
| 253 | * appended to the kernel commandline in the tags. |
| 254 | * 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr |
| 255 | * 6. if second_size != 0: jump to second_addr |
| 256 | * else: jump to kernel_addr |
| 257 | */ |
| 258 | |
| 259 | |
| 260 | #define ANDROID_R_IMG_VER (3) |
| 261 | #define ANDROID_S_IMG_VER (4) |
| 262 | |
| 263 | /* Android R boot.img and vendor_boot.img structure */ |
| 264 | struct boot_img_hdr_v3 { |
| 265 | char magic[ANDR_BOOT_MAGIC_SIZE]; /*"ANDROID!"*/ |
| 266 | |
| 267 | u32 kernel_size; /* size in bytes */ |
| 268 | u32 ramdisk_size; /* size in bytes */ |
| 269 | |
| 270 | /* Operating system version and security patch level. |
| 271 | For version "A.B.C" and patch level "Y-M-D": |
| 272 | (7 bits for each of A, B, C; 7 bits for (Y-2000), 4 bits for M) |
| 273 | os_version = A[31:25] B[24:18] C[17:11] (Y-2000)[10:4] M[3:0] |
| 274 | */ |
| 275 | |
| 276 | uint32_t os_version; |
| 277 | uint32_t header_size; |
| 278 | uint32_t reserved[4]; |
| 279 | |
| 280 | uint32_t header_version; /* Version of the boot image header */ |
| 281 | char cmdline[BOOT_ARGS_SIZE + BOOT_EXTRA_ARGS_SIZE]; |
| 282 | unsigned char szReserved[BOOT_IMG_V3_HDR_SIZE - 1580]; /*align to 4KB header,1580 is size before this*/ |
| 283 | }; |
| 284 | |
| 285 | typedef struct boot_img_hdr_v3 boot_img_hdr_v3_t; |
| 286 | typedef struct boot_img_hdr_v3 *p_boot_img_hdr_v3_t; |
| 287 | |
| 288 | |
| 289 | /*compile check*/ |
| 290 | BUILD_ASSERT(sizeof(boot_img_hdr_v3_t) == BOOT_IMG_V3_HDR_SIZE); |
| 291 | |
| 292 | struct boot_img_v3 { |
| 293 | boot_img_hdr_v3_t hdr; |
| 294 | unsigned char szData[1]; |
| 295 | }; |
| 296 | |
| 297 | typedef struct boot_img_v3 boot_img_v3_t; |
| 298 | typedef struct boot_img_v3 *p_boot_img_v3_t; |
| 299 | |
| 300 | |
| 301 | /* When the boot image header has a version of 3, the structure of the boot |
| 302 | * image is as follows: |
| 303 | * |
| 304 | * +---------------------+ |
| 305 | * | boot header | 4096 bytes |
| 306 | * +---------------------+ |
| 307 | * | kernel | m pages |
| 308 | * +---------------------+ |
| 309 | * | ramdisk | n pages |
| 310 | * +---------------------+ |
| 311 | * |
| 312 | * m = (kernel_size + 4096 - 1) / 4096 |
| 313 | * n = (ramdisk_size + 4096 - 1) / 4096 |
| 314 | * |
| 315 | * Note that in version 3 of the boot image header, page size is fixed at 4096 bytes. |
| 316 | * |
| 317 | * The structure of the vendor boot image (introduced with version 3 and |
| 318 | * required to be present when a v3 boot image is used) is as follows: |
| 319 | * |
| 320 | * +---------------------+ |
| 321 | * | vendor boot header | o pages |
| 322 | * +---------------------+ |
| 323 | * | vendor ramdisk | p pages |
| 324 | * +---------------------+ |
| 325 | * | dtb | q pages |
| 326 | * +---------------------+ |
| 327 | * o = (2112 + page_size - 1) / page_size |
| 328 | * p = (vendor_ramdisk_size + page_size - 1) / page_size |
| 329 | * q = (dtb_size + page_size - 1) / page_size |
| 330 | * |
| 331 | * 0. all entities in the boot image are 4096-byte aligned in flash, all |
| 332 | * entities in the vendor boot image are page_size (determined by the vendor |
| 333 | * and specified in the vendor boot image header) aligned in flash |
| 334 | * 1. kernel, ramdisk, vendor ramdisk, and DTB are required (size != 0) |
| 335 | * 2. load the kernel and DTB at the specified physical address (kernel_addr, |
| 336 | * dtb_addr) * 3. load the vendor ramdisk at ramdisk_addr |
| 337 | * 4. load the generic ramdisk immediately following the vendor ramdisk in |
| 338 | * memory |
| 339 | * 5. set up registers for kernel entry as required by your architecture |
| 340 | * 6. if the platform has a second stage bootloader jump to it (must be |
| 341 | * contained outside boot and vendor boot partitions), otherwise |
| 342 | * jump to kernel_addr |
| 343 | */ |
| 344 | |
| 345 | struct vendor_boot_img_hdr { |
| 346 | char magic[VENDOR_BOOT_MAGIC_SIZE]; /*"VNDRBOOT"*/ |
| 347 | |
| 348 | uint32_t header_version; /*Version of the vendor boot image header*/ |
| 349 | uint32_t page_size; /* flash page size we assume */ |
| 350 | |
| 351 | uint32_t kernel_addr; /* physical load addr */ |
| 352 | uint32_t ramdisk_addr; /* physical load addr */ |
| 353 | |
| 354 | uint32_t vendor_ramdisk_size; /* size in bytes */ |
| 355 | |
| 356 | char cmdline[VENDOR_BOOT_ARGS_SIZE]; /*2048B*/ |
| 357 | |
| 358 | uint32_t tags_addr; /* physical addr for kernel tags (if required) */ |
| 359 | uint8_t name[VENDOR_BOOT_NAME_SIZE]; /* 16B asciiz product name */ |
| 360 | |
| 361 | uint32_t header_size; |
| 362 | |
| 363 | uint32_t dtb_size; /* size in bytes for DTB image */ |
| 364 | uint64_t dtb_addr; /* physical load address for DTB image */ |
| 365 | /* new for v4 */ |
| 366 | u32 vendor_ramdisk_table_size;/* size in bytes for the vendor ramdisk table */ |
| 367 | u32 vendor_ramdisk_table_entry_num;/* number of entries in the vendor ramdisk table */ |
| 368 | u32 vendor_ramdisk_table_entry_size; |
| 369 | u32 vendor_bootconfig_size;/* size in bytes for bootconfig image */ |
| 370 | unsigned char szReserved[VENDOR_BOOT_IMG_HDR_SIZE - 2128]; |
| 371 | }; |
| 372 | |
| 373 | typedef struct vendor_boot_img_hdr vendor_boot_img_hdr_t; |
| 374 | typedef struct vendor_boot_img_hdr *p_vendor_boot_img_hdr_t; |
| 375 | |
| 376 | struct vendor_ramdisk_table_entry_v4 { |
| 377 | u32 ramdisk_size; /* size in bytes for the ramdisk image */ |
| 378 | u32 ramdisk_offset; /* offset to the ramdisk image in vendor ramdisk section */ |
| 379 | u32 ramdisk_type; /* type of the ramdisk */ |
| 380 | char ramdisk_name[VENDOR_RAMDISK_NAME_SIZE]; /* asciiz ramdisk name */ |
| 381 | // Hardware identifiers describing the board, soc or platform which this |
| 382 | // ramdisk is intended to be loaded on. |
| 383 | u32 board_id[VENDOR_RAMDISK_TABLE_ENTRY_BOARD_ID_SIZE]; |
| 384 | }; |
| 385 | |
| 386 | typedef struct vendor_ramdisk_table_entry_v4 *p_vendor_ramdisk_table_entry_v4_t; |
| 387 | |
| 388 | /* When the boot image header has a version of 4, the structure of the boot |
| 389 | * image is the same as version 3: |
| 390 | * |
| 391 | * +---------------------+ |
| 392 | * | boot header | 4096 bytes |
| 393 | * +---------------------+ |
| 394 | * | kernel | m pages |
| 395 | * +---------------------+ |
| 396 | * | ramdisk | n pages |
| 397 | * +---------------------+ |
| 398 | * |
| 399 | * m = (kernel_size + 4096 - 1) / 4096 |
| 400 | * n = (ramdisk_size + 4096 - 1) / 4096 |
| 401 | * |
| 402 | * Note that in version 4 of the boot image header, page size is fixed at 4096 |
| 403 | * bytes. |
| 404 | * |
| 405 | * The structure of the vendor boot image version 4, which is required to be |
| 406 | * present when a version 4 boot image is used, is as follows: |
| 407 | * |
| 408 | * +------------------------+ |
| 409 | * | vendor boot header | o pages |
| 410 | * +------------------------+ |
| 411 | * | vendor ramdisk section | p pages |
| 412 | * +------------------------+ |
| 413 | * | dtb | q pages |
| 414 | * +------------------------+ |
| 415 | * | vendor ramdisk table | r pages |
| 416 | * +------------------------+ |
| 417 | * | bootconfig | s pages |
| 418 | * +------------------------+ |
| 419 | * |
| 420 | * o = (2124 + page_size - 1) / page_size |
| 421 | * p = (vendor_ramdisk_size + page_size - 1) / page_size |
| 422 | * q = (dtb_size + page_size - 1) / page_size |
| 423 | * r = (vendor_ramdisk_table_size + page_size - 1) / page_size |
| 424 | * s = (vendor_bootconfig_size + page_size - 1) / page_size |
| 425 | * |
| 426 | * Note that in version 4 of the vendor boot image, multiple vendor ramdisks can |
| 427 | * be included in the vendor boot image. The bootloader can select a subset of |
| 428 | * ramdisks to load at runtime. To help the bootloader select the ramdisks, each |
| 429 | * ramdisk is tagged with a type tag and a set of hardware identifiers |
| 430 | * describing the board, soc or platform that this ramdisk is intended for. |
| 431 | * |
| 432 | * The vendor ramdisk section is consist of multiple ramdisk images concatenated |
| 433 | * one after another, and vendor_ramdisk_size is the size of the section, which |
| 434 | * is the total size of all the ramdisks included in the vendor boot image. |
| 435 | * |
| 436 | * The vendor ramdisk table holds the size, offset, type, name and hardware |
| 437 | * identifiers of each ramdisk. The type field denotes the type of its content. |
| 438 | * The hardware identifiers are specified in the board_id field in each table |
| 439 | * entry. The board_id field is consist of a vector of unsigned integer words, |
| 440 | * and the encoding scheme is defined by the hardware vendor. |
| 441 | * |
| 442 | * For the different type of ramdisks, there are: |
| 443 | * - VENDOR_RAMDISK_TYPE_NONE indicates the value is unspecified. |
| 444 | * - VENDOR_RAMDISK_TYPE_PLATFORM ramdisk contains platform specific bits. |
| 445 | * - VENDOR_RAMDISK_TYPE_RECOVERY ramdisk contains recovery resources. |
| 446 | * - VENDOR_RAMDISK_TYPE_DLKM ramdisk contains dynamic loadable kernel |
| 447 | * modules. |
| 448 | * |
| 449 | * Version 4 of the vendor boot image also adds a bootconfig section to the end |
| 450 | * of the image. This section contains Boot Configuration parameters known at |
| 451 | * build time. The bootloader is responsible for placing this section directly |
| 452 | * after the boot image ramdisk, followed by the bootconfig trailer, before |
| 453 | * entering the kernel. |
| 454 | * |
| 455 | * 0. all entities in the boot image are 4096-byte aligned in flash, all |
| 456 | * entities in the vendor boot image are page_size (determined by the vendor |
| 457 | * and specified in the vendor boot image header) aligned in flash |
| 458 | * 1. kernel, ramdisk, and DTB are required (size != 0) |
| 459 | * 2. load the kernel and DTB at the specified physical address (kernel_addr, |
| 460 | * dtb_addr) |
| 461 | * 3. load the vendor ramdisks at ramdisk_addr |
| 462 | * 4. load the generic ramdisk immediately following the vendor ramdisk in |
| 463 | * memory |
| 464 | * 5. load the vendor bootconfig immediately following the generic ramdisk. Add |
| 465 | * additional bootconfig parameters followed by the bootconfig trailer. |
| 466 | * 6. set up registers for kernel entry as required by your architecture |
| 467 | * 7. if the platform has a second stage bootloader jump to it (must be |
| 468 | * contained outside boot and vendor boot partitions), otherwise |
| 469 | * jump to kernel_addr |
| 470 | */ |
| 471 | /* When the boot image header has a version of 3, the structure of the boot |
| 472 | * image is as follows: |
| 473 | * |
| 474 | * +---------------------+ |
| 475 | * | boot header | 4096 bytes |
| 476 | * +---------------------+ |
| 477 | * | kernel | m pages |
| 478 | * +---------------------+ |
| 479 | * | ramdisk | n pages |
| 480 | * +---------------------+ |
| 481 | * |
| 482 | * m = (kernel_size + 4096 - 1) / 4096 |
| 483 | * n = (ramdisk_size + 4096 - 1) / 4096 |
| 484 | * |
| 485 | * Note that in version 3 of the boot image header, page size is fixed at 4096 bytes. |
| 486 | * |
| 487 | * The structure of the vendor boot image (introduced with version 3 and |
| 488 | * required to be present when a v3 boot image is used) is as follows: |
| 489 | * |
| 490 | * +---------------------+ |
| 491 | * | vendor boot header | o pages |
| 492 | * +---------------------+ |
| 493 | * | vendor ramdisk | p pages |
| 494 | * +---------------------+ |
| 495 | * | dtb | q pages |
| 496 | * +---------------------+ |
| 497 | * |
| 498 | * o = (2112 + page_size - 1) / page_size |
| 499 | * p = (vendor_ramdisk_size + page_size - 1) / page_size |
| 500 | * q = (dtb_size + page_size - 1) / page_size |
| 501 | * |
| 502 | * 0. all entities in the boot image are 4096-byte aligned in flash, all |
| 503 | * entities in the vendor boot image are page_size (determined by the vendor |
| 504 | * and specified in the vendor boot image header) aligned in flash |
| 505 | * 1. kernel, ramdisk, vendor ramdisk, and DTB are required (size != 0) |
| 506 | * 2. load the kernel and DTB at the specified physical address (kernel_addr, |
| 507 | * dtb_addr) |
| 508 | * 3. load the vendor ramdisk at ramdisk_addr |
| 509 | * 4. load the generic ramdisk immediately following the vendor ramdisk in |
| 510 | * memory |
| 511 | * 5. set up registers for kernel entry as required by your architecture |
| 512 | * 6. if the platform has a second stage bootloader jump to it (must be |
| 513 | * contained outside boot and vendor boot partitions), otherwise |
| 514 | * jump to kernel_addr |
| 515 | */ |
| 516 | /* When a boot header is of version 0, the structure of boot image is as |
| 517 | * follows: |
| 518 | * |
| 519 | * +-----------------+ |
| 520 | * | boot header | 1 page |
| 521 | * +-----------------+ |
| 522 | * | kernel | n pages |
| 523 | * +-----------------+ |
| 524 | * | ramdisk | m pages |
| 525 | * +-----------------+ |
| 526 | * | second stage | o pages |
| 527 | * +-----------------+ |
| 528 | * |
| 529 | * n = (kernel_size + page_size - 1) / page_size |
| 530 | * m = (ramdisk_size + page_size - 1) / page_size |
| 531 | * o = (second_size + page_size - 1) / page_size |
| 532 | * |
| 533 | * 0. all entities are page_size aligned in flash |
| 534 | * 1. kernel and ramdisk are required (size != 0) |
| 535 | * 2. second is optional (second_size == 0 -> no second) |
| 536 | * 3. load each element (kernel, ramdisk, second) at |
| 537 | * the specified physical address (kernel_addr, etc) |
| 538 | * 4. prepare tags at tag_addr. kernel_args[] is |
| 539 | * appended to the kernel commandline in the tags. |
| 540 | * 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr |
| 541 | * 6. if second_size != 0: jump to second_addr |
| 542 | * else: jump to kernel_addr |
| 543 | */ |
| 544 | /* When the boot image header has a version of 2, the structure of the boot |
| 545 | * image is as follows: |
| 546 | * |
| 547 | * +---------------------+ |
| 548 | * | boot header | 1 page |
| 549 | * +---------------------+ |
| 550 | * | kernel | n pages |
| 551 | * +---------------------+ |
| 552 | * | ramdisk | m pages |
| 553 | * +---------------------+ |
| 554 | * | second stage | o pages |
| 555 | * +---------------------+ |
| 556 | * | recovery dtbo/acpio | p pages |
| 557 | * +---------------------+ |
| 558 | * | dtb | q pages |
| 559 | * +---------------------+ |
| 560 | * |
| 561 | * n = (kernel_size + page_size - 1) / page_size |
| 562 | * m = (ramdisk_size + page_size - 1) / page_size |
| 563 | * o = (second_size + page_size - 1) / page_size |
| 564 | * p = (recovery_dtbo_size + page_size - 1) / page_size |
| 565 | * q = (dtb_size + page_size - 1) / page_size |
| 566 | * |
| 567 | * 0. all entities are page_size aligned in flash |
| 568 | * 1. kernel, ramdisk and DTB are required (size != 0) |
| 569 | * 2. recovery_dtbo/recovery_acpio is required for recovery.img in non-A/B |
| 570 | * devices(recovery_dtbo_size != 0) |
| 571 | * 3. second is optional (second_size == 0 -> no second) |
| 572 | * 4. load each element (kernel, ramdisk, second, dtb) at |
| 573 | * the specified physical address (kernel_addr, etc) |
| 574 | * 5. If booting to recovery mode in a non-A/B device, extract recovery |
| 575 | * dtbo/acpio and apply the correct set of overlays on the base device tree |
| 576 | * depending on the hardware/product revision. |
| 577 | * 6. prepare tags at tag_addr. kernel_args[] is |
| 578 | * appended to the kernel commandline in the tags. |
| 579 | * 7. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr |
| 580 | * 8. if second_size != 0: jump to second_addr |
| 581 | * else: jump to kernel_addr |
| 582 | */ |
| 583 | |
| 584 | typedef struct vendor_ramdisk_table_entry_v4 vendor_ramdisk_table_entry_v4_t; |
| 585 | typedef struct vendor_ramdisk_table_entry_v4 *p_vendor_ramdisk_table_entry_v4_t; |
| 586 | |
| 587 | /*compile check*/ |
| 588 | BUILD_ASSERT((sizeof(vendor_boot_img_hdr_t) == VENDOR_BOOT_IMG_HDR_SIZE)); |
| 589 | |
| 590 | struct vendor_boot_img { |
| 591 | vendor_boot_img_hdr_t hdr; |
| 592 | unsigned char szData[1]; |
| 593 | }; |
| 594 | |
| 595 | typedef struct vendor_boot_img vendor_boot_img_t; |
| 596 | typedef struct vendor_boot_img *p_vendor_boot_img_t; |
| 597 | |
| 598 | extern p_vendor_boot_img_t p_vender_boot_img; |
| 599 | extern unsigned init_boot_ramdisk_size; |
| 600 | #endif |
Alex Deymo | 0b6febf | 2019-08-05 22:24:45 +0200 | [diff] [blame] | 601 | |
Sebastian Siewior | 9ace3fc | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 602 | #endif |