summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHridya Valsaraju2018-03-20 17:26:00 -0500
committerHridya Valsaraju2018-03-28 14:53:21 -0500
commit147b355bb34cbd457a260c585be93193cef43b8e (patch)
tree8d03d64931ab6d4bf693fc27bd1fde4d72584019 /mkbootimg
parent7102f7c98d2aaa393cc6ddc44cf277c5b9b71bf1 (diff)
downloadplatform-system-core-147b355bb34cbd457a260c585be93193cef43b8e.tar.gz
platform-system-core-147b355bb34cbd457a260c585be93193cef43b8e.tar.xz
platform-system-core-147b355bb34cbd457a260c585be93193cef43b8e.zip
Add a recovery DTBO section to boot image
For non-A/B devices, the recovery partition should be self-sufficient and not depend on any other partition. Since recovery may need access to devices added to the DT by overlays(for eg.display), we need to make sure that the the recovery image also contains the information from the DTBO image. The following fields are added to the boot image header for this purpose: -boot header version -header size -recovery dtbo size -recovery dtbo address Bug: 74763691 Test: unpack_bootimage --boot_img $OUT/recovery.img diff out/extracted_dtbo $TOP/device/google/wahoo-kernel/dtbo.img Change-Id: I1969859038b84fac1e4a71f79f2f546b9cacffc8
Diffstat (limited to 'mkbootimg')
-rw-r--r--mkbootimg/bootimg.h113
-rwxr-xr-xmkbootimg/mkbootimg18
2 files changed, 100 insertions, 31 deletions
diff --git a/mkbootimg/bootimg.h b/mkbootimg/bootimg.h
index 60834fed9..1be8c229c 100644
--- a/mkbootimg/bootimg.h
+++ b/mkbootimg/bootimg.h
@@ -20,16 +20,18 @@
20#ifndef _BOOT_IMAGE_H_ 20#ifndef _BOOT_IMAGE_H_
21#define _BOOT_IMAGE_H_ 21#define _BOOT_IMAGE_H_
22 22
23typedef struct boot_img_hdr boot_img_hdr;
24
25#define BOOT_MAGIC "ANDROID!" 23#define BOOT_MAGIC "ANDROID!"
26#define BOOT_MAGIC_SIZE 8 24#define BOOT_MAGIC_SIZE 8
27#define BOOT_NAME_SIZE 16 25#define BOOT_NAME_SIZE 16
28#define BOOT_ARGS_SIZE 512 26#define BOOT_ARGS_SIZE 512
29#define BOOT_EXTRA_ARGS_SIZE 1024 27#define BOOT_EXTRA_ARGS_SIZE 1024
30 28
31struct boot_img_hdr 29#define BOOT_HEADER_VERSION_ZERO 0
32{ 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 {
33 uint8_t magic[BOOT_MAGIC_SIZE]; 35 uint8_t magic[BOOT_MAGIC_SIZE];
34 36
35 uint32_t kernel_size; /* size in bytes */ 37 uint32_t kernel_size; /* size in bytes */
@@ -43,7 +45,10 @@ struct boot_img_hdr
43 45
44 uint32_t tags_addr; /* physical addr for kernel tags */ 46 uint32_t tags_addr; /* physical addr for kernel tags */
45 uint32_t page_size; /* flash page size we assume */ 47 uint32_t page_size; /* flash page size we assume */
46 uint32_t unused; /* reserved for future expansion: MUST be 0 */ 48 /*
49 * version for the boot image header.
50 */
51 uint32_t header_version;
47 52
48 /* operating system version and security patch level; for 53 /* operating system version and security patch level; for
49 * version "A.B.C" and patch level "Y-M-D": 54 * version "A.B.C" and patch level "Y-M-D":
@@ -64,31 +69,79 @@ struct boot_img_hdr
64} __attribute__((packed)); 69} __attribute__((packed));
65 70
66/* 71/*
67** +-----------------+ 72 * It is expected that callers would explicitly specify which version of the
68** | boot header | 1 page 73 * boot image header they need to use.
69** +-----------------+ 74 */
70** | kernel | n pages 75typedef struct boot_img_hdr_v0 boot_img_hdr;
71** +-----------------+ 76
72** | ramdisk | m pages 77/* When a boot header is of version BOOT_HEADER_VERSION_ZERO, the structure of boot image is as
73** +-----------------+ 78 * follows:
74** | second stage | o pages 79 *
75** +-----------------+ 80 * +-----------------+
76** 81 * | boot header | 1 page
77** n = (kernel_size + page_size - 1) / page_size 82 * +-----------------+
78** m = (ramdisk_size + page_size - 1) / page_size 83 * | kernel | n pages
79** o = (second_size + page_size - 1) / page_size 84 * +-----------------+
80** 85 * | ramdisk | m pages
81** 0. all entities are page_size aligned in flash 86 * +-----------------+
82** 1. kernel and ramdisk are required (size != 0) 87 * | second stage | o pages
83** 2. second is optional (second_size == 0 -> no second) 88 * +-----------------+
84** 3. load each element (kernel, ramdisk, second) at 89 *
85** the specified physical address (kernel_addr, etc) 90 * n = (kernel_size + page_size - 1) / page_size
86** 4. prepare tags at tag_addr. kernel_args[] is 91 * m = (ramdisk_size + page_size - 1) / page_size
87** appended to the kernel commandline in the tags. 92 * o = (second_size + page_size - 1) / page_size
88** 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr 93 *
89** 6. if second_size != 0: jump to second_addr 94 * 0. all entities are page_size aligned in flash
90** else: jump to kernel_addr 95 * 1. kernel and ramdisk are required (size != 0)
91*/ 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 */
110 uint64_t recovery_dtbo_offset; /* physical load addr */
111 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)
137 * 4. load each element (kernel, ramdisk, second, recovery_dtbo) at
138 * the specified physical address (kernel_addr, etc)
139 * 5. prepare tags at tag_addr. kernel_args[] is
140 * appended to the kernel commandline in the tags.
141 * 6. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
142 * 7. if second_size != 0: jump to second_addr
143 * else: jump to kernel_addr
144 */
92 145
93#if 0 146#if 0
94typedef struct ptentry ptentry; 147typedef struct ptentry ptentry;
diff --git a/mkbootimg/mkbootimg b/mkbootimg/mkbootimg
index 5a13da26b..ac20d0503 100755
--- a/mkbootimg/mkbootimg
+++ b/mkbootimg/mkbootimg
@@ -57,7 +57,7 @@ def write_header(args):
57 args.base + args.second_offset, # physical load addr 57 args.base + args.second_offset, # physical load addr
58 args.base + args.tags_offset, # physical addr for kernel tags 58 args.base + args.tags_offset, # physical addr for kernel tags
59 args.pagesize, # flash page size we assume 59 args.pagesize, # flash page size we assume
60 0, # future expansion: MUST be 0 60 args.header_version, # version of bootimage header
61 (args.os_version << 11) | args.os_patch_level)) # os version and patch level 61 (args.os_version << 11) | args.os_patch_level)) # os version and patch level
62 args.output.write(pack('16s', args.board.encode())) # asciiz product name 62 args.output.write(pack('16s', args.board.encode())) # asciiz product name
63 args.output.write(pack('512s', args.cmdline[:512].encode())) 63 args.output.write(pack('512s', args.cmdline[:512].encode()))
@@ -66,10 +66,20 @@ def write_header(args):
66 update_sha(sha, args.kernel) 66 update_sha(sha, args.kernel)
67 update_sha(sha, args.ramdisk) 67 update_sha(sha, args.ramdisk)
68 update_sha(sha, args.second) 68 update_sha(sha, args.second)
69
70 if args.header_version > 0:
71 update_sha(sha, args.recovery_dtbo)
72
69 img_id = pack('32s', sha.digest()) 73 img_id = pack('32s', sha.digest())
70 74
71 args.output.write(img_id) 75 args.output.write(img_id)
72 args.output.write(pack('1024s', args.cmdline[512:].encode())) 76 args.output.write(pack('1024s', args.cmdline[512:].encode()))
77
78 if args.header_version > 0:
79 args.output.write(pack('I', filesize(args.recovery_dtbo))) # size in bytes
80 args.output.write(pack('Q', args.base + args.recovery_dtbo_offset)) # physical load addr
81 args.output.write(pack('I', args.output.tell() + 4)) # size of boot header
82
73 pad_file(args.output, args.pagesize) 83 pad_file(args.output, args.pagesize)
74 return img_id 84 return img_id
75 85
@@ -132,6 +142,7 @@ def parse_cmdline():
132 required=True) 142 required=True)
133 parser.add_argument('--ramdisk', help='path to the ramdisk', type=FileType('rb')) 143 parser.add_argument('--ramdisk', help='path to the ramdisk', type=FileType('rb'))
134 parser.add_argument('--second', help='path to the 2nd bootloader', type=FileType('rb')) 144 parser.add_argument('--second', help='path to the 2nd bootloader', type=FileType('rb'))
145 parser.add_argument('--recovery_dtbo', help='path to the recovery DTBO', type=FileType('rb'))
135 parser.add_argument('--cmdline', help='extra arguments to be passed on the ' 146 parser.add_argument('--cmdline', help='extra arguments to be passed on the '
136 'kernel command line', default='', action=ValidateStrLenAction, maxlen=1536) 147 'kernel command line', default='', action=ValidateStrLenAction, maxlen=1536)
137 parser.add_argument('--base', help='base address', type=parse_int, default=0x10000000) 148 parser.add_argument('--base', help='base address', type=parse_int, default=0x10000000)
@@ -139,6 +150,8 @@ def parse_cmdline():
139 parser.add_argument('--ramdisk_offset', help='ramdisk offset', type=parse_int, default=0x01000000) 150 parser.add_argument('--ramdisk_offset', help='ramdisk offset', type=parse_int, default=0x01000000)
140 parser.add_argument('--second_offset', help='2nd bootloader offset', type=parse_int, 151 parser.add_argument('--second_offset', help='2nd bootloader offset', type=parse_int,
141 default=0x00f00000) 152 default=0x00f00000)
153 parser.add_argument('--recovery_dtbo_offset', help='recovery dtbo offset', type=parse_int,
154 default=0x0f000000)
142 parser.add_argument('--os_version', help='operating system version', type=parse_os_version, 155 parser.add_argument('--os_version', help='operating system version', type=parse_os_version,
143 default=0) 156 default=0)
144 parser.add_argument('--os_patch_level', help='operating system patch level', 157 parser.add_argument('--os_patch_level', help='operating system patch level',
@@ -150,6 +163,7 @@ def parse_cmdline():
150 choices=[2**i for i in range(11,15)], default=2048) 163 choices=[2**i for i in range(11,15)], default=2048)
151 parser.add_argument('--id', help='print the image ID on standard output', 164 parser.add_argument('--id', help='print the image ID on standard output',
152 action='store_true') 165 action='store_true')
166 parser.add_argument('--header_version', help='boot image header version', type=parse_int, default=0)
153 parser.add_argument('-o', '--output', help='output file name', type=FileType('wb'), 167 parser.add_argument('-o', '--output', help='output file name', type=FileType('wb'),
154 required=True) 168 required=True)
155 return parser.parse_args() 169 return parser.parse_args()
@@ -160,6 +174,8 @@ def write_data(args):
160 write_padded_file(args.output, args.ramdisk, args.pagesize) 174 write_padded_file(args.output, args.ramdisk, args.pagesize)
161 write_padded_file(args.output, args.second, args.pagesize) 175 write_padded_file(args.output, args.second, args.pagesize)
162 176
177 if args.header_version > 0:
178 write_padded_file(args.output, args.recovery_dtbo, args.pagesize)
163 179
164def main(): 180def main():
165 args = parse_cmdline() 181 args = parse_cmdline()