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