• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* tools/mkbootimg/bootimg.h
2 **
3 ** Copyright 2007, The Android Open Source Project
4 **
5 ** 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
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** 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
15 ** limitations under the License.
16 */
17 
18 // This file is a clone of the one found on system/core/mkbootimg. We've made a
19 // clone because the location of the original header has changed over time.
20 
21 #include <stdint.h>
22 
23 #ifndef CUTTLEFISH_LAUNCH_BOOT_IMAGE_H_
24 #define CUTTLEFISH_LAUNCH_BOOT_IMAGE_H_
25 
26 #define BOOT_MAGIC "ANDROID!"
27 #define BOOT_MAGIC_SIZE 8
28 #define BOOT_NAME_SIZE 16
29 #define BOOT_ARGS_SIZE 512
30 #define BOOT_EXTRA_ARGS_SIZE 1024
31 
32 #define BOOT_HEADER_VERSION_ZERO 0
33 /*
34  *  Bootloader expects the structure of boot_img_hdr with header version
35  *  BOOT_HEADER_VERSION_ZERO to be as follows:
36  */
37 struct boot_img_hdr_v0 {
38     uint8_t magic[BOOT_MAGIC_SIZE];
39 
40     uint32_t kernel_size; /* size in bytes */
41     uint32_t kernel_addr; /* physical load addr */
42 
43     uint32_t ramdisk_size; /* size in bytes */
44     uint32_t ramdisk_addr; /* physical load addr */
45 
46     uint32_t second_size; /* size in bytes */
47     uint32_t second_addr; /* physical load addr */
48 
49     uint32_t tags_addr; /* physical addr for kernel tags */
50     uint32_t page_size; /* flash page size we assume */
51     /*
52      * version for the boot image header.
53      */
54     uint32_t header_version;
55 
56     /* operating system version and security patch level; for
57      * version "A.B.C" and patch level "Y-M-D":
58      * ver = A << 14 | B << 7 | C         (7 bits for each of A, B, C)
59      * lvl = ((Y - 2000) & 127) << 4 | M  (7 bits for Y, 4 bits for M)
60      * os_version = ver << 11 | lvl */
61     uint32_t os_version;
62 
63     uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */
64 
65     uint8_t cmdline[BOOT_ARGS_SIZE];
66 
67     uint32_t id[8]; /* timestamp / checksum / sha1 / etc */
68 
69     /* Supplemental command line data; kept here to maintain
70      * binary compatibility with older versions of mkbootimg */
71     uint8_t extra_cmdline[BOOT_EXTRA_ARGS_SIZE];
72 } __attribute__((packed));
73 
74 /*
75  * It is expected that callers would explicitly specify which version of the
76  * boot image header they need to use.
77  */
78 typedef struct boot_img_hdr_v0 boot_img_hdr;
79 
80 /* When a boot header is of version BOOT_HEADER_VERSION_ZERO, the structure of boot image is as
81  * follows:
82  *
83  * +-----------------+
84  * | boot header     | 1 page
85  * +-----------------+
86  * | kernel          | n pages
87  * +-----------------+
88  * | ramdisk         | m pages
89  * +-----------------+
90  * | second stage    | o pages
91  * +-----------------+
92  *
93  * n = (kernel_size + page_size - 1) / page_size
94  * m = (ramdisk_size + page_size - 1) / page_size
95  * o = (second_size + page_size - 1) / page_size
96  *
97  * 0. all entities are page_size aligned in flash
98  * 1. kernel and ramdisk are required (size != 0)
99  * 2. second is optional (second_size == 0 -> no second)
100  * 3. load each element (kernel, ramdisk, second) at
101  *    the specified physical address (kernel_addr, etc)
102  * 4. prepare tags at tag_addr.  kernel_args[] is
103  *    appended to the kernel commandline in the tags.
104  * 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
105  * 6. if second_size != 0: jump to second_addr
106  *    else: jump to kernel_addr
107  */
108 
109 #define BOOT_HEADER_VERSION_ONE 1
110 
111 struct boot_img_hdr_v1 : public boot_img_hdr_v0 {
112     uint32_t recovery_dtbo_size;   /* size in bytes for recovery DTBO image */
113     uint64_t recovery_dtbo_offset; /* physical load addr */
114     uint32_t header_size;
115 } __attribute__((packed));
116 
117 /* When the boot image header has a version of BOOT_HEADER_VERSION_ONE, the structure of the boot
118  * image is as follows:
119  *
120  * +-----------------+
121  * | boot header     | 1 page
122  * +-----------------+
123  * | kernel          | n pages
124  * +-----------------+
125  * | ramdisk         | m pages
126  * +-----------------+
127  * | second stage    | o pages
128  * +-----------------+
129  * | recovery dtbo   | p pages
130  * +-----------------+
131  * n = (kernel_size + page_size - 1) / page_size
132  * m = (ramdisk_size + page_size - 1) / page_size
133  * o = (second_size + page_size - 1) / page_size
134  * p = (recovery_dtbo_size + page_size - 1) / page_size
135  *
136  * 0. all entities are page_size aligned in flash
137  * 1. kernel and ramdisk are required (size != 0)
138  * 2. recovery_dtbo is required for recovery.img in non-A/B devices(recovery_dtbo_size != 0)
139  * 3. second is optional (second_size == 0 -> no second)
140  * 4. load each element (kernel, ramdisk, second, recovery_dtbo) at
141  *    the specified physical address (kernel_addr, etc)
142  * 5. prepare tags at tag_addr.  kernel_args[] is
143  *    appended to the kernel commandline in the tags.
144  * 6. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
145  * 7. if second_size != 0: jump to second_addr
146  *    else: jump to kernel_addr
147  */
148 
149 #if 0
150 typedef struct ptentry ptentry;
151 
152 struct 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
168