1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* 3 * This is from the Android Project, 4 * Repository: https://android.googlesource.com/platform/system/tools/mkbootimg 5 * File: include/bootimg/bootimg.h 6 * Commit: e55998a0f2b61b685d5eb4a486ca3a0c680b1a2f 7 * 8 * Copyright (C) 2007 The Android Open Source Project 9 */ 10 11 #ifndef _ANDROID_IMAGE_H_ 12 #define _ANDROID_IMAGE_H_ 13 14 #define ANDROID_PARTITION_BOOT "boot" 15 #define ANDROID_PARTITION_VENDOR_BOOT "vendor_boot" 16 #define ANDROID_PARTITION_INIT_BOOT "init_boot" 17 #define ANDROID_PARTITION_MISC "misc" 18 #define ANDROID_PARTITION_OEM "oem" 19 #define ANDROID_PARTITION_RESOURCE "resource" 20 #define ANDROID_PARTITION_RECOVERY "recovery" 21 #define ANDROID_PARTITION_SYSTEM "system" 22 #define ANDROID_PARTITION_VBMETA "vbmeta" 23 #define ANDROID_PARTITION_SUPER "super" 24 25 #define ANDROID_ARG_SLOT_SUFFIX "androidboot.slot_suffix=" 26 #define ANDROID_ARG_ROOT "root=" 27 #define ANDROID_ARG_SERIALNO "androidboot.serialno=" 28 #define ANDROID_VERIFY_STATE "androidboot.verifiedbootstate=" 29 #ifdef CONFIG_ROCKCHIP_RESOURCE_IMAGE 30 #define ANDROID_ARG_FDT_FILENAME "rk-kernel.dtb" 31 #else 32 #define ANDROID_ARG_FDT_FILENAME "kernel.dtb" 33 #endif 34 #define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR 0x10008000 35 36 #define OEM_UNLOCK_ARG_SIZE 30 37 #define UUID_SIZE 37 38 39 #define ANDR_BOOT_MAGIC "ANDROID!" 40 #define VENDOR_BOOT_MAGIC "VNDRBOOT" 41 #define ANDR_BOOT_MAGIC_SIZE 8 42 #define VENDOR_BOOT_MAGIC_SIZE 8 43 #define ANDR_BOOT_NAME_SIZE 16 44 #define VENDOR_BOOT_NAME_SIZE 16 45 #define ANDR_BOOT_ARGS_SIZE 512 46 #define ANDR_BOOT_EXTRA_ARGS_SIZE 1024 47 #define VENDOR_BOOT_ARGS_SIZE 2048 48 #define ANDR_BOOT_IMG_PAGE_SIZE 4096 49 #define ANDR_BOOT_IMG_HDR_SIZE (ANDR_BOOT_IMG_PAGE_SIZE) 50 #define TOTAL_BOOT_ARGS_SIZE (ANDR_BOOT_ARGS_SIZE + ANDR_BOOT_EXTRA_ARGS_SIZE + \ 51 VENDOR_BOOT_ARGS_SIZE + 1) 52 #define VENDOR_BOOT_HDRv3_SIZE 2112 53 #define VENDOR_BOOT_HDRv4_SIZE 2124 54 55 #define VENDOR_RAMDISK_TYPE_NONE 0 56 #define VENDOR_RAMDISK_TYPE_PLATFORM 1 57 #define VENDOR_RAMDISK_TYPE_RECOVERY 2 58 #define VENDOR_RAMDISK_TYPE_DLKM 3 59 #define VENDOR_RAMDISK_NAME_SIZE 32 60 #define VENDOR_RAMDISK_TABLE_ENTRY_BOARD_ID_SIZE 16 61 62 /* defined by rockchip but not google, it's adjustable */ 63 #define ANDROID_ADDITION_BOOTCONFIG_PARAMS_MAX_SIZE SZ_8K 64 65 /* 66 * It is expected that callers would explicitly specify which version of the 67 * boot image header they need to use. 68 */ 69 typedef struct andr_img_hdr andr_img_hdr; 70 71 /* The bootloader expects the structure of andr_img_hdr with header 72 * version 0 to be as follows: */ 73 struct andr_img_hdr { 74 /* Must be ANDR_BOOT_MAGIC. */ 75 char magic[ANDR_BOOT_MAGIC_SIZE]; 76 77 u32 kernel_size; /* size in bytes */ 78 u32 kernel_addr; /* physical load addr */ 79 80 u32 ramdisk_size; /* size in bytes */ 81 u32 ramdisk_addr; /* physical load addr */ 82 83 u32 second_size; /* size in bytes */ 84 u32 second_addr; /* physical load addr */ 85 86 u32 tags_addr; /* physical addr for kernel tags */ 87 u32 page_size; /* flash page size we assume */ 88 89 /* Version of the boot image header. */ 90 u32 header_version; 91 92 /* Operating system version and security patch level. 93 * For version "A.B.C" and patch level "Y-M-D": 94 * (7 bits for each of A, B, C; 7 bits for (Y-2000), 4 bits for M) 95 * os_version = A[31:25] B[24:18] C[17:11] (Y-2000)[10:4] M[3:0] */ 96 u32 os_version; 97 98 char name[ANDR_BOOT_NAME_SIZE]; /* asciiz product name */ 99 100 char cmdline[ANDR_BOOT_ARGS_SIZE]; 101 102 u32 id[8]; /* timestamp / checksum / sha1 / etc */ 103 104 /* Supplemental command line data; kept here to maintain 105 * binary compatibility with older versions of mkbootimg. */ 106 char extra_cmdline[ANDR_BOOT_EXTRA_ARGS_SIZE]; 107 108 /* Fields in boot_img_hdr_v1(Android-9) and newer. */ 109 u32 recovery_dtbo_size; /* size in bytes for recovery DTBO/ACPIO image */ 110 u64 recovery_dtbo_offset; /* offset to recovery dtbo/acpio in boot image */ 111 u32 header_size; 112 113 /* Fields in boot_img_hdr_v2(Android-10) and newer. */ 114 u32 dtb_size; /* size in bytes for DTB image */ 115 u64 dtb_addr; /* physical load address for DTB image */ 116 117 /* 118 * [Rockchip compatibility Android v3] 119 * 120 * boot_img_hdr_v3(Android-11) is not compatible with boot_img_hdr_v012, 121 * we have to partly merge fields from boot_img_hdr_v34 and vendor_boot_img_hdr_v34 122 * into this structure to compatible with boot_img_hdr_v012. 123 */ 124 u32 vendor_ramdisk_size; /* size in bytes */ 125 u32 vendor_page_size; 126 u32 vendor_header_version; 127 u32 vendor_header_size; 128 129 /* 130 * [Rockchip compatibility Android v4] 131 * 132 * boot_img_hdr_v4(Android-12) is not compatible with boot_img_hdr_v012, 133 * we have to partly merge fields from boot_img_hdr_v34 and vendor_boot_img_hdr_v34 134 * into this structure to compatible with boot_img_hdr_v012. 135 */ 136 u32 vendor_ramdisk_table_size; 137 u32 vendor_ramdisk_table_entry_num; 138 u32 vendor_ramdisk_table_entry_size; 139 u32 vendor_bootconfig_size; /* size in bytes for bootconfig image */ 140 141 void *init_boot_buf; 142 void *vendor_boot_buf; 143 144 /* 145 * Don't define 'char total_cmdline[TOTAL_BOOT_ARGS_SIZE]' to avoid 146 * this structrue is over size than page_size. 147 */ 148 char *total_cmdline; 149 } __attribute__((packed)); 150 151 struct boot_img_hdr_v34 { 152 /* Must be ANDR_BOOT_MAGIC. */ 153 uint8_t magic[ANDR_BOOT_MAGIC_SIZE]; 154 155 uint32_t kernel_size; /* size in bytes */ 156 uint32_t ramdisk_size; /* size in bytes */ 157 158 /* Operating system version and security patch level. 159 * For version "A.B.C" and patch level "Y-M-D": 160 * (7 bits for each of A, B, C; 7 bits for (Y-2000), 4 bits for M) 161 * os_version = A[31:25] B[24:18] C[17:11] (Y-2000)[10:4] M[3:0] */ 162 uint32_t os_version; 163 164 uint32_t header_size; 165 166 uint32_t reserved[4]; 167 168 uint32_t header_version; 169 170 uint8_t cmdline[ANDR_BOOT_ARGS_SIZE + ANDR_BOOT_EXTRA_ARGS_SIZE]; 171 } __attribute__((packed)); 172 173 struct vendor_boot_img_hdr_v34 { 174 /* Must be VENDOR_BOOT_MAGIC. */ 175 uint8_t magic[VENDOR_BOOT_MAGIC_SIZE]; 176 177 /* Version of the vendor boot image header. */ 178 uint32_t header_version; 179 180 uint32_t page_size; /* flash page size we assume */ 181 182 uint32_t kernel_addr; /* physical load addr */ 183 uint32_t ramdisk_addr; /* physical load addr */ 184 185 uint32_t vendor_ramdisk_size; /* size in bytes */ 186 187 uint8_t cmdline[VENDOR_BOOT_ARGS_SIZE]; 188 189 uint32_t tags_addr; /* physical addr for kernel tags (if required) */ 190 uint8_t name[VENDOR_BOOT_NAME_SIZE]; /* asciiz product name */ 191 192 uint32_t header_size; 193 194 uint32_t dtb_size; /* size in bytes for DTB image */ 195 uint64_t dtb_addr; /* physical load address for DTB image */ 196 197 /* new for v4 */ 198 uint32_t vendor_ramdisk_table_size; /* size in bytes for the vendor ramdisk table */ 199 uint32_t vendor_ramdisk_table_entry_num; /* number of entries in the vendor ramdisk table */ 200 uint32_t vendor_ramdisk_table_entry_size; 201 uint32_t vendor_bootconfig_size; /* size in bytes for bootconfig image */ 202 } __attribute__((packed)); 203 204 struct vendor_ramdisk_table_entry_v4 { 205 uint32_t ramdisk_size; /* size in bytes for the ramdisk image */ 206 uint32_t ramdisk_offset; /* offset to the ramdisk image in vendor ramdisk section */ 207 uint32_t ramdisk_type; /* type of the ramdisk */ 208 uint8_t ramdisk_name[VENDOR_RAMDISK_NAME_SIZE]; /* asciiz ramdisk name */ 209 210 // Hardware identifiers describing the board, soc or platform which this 211 // ramdisk is intended to be loaded on. 212 uint32_t board_id[VENDOR_RAMDISK_TABLE_ENTRY_BOARD_ID_SIZE]; 213 } __attribute__((packed)); 214 215 /* When the boot image header has a version of 4, the structure of the boot 216 * image is the same as version 3: 217 * 218 * +---------------------+ 219 * | boot header | 4096 bytes 220 * +---------------------+ 221 * | kernel | m pages 222 * +---------------------+ 223 * | ramdisk | n pages 224 * +---------------------+ 225 * 226 * m = (kernel_size + 4096 - 1) / 4096 227 * n = (ramdisk_size + 4096 - 1) / 4096 228 * 229 * Note that in version 4 of the boot image header, page size is fixed at 4096 230 * bytes. 231 * 232 * The structure of the vendor boot image version 4, which is required to be 233 * present when a version 4 boot image is used, is as follows: 234 * 235 * +------------------------+ 236 * | vendor boot header | o pages 237 * +------------------------+ 238 * | vendor ramdisk section | p pages 239 * +------------------------+ 240 * | dtb | q pages 241 * +------------------------+ 242 * | vendor ramdisk table | r pages 243 * +------------------------+ 244 * | bootconfig | s pages 245 * +------------------------+ 246 * 247 * o = (2124 + page_size - 1) / page_size 248 * p = (vendor_ramdisk_size + page_size - 1) / page_size 249 * q = (dtb_size + page_size - 1) / page_size 250 * r = (vendor_ramdisk_table_size + page_size - 1) / page_size 251 * s = (vendor_bootconfig_size + page_size - 1) / page_size 252 * 253 * Note that in version 4 of the vendor boot image, multiple vendor ramdisks can 254 * be included in the vendor boot image. The bootloader can select a subset of 255 * ramdisks to load at runtime. To help the bootloader select the ramdisks, each 256 * ramdisk is tagged with a type tag and a set of hardware identifiers 257 * describing the board, soc or platform that this ramdisk is intended for. 258 * 259 * The vendor ramdisk section is consist of multiple ramdisk images concatenated 260 * one after another, and vendor_ramdisk_size is the size of the section, which 261 * is the total size of all the ramdisks included in the vendor boot image. 262 * 263 * The vendor ramdisk table holds the size, offset, type, name and hardware 264 * identifiers of each ramdisk. The type field denotes the type of its content. 265 * The hardware identifiers are specified in the board_id field in each table 266 * entry. The board_id field is consist of a vector of unsigned integer words, 267 * and the encoding scheme is defined by the hardware vendor. 268 * 269 * For the different type of ramdisks, there are: 270 * - VENDOR_RAMDISK_TYPE_NONE indicates the value is unspecified. 271 * - VENDOR_RAMDISK_TYPE_PLATFORM ramdisk contains platform specific bits. 272 * - VENDOR_RAMDISK_TYPE_RECOVERY ramdisk contains recovery resources. 273 * - VENDOR_RAMDISK_TYPE_DLKM ramdisk contains dynamic loadable kernel 274 * modules. 275 * 276 * Version 4 of the vendor boot image also adds a bootconfig section to the end 277 * of the image. This section contains Boot Configuration parameters known at 278 * build time. The bootloader is responsible for placing this section directly 279 * after the boot image ramdisk, followed by the bootconfig trailer, before 280 * entering the kernel. 281 * 282 * 0. all entities in the boot image are 4096-byte aligned in flash, all 283 * entities in the vendor boot image are page_size (determined by the vendor 284 * and specified in the vendor boot image header) aligned in flash 285 * 1. kernel, ramdisk, and DTB are required (size != 0) 286 * 2. load the kernel and DTB at the specified physical address (kernel_addr, 287 * dtb_addr) 288 * 3. load the vendor ramdisks at ramdisk_addr 289 * 4. load the generic ramdisk immediately following the vendor ramdisk in 290 * memory 291 * 5. load the vendor bootconfig immediately following the generic ramdisk. Add 292 * additional bootconfig parameters followed by the bootconfig trailer. 293 * 6. set up registers for kernel entry as required by your architecture 294 * 7. if the platform has a second stage bootloader jump to it (must be 295 * contained outside boot and vendor boot partitions), otherwise 296 * jump to kernel_addr 297 * 298 * When a boot header is of version 0, the structure of boot image is as 299 * follows: 300 * 301 * +-----------------+ 302 * | boot header | 1 page 303 * +-----------------+ 304 * | kernel | n pages 305 * +-----------------+ 306 * | ramdisk | m pages 307 * +-----------------+ 308 * | second stage | o pages 309 * +-----------------+ 310 * 311 * n = (kernel_size + page_size - 1) / page_size 312 * m = (ramdisk_size + page_size - 1) / page_size 313 * o = (second_size + page_size - 1) / page_size 314 * 315 * 0. all entities are page_size aligned in flash 316 * 1. kernel and ramdisk are required (size != 0) 317 * 2. second is optional (second_size == 0 -> no second) 318 * 3. load each element (kernel, ramdisk, second) at 319 * the specified physical address (kernel_addr, etc) 320 * 4. prepare tags at tag_addr. kernel_args[] is 321 * appended to the kernel commandline in the tags. 322 * 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr 323 * 6. if second_size != 0: jump to second_addr 324 * else: jump to kernel_addr 325 */ 326 327 /* When the boot image header has a version of 2, the structure of the boot 328 * image is as follows: 329 * 330 * +---------------------+ 331 * | boot header | 1 page 332 * +---------------------+ 333 * | kernel | n pages 334 * +---------------------+ 335 * | ramdisk | m pages 336 * +---------------------+ 337 * | second stage | o pages 338 * +---------------------+ 339 * | recovery dtbo/acpio | p pages 340 * +---------------------+ 341 * | dtb | q pages 342 * +---------------------+ 343 344 * n = (kernel_size + page_size - 1) / page_size 345 * m = (ramdisk_size + page_size - 1) / page_size 346 * o = (second_size + page_size - 1) / page_size 347 * p = (recovery_dtbo_size + page_size - 1) / page_size 348 * q = (dtb_size + page_size - 1) / page_size 349 * 350 * 0. all entities are page_size aligned in flash 351 * 1. kernel, ramdisk and DTB are required (size != 0) 352 * 2. recovery_dtbo/recovery_acpio is required for recovery.img in non-A/B 353 * devices(recovery_dtbo_size != 0) 354 * 3. second is optional (second_size == 0 -> no second) 355 * 4. load each element (kernel, ramdisk, second, dtb) at 356 * the specified physical address (kernel_addr, etc) 357 * 5. If booting to recovery mode in a non-A/B device, extract recovery 358 * dtbo/acpio and apply the correct set of overlays on the base device tree 359 * depending on the hardware/product revision. 360 * 6. prepare tags at tag_addr. kernel_args[] is 361 * appended to the kernel commandline in the tags. 362 * 7. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr 363 * 8. if second_size != 0: jump to second_addr 364 * else: jump to kernel_addr 365 */ 366 367 /* When the boot image header has a version of 3, the structure of the boot 368 * image is as follows: 369 * 370 * +---------------------+ 371 * | boot header | 4096 bytes 372 * +---------------------+ 373 * | kernel | m pages 374 * +---------------------+ 375 * | ramdisk | n pages 376 * +---------------------+ 377 * 378 * m = (kernel_size + 4096 - 1) / 4096 379 * n = (ramdisk_size + 4096 - 1) / 4096 380 * 381 * Note that in version 3 of the boot image header, page size is fixed at 4096 bytes. 382 * 383 * The structure of the vendor boot image (introduced with version 3 and 384 * required to be present when a v3 boot image is used) is as follows: 385 * 386 * +---------------------+ 387 * | vendor boot header | o pages 388 * +---------------------+ 389 * | vendor ramdisk | p pages 390 * +---------------------+ 391 * | dtb | q pages 392 * +---------------------+ 393 * 394 * o = (2112 + page_size - 1) / page_size 395 * p = (vendor_ramdisk_size + page_size - 1) / page_size 396 * q = (dtb_size + page_size - 1) / page_size 397 * 398 * 0. all entities in the boot image are 4096-byte aligned in flash, all 399 * entities in the vendor boot image are page_size (determined by the vendor 400 * and specified in the vendor boot image header) aligned in flash 401 * 1. kernel, ramdisk, vendor ramdisk, and DTB are required (size != 0) 402 * 2. load the kernel and DTB at the specified physical address (kernel_addr, 403 * dtb_addr) 404 * 3. load the vendor ramdisk at ramdisk_addr 405 * 4. load the generic ramdisk immediately following the vendor ramdisk in 406 * memory 407 * 5. set up registers for kernel entry as required by your architecture 408 * 6. if the platform has a second stage bootloader jump to it (must be 409 * contained outside boot and vendor boot partitions), otherwise 410 * jump to kernel_addr 411 */ 412 413 #endif 414