blob: 0188d0e9409749463a475e7d21655573767cd814 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/* tools/mkbootimg/bootimg.h
2**
3** Copyright 2007, The Android Open Source Project
4**
Jayant Chowdharyf4bda9a2018-03-28 18:45:35 -07005** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08008**
Jayant Chowdharyf4bda9a2018-03-28 18:45:35 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080010**
Jayant Chowdharyf4bda9a2018-03-28 18:45:35 -070011** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080015** limitations under the License.
16*/
17
Rom Lemarchanddfff8292015-05-07 14:08:31 -070018#include <stdint.h>
19
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080020#ifndef _BOOT_IMAGE_H_
21#define _BOOT_IMAGE_H_
22
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080023#define BOOT_MAGIC "ANDROID!"
24#define BOOT_MAGIC_SIZE 8
25#define BOOT_NAME_SIZE 16
26#define BOOT_ARGS_SIZE 512
Andrew Boied35ce352013-08-21 15:48:40 -070027#define BOOT_EXTRA_ARGS_SIZE 1024
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080028
Hridya Valsaraju6bacea22018-03-20 15:26:00 -070029#define BOOT_HEADER_VERSION_ZERO 0
30/*
31 * Bootloader expects the structure of boot_img_hdr with header version
32 * BOOT_HEADER_VERSION_ZERO to be as follows:
33 */
34struct boot_img_hdr_v0 {
Rom Lemarchanddfff8292015-05-07 14:08:31 -070035 uint8_t magic[BOOT_MAGIC_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080036
Jayant Chowdharyf4bda9a2018-03-28 18:45:35 -070037 uint32_t kernel_size; /* size in bytes */
38 uint32_t kernel_addr; /* physical load addr */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080039
Rom Lemarchanddfff8292015-05-07 14:08:31 -070040 uint32_t ramdisk_size; /* size in bytes */
41 uint32_t ramdisk_addr; /* physical load addr */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080042
Jayant Chowdharyf4bda9a2018-03-28 18:45:35 -070043 uint32_t second_size; /* size in bytes */
44 uint32_t second_addr; /* physical load addr */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080045
Jayant Chowdharyf4bda9a2018-03-28 18:45:35 -070046 uint32_t tags_addr; /* physical addr for kernel tags */
47 uint32_t page_size; /* flash page size we assume */
Hridya Valsaraju6bacea22018-03-20 15:26:00 -070048 /*
49 * version for the boot image header.
50 */
51 uint32_t header_version;
Sami Tolvanend1628282016-03-14 09:08:59 -070052
53 /* operating system version and security patch level; for
54 * version "A.B.C" and patch level "Y-M-D":
55 * ver = A << 14 | B << 7 | C (7 bits for each of A, B, C)
56 * lvl = ((Y - 2000) & 127) << 4 | M (7 bits for Y, 4 bits for M)
57 * os_version = ver << 11 | lvl */
58 uint32_t os_version;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080059
Rom Lemarchanddfff8292015-05-07 14:08:31 -070060 uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */
Andrew Boied35ce352013-08-21 15:48:40 -070061
Rom Lemarchanddfff8292015-05-07 14:08:31 -070062 uint8_t cmdline[BOOT_ARGS_SIZE];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080063
Rom Lemarchanddfff8292015-05-07 14:08:31 -070064 uint32_t id[8]; /* timestamp / checksum / sha1 / etc */
Andrew Boied35ce352013-08-21 15:48:40 -070065
66 /* Supplemental command line data; kept here to maintain
67 * binary compatibility with older versions of mkbootimg */
Rom Lemarchanddfff8292015-05-07 14:08:31 -070068 uint8_t extra_cmdline[BOOT_EXTRA_ARGS_SIZE];
69} __attribute__((packed));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080070
71/*
Hridya Valsaraju6bacea22018-03-20 15:26:00 -070072 * It is expected that callers would explicitly specify which version of the
73 * boot image header they need to use.
74 */
75typedef struct boot_img_hdr_v0 boot_img_hdr;
76
77/* When a boot header is of version BOOT_HEADER_VERSION_ZERO, the structure of boot image is as
78 * follows:
79 *
80 * +-----------------+
81 * | boot header | 1 page
82 * +-----------------+
83 * | kernel | n pages
84 * +-----------------+
85 * | ramdisk | m pages
86 * +-----------------+
87 * | second stage | o pages
88 * +-----------------+
89 *
90 * n = (kernel_size + page_size - 1) / page_size
91 * m = (ramdisk_size + page_size - 1) / page_size
92 * o = (second_size + page_size - 1) / page_size
93 *
94 * 0. all entities are page_size aligned in flash
95 * 1. kernel and ramdisk are required (size != 0)
96 * 2. second is optional (second_size == 0 -> no second)
97 * 3. load each element (kernel, ramdisk, second) at
98 * the specified physical address (kernel_addr, etc)
99 * 4. prepare tags at tag_addr. kernel_args[] is
100 * appended to the kernel commandline in the tags.
101 * 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
102 * 6. if second_size != 0: jump to second_addr
103 * else: jump to kernel_addr
104 */
105
106#define BOOT_HEADER_VERSION_ONE 1
107
108struct boot_img_hdr_v1 : public boot_img_hdr_v0 {
109 uint32_t recovery_dtbo_size; /* size in bytes for recovery DTBO image */
Hridya Valsaraju59ef43e2018-05-30 10:57:18 -0700110 uint64_t recovery_dtbo_offset; /* offset to recovery dtbo in boot image */
Hridya Valsaraju6bacea22018-03-20 15:26:00 -0700111 uint32_t header_size;
112} __attribute__((packed));
113
114/* When the boot image header has a version of BOOT_HEADER_VERSION_ONE, the structure of the boot
115 * image is as follows:
116 *
117 * +-----------------+
118 * | boot header | 1 page
119 * +-----------------+
120 * | kernel | n pages
121 * +-----------------+
122 * | ramdisk | m pages
123 * +-----------------+
124 * | second stage | o pages
125 * +-----------------+
126 * | recovery dtbo | p pages
127 * +-----------------+
128 * n = (kernel_size + page_size - 1) / page_size
129 * m = (ramdisk_size + page_size - 1) / page_size
130 * o = (second_size + page_size - 1) / page_size
131 * p = (recovery_dtbo_size + page_size - 1) / page_size
132 *
133 * 0. all entities are page_size aligned in flash
134 * 1. kernel and ramdisk are required (size != 0)
135 * 2. recovery_dtbo is required for recovery.img in non-A/B devices(recovery_dtbo_size != 0)
136 * 3. second is optional (second_size == 0 -> no second)
Hridya Valsaraju59ef43e2018-05-30 10:57:18 -0700137 * 4. load each element (kernel, ramdisk, second) at
Hridya Valsaraju6bacea22018-03-20 15:26:00 -0700138 * the specified physical address (kernel_addr, etc)
Hridya Valsaraju59ef43e2018-05-30 10:57:18 -0700139 * 5. If booting to recovery mode in a non-A/B device, extract recovery dtbo and
140 * apply the correct set of overlays on the base device tree depending on the
141 * hardware/product revision.
142 * 6. prepare tags at tag_addr. kernel_args[] is
Hridya Valsaraju6bacea22018-03-20 15:26:00 -0700143 * appended to the kernel commandline in the tags.
Hridya Valsaraju59ef43e2018-05-30 10:57:18 -0700144 * 7. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
145 * 8. if second_size != 0: jump to second_addr
Hridya Valsaraju6bacea22018-03-20 15:26:00 -0700146 * else: jump to kernel_addr
147 */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800148
149#if 0
150typedef struct ptentry ptentry;
151
152struct ptentry {
153 char name[16]; /* asciiz partition name */
154 unsigned start; /* starting block number */
155 unsigned length; /* length in blocks */
156 unsigned flags; /* set to zero */
157};
158
159/* MSM Partition Table ATAG
160**
161** length: 2 + 7 * n
162** atag: 0x4d534d70
163** <ptentry> x n
164*/
165#endif
166
167#endif