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_MISC "misc" 17 #define ANDROID_PARTITION_OEM "oem" 18 #define ANDROID_PARTITION_RECOVERY "recovery" 19 #define ANDROID_PARTITION_SYSTEM "system" 20 #define ANDROID_PARTITION_VBMETA "vbmeta" 21 #define ANDROID_PARTITION_SUPER "super" 22 23 #define ANDROID_ARG_SLOT_SUFFIX "androidboot.slot_suffix=" 24 #define ANDROID_ARG_ROOT "root=" 25 #define ANDROID_ARG_SERIALNO "androidboot.serialno=" 26 #define ANDROID_VERIFY_STATE "androidboot.verifiedbootstate=" 27 #ifdef CONFIG_ROCKCHIP_RESOURCE_IMAGE 28 #define ANDROID_ARG_FDT_FILENAME "rk-kernel.dtb" 29 #else 30 #define ANDROID_ARG_FDT_FILENAME "kernel.dtb" 31 #endif 32 #define OEM_UNLOCK_ARG_SIZE 30 33 #define UUID_SIZE 37 34 35 #define ANDR_BOOT_MAGIC "ANDROID!" 36 #define VENDOR_BOOT_MAGIC "VNDRBOOT" 37 #define ANDR_BOOT_MAGIC_SIZE 8 38 #define VENDOR_BOOT_MAGIC_SIZE 8 39 #define ANDR_BOOT_NAME_SIZE 16 40 #define VENDOR_BOOT_NAME_SIZE 16 41 #define ANDR_BOOT_ARGS_SIZE 512 42 #define ANDR_BOOT_EXTRA_ARGS_SIZE 1024 43 #define VENDOR_BOOT_ARGS_SIZE 2048 44 #define ANDR_BOOT_IMG_PAGE_SIZE 4096 45 #define ANDR_BOOT_IMG_HDR_SIZE (ANDR_BOOT_IMG_PAGE_SIZE) 46 #define TOTAL_BOOT_ARGS_SIZE (ANDR_BOOT_ARGS_SIZE + ANDR_BOOT_EXTRA_ARGS_SIZE + \ 47 VENDOR_BOOT_ARGS_SIZE + 1) 48 #define VENDOR_BOOT_HDR_SIZE 2112 49 50 /* 51 * It is expected that callers would explicitly specify which version of the 52 * boot image header they need to use. 53 */ 54 typedef struct andr_img_hdr andr_img_hdr; 55 56 /* The bootloader expects the structure of andr_img_hdr with header 57 * version 0 to be as follows: */ 58 struct andr_img_hdr { 59 /* Must be ANDR_BOOT_MAGIC. */ 60 char magic[ANDR_BOOT_MAGIC_SIZE]; 61 62 u32 kernel_size; /* size in bytes */ 63 u32 kernel_addr; /* physical load addr */ 64 65 u32 ramdisk_size; /* size in bytes */ 66 u32 ramdisk_addr; /* physical load addr */ 67 68 u32 second_size; /* size in bytes */ 69 u32 second_addr; /* physical load addr */ 70 71 u32 tags_addr; /* physical addr for kernel tags */ 72 u32 page_size; /* flash page size we assume */ 73 74 /* Version of the boot image header. */ 75 u32 header_version; 76 77 /* Operating system version and security patch level. 78 * For version "A.B.C" and patch level "Y-M-D": 79 * (7 bits for each of A, B, C; 7 bits for (Y-2000), 4 bits for M) 80 * os_version = A[31:25] B[24:18] C[17:11] (Y-2000)[10:4] M[3:0] */ 81 u32 os_version; 82 83 char name[ANDR_BOOT_NAME_SIZE]; /* asciiz product name */ 84 85 char cmdline[ANDR_BOOT_ARGS_SIZE]; 86 87 u32 id[8]; /* timestamp / checksum / sha1 / etc */ 88 89 /* Supplemental command line data; kept here to maintain 90 * binary compatibility with older versions of mkbootimg. */ 91 char extra_cmdline[ANDR_BOOT_EXTRA_ARGS_SIZE]; 92 93 /* Fields in boot_img_hdr_v1(Android-9) and newer. */ 94 u32 recovery_dtbo_size; /* size in bytes for recovery DTBO/ACPIO image */ 95 u64 recovery_dtbo_offset; /* offset to recovery dtbo/acpio in boot image */ 96 u32 header_size; 97 98 /* Fields in boot_img_hdr_v2(Android-10) and newer. */ 99 u32 dtb_size; /* size in bytes for DTB image */ 100 u64 dtb_addr; /* physical load address for DTB image */ 101 102 /* 103 * [Rockchip compatibility] 104 * 105 * boot_img_hdr_v3(Android-11) is not compatible with boot_img_hdr_v012, 106 * we have to partly merge fields from boot_img_hdr_v3 and vendor_boot_img_hdr_v3 107 * into this structure to compatible with boot_img_hdr_v012. 108 */ 109 u32 boot_ramdisk_size; /* size in bytes */ 110 u32 vendor_ramdisk_size; /* size in bytes */ 111 u32 vendor_page_size; 112 u32 vendor_header_version; 113 u32 vendor_header_size; 114 /* 115 * Don't define 'char total_cmdline[TOTAL_BOOT_ARGS_SIZE]' to avoid 116 * this structrue is over size than page_size. 117 */ 118 char *total_cmdline; 119 } __attribute__((packed)); 120 121 struct boot_img_hdr_v3 { 122 /* Must be ANDR_BOOT_MAGIC. */ 123 uint8_t magic[ANDR_BOOT_MAGIC_SIZE]; 124 125 uint32_t kernel_size; /* size in bytes */ 126 uint32_t ramdisk_size; /* size in bytes */ 127 128 /* Operating system version and security patch level. 129 * For version "A.B.C" and patch level "Y-M-D": 130 * (7 bits for each of A, B, C; 7 bits for (Y-2000), 4 bits for M) 131 * os_version = A[31:25] B[24:18] C[17:11] (Y-2000)[10:4] M[3:0] */ 132 uint32_t os_version; 133 134 uint32_t header_size; 135 136 uint32_t reserved[4]; 137 138 uint32_t header_version; 139 140 uint8_t cmdline[ANDR_BOOT_ARGS_SIZE + ANDR_BOOT_EXTRA_ARGS_SIZE]; 141 } __attribute__((packed)); 142 143 struct vendor_boot_img_hdr_v3 { 144 /* Must be VENDOR_BOOT_MAGIC. */ 145 uint8_t magic[VENDOR_BOOT_MAGIC_SIZE]; 146 147 /* Version of the vendor boot image header. */ 148 uint32_t header_version; 149 150 uint32_t page_size; /* flash page size we assume */ 151 152 uint32_t kernel_addr; /* physical load addr */ 153 uint32_t ramdisk_addr; /* physical load addr */ 154 155 uint32_t vendor_ramdisk_size; /* size in bytes */ 156 157 uint8_t cmdline[VENDOR_BOOT_ARGS_SIZE]; 158 159 uint32_t tags_addr; /* physical addr for kernel tags (if required) */ 160 uint8_t name[VENDOR_BOOT_NAME_SIZE]; /* asciiz product name */ 161 162 uint32_t header_size; 163 164 uint32_t dtb_size; /* size in bytes for DTB image */ 165 uint64_t dtb_addr; /* physical load address for DTB image */ 166 } __attribute__((packed)); 167 168 /* When a boot header is of version 0, the structure of boot image is as 169 * follows: 170 * 171 * +-----------------+ 172 * | boot header | 1 page 173 * +-----------------+ 174 * | kernel | n pages 175 * +-----------------+ 176 * | ramdisk | m pages 177 * +-----------------+ 178 * | second stage | o pages 179 * +-----------------+ 180 * 181 * n = (kernel_size + page_size - 1) / page_size 182 * m = (ramdisk_size + page_size - 1) / page_size 183 * o = (second_size + page_size - 1) / page_size 184 * 185 * 0. all entities are page_size aligned in flash 186 * 1. kernel and ramdisk are required (size != 0) 187 * 2. second is optional (second_size == 0 -> no second) 188 * 3. load each element (kernel, ramdisk, second) at 189 * the specified physical address (kernel_addr, etc) 190 * 4. prepare tags at tag_addr. kernel_args[] is 191 * appended to the kernel commandline in the tags. 192 * 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr 193 * 6. if second_size != 0: jump to second_addr 194 * else: jump to kernel_addr 195 */ 196 197 /* When the boot image header has a version of 2, the structure of the boot 198 * image is as follows: 199 * 200 * +---------------------+ 201 * | boot header | 1 page 202 * +---------------------+ 203 * | kernel | n pages 204 * +---------------------+ 205 * | ramdisk | m pages 206 * +---------------------+ 207 * | second stage | o pages 208 * +---------------------+ 209 * | recovery dtbo/acpio | p pages 210 * +---------------------+ 211 * | dtb | q pages 212 * +---------------------+ 213 214 * n = (kernel_size + page_size - 1) / page_size 215 * m = (ramdisk_size + page_size - 1) / page_size 216 * o = (second_size + page_size - 1) / page_size 217 * p = (recovery_dtbo_size + page_size - 1) / page_size 218 * q = (dtb_size + page_size - 1) / page_size 219 * 220 * 0. all entities are page_size aligned in flash 221 * 1. kernel, ramdisk and DTB are required (size != 0) 222 * 2. recovery_dtbo/recovery_acpio is required for recovery.img in non-A/B 223 * devices(recovery_dtbo_size != 0) 224 * 3. second is optional (second_size == 0 -> no second) 225 * 4. load each element (kernel, ramdisk, second, dtb) at 226 * the specified physical address (kernel_addr, etc) 227 * 5. If booting to recovery mode in a non-A/B device, extract recovery 228 * dtbo/acpio and apply the correct set of overlays on the base device tree 229 * depending on the hardware/product revision. 230 * 6. prepare tags at tag_addr. kernel_args[] is 231 * appended to the kernel commandline in the tags. 232 * 7. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr 233 * 8. if second_size != 0: jump to second_addr 234 * else: jump to kernel_addr 235 */ 236 237 /* When the boot image header has a version of 3, the structure of the boot 238 * image is as follows: 239 * 240 * +---------------------+ 241 * | boot header | 4096 bytes 242 * +---------------------+ 243 * | kernel | m pages 244 * +---------------------+ 245 * | ramdisk | n pages 246 * +---------------------+ 247 * 248 * m = (kernel_size + 4096 - 1) / 4096 249 * n = (ramdisk_size + 4096 - 1) / 4096 250 * 251 * Note that in version 3 of the boot image header, page size is fixed at 4096 bytes. 252 * 253 * The structure of the vendor boot image (introduced with version 3 and 254 * required to be present when a v3 boot image is used) is as follows: 255 * 256 * +---------------------+ 257 * | vendor boot header | o pages 258 * +---------------------+ 259 * | vendor ramdisk | p pages 260 * +---------------------+ 261 * | dtb | q pages 262 * +---------------------+ 263 * 264 * o = (2112 + page_size - 1) / page_size 265 * p = (vendor_ramdisk_size + page_size - 1) / page_size 266 * q = (dtb_size + page_size - 1) / page_size 267 * 268 * 0. all entities in the boot image are 4096-byte aligned in flash, all 269 * entities in the vendor boot image are page_size (determined by the vendor 270 * and specified in the vendor boot image header) aligned in flash 271 * 1. kernel, ramdisk, vendor ramdisk, and DTB are required (size != 0) 272 * 2. load the kernel and DTB at the specified physical address (kernel_addr, 273 * dtb_addr) 274 * 3. load the vendor ramdisk at ramdisk_addr 275 * 4. load the generic ramdisk immediately following the vendor ramdisk in 276 * memory 277 * 5. set up registers for kernel entry as required by your architecture 278 * 6. if the platform has a second stage bootloader jump to it (must be 279 * contained outside boot and vendor boot partitions), otherwise 280 * jump to kernel_addr 281 */ 282 283 #endif 284