summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Tolvanen2016-03-14 11:08:59 -0500
committerSami Tolvanen2016-03-15 11:38:36 -0500
commitd162828814b08ada310846a33205befb69ef5799 (patch)
tree173cacb651d47e91d5e1fac200e029a9a1323adb /mkbootimg
parentff038574377f183f503362ed03468581ebfc2486 (diff)
downloadplatform-system-core-d162828814b08ada310846a33205befb69ef5799.tar.gz
platform-system-core-d162828814b08ada310846a33205befb69ef5799.tar.xz
platform-system-core-d162828814b08ada310846a33205befb69ef5799.zip
mkbootimg: add os_version
Adds operating system version and security patch level to the boot image header. This change take into use one of the existing unused fields to preserve compatibility. Note: All information is packed into a single field, because there are a lot of existing devices that break if the first unused field is set to a non-zero value. Bug: 27498078 Bug: 22914603 Change-Id: I24953129e06019b95014a050e916fe4f5c199286
Diffstat (limited to 'mkbootimg')
-rw-r--r--mkbootimg/bootimg.h9
-rwxr-xr-xmkbootimg/mkbootimg38
2 files changed, 43 insertions, 4 deletions
diff --git a/mkbootimg/bootimg.h b/mkbootimg/bootimg.h
index 5ab619599..60834fed9 100644
--- a/mkbootimg/bootimg.h
+++ b/mkbootimg/bootimg.h
@@ -43,7 +43,14 @@ struct boot_img_hdr
43 43
44 uint32_t tags_addr; /* physical addr for kernel tags */ 44 uint32_t tags_addr; /* physical addr for kernel tags */
45 uint32_t page_size; /* flash page size we assume */ 45 uint32_t page_size; /* flash page size we assume */
46 uint32_t unused[2]; /* future expansion: should be 0 */ 46 uint32_t unused; /* reserved for future expansion: MUST be 0 */
47
48 /* operating system version and security patch level; for
49 * version "A.B.C" and patch level "Y-M-D":
50 * ver = A << 14 | B << 7 | C (7 bits for each of A, B, C)
51 * lvl = ((Y - 2000) & 127) << 4 | M (7 bits for Y, 4 bits for M)
52 * os_version = ver << 11 | lvl */
53 uint32_t os_version;
47 54
48 uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */ 55 uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */
49 56
diff --git a/mkbootimg/mkbootimg b/mkbootimg/mkbootimg
index f95d7039c..7b04bcc7b 100755
--- a/mkbootimg/mkbootimg
+++ b/mkbootimg/mkbootimg
@@ -20,6 +20,7 @@ from os import fstat
20from struct import pack 20from struct import pack
21from hashlib import sha1 21from hashlib import sha1
22import sys 22import sys
23import re
23 24
24def filesize(f): 25def filesize(f):
25 if f is None: 26 if f is None:
@@ -47,7 +48,7 @@ def pad_file(f, padding):
47def write_header(args): 48def write_header(args):
48 BOOT_MAGIC = 'ANDROID!'.encode() 49 BOOT_MAGIC = 'ANDROID!'.encode()
49 args.output.write(pack('8s', BOOT_MAGIC)) 50 args.output.write(pack('8s', BOOT_MAGIC))
50 args.output.write(pack('8I', 51 args.output.write(pack('10I',
51 filesize(args.kernel), # size in bytes 52 filesize(args.kernel), # size in bytes
52 args.base + args.kernel_offset, # physical load addr 53 args.base + args.kernel_offset, # physical load addr
53 filesize(args.ramdisk), # size in bytes 54 filesize(args.ramdisk), # size in bytes
@@ -55,8 +56,9 @@ def write_header(args):
55 filesize(args.second), # size in bytes 56 filesize(args.second), # size in bytes
56 args.base + args.second_offset, # physical load addr 57 args.base + args.second_offset, # physical load addr
57 args.base + args.tags_offset, # physical addr for kernel tags 58 args.base + args.tags_offset, # physical addr for kernel tags
58 args.pagesize)) # flash page size we assume 59 args.pagesize, # flash page size we assume
59 args.output.write(pack('8x')) # future expansion: should be 0 60 0, # future expansion: MUST be 0
61 (args.os_version << 11) | args.os_patch_level)) # os version and patch level
60 args.output.write(pack('16s', args.board.encode())) # asciiz product name 62 args.output.write(pack('16s', args.board.encode())) # asciiz product name
61 args.output.write(pack('512s', args.cmdline[:512].encode())) 63 args.output.write(pack('512s', args.cmdline[:512].encode()))
62 64
@@ -97,6 +99,32 @@ def write_padded_file(f_out, f_in, padding):
97def parse_int(x): 99def parse_int(x):
98 return int(x, 0) 100 return int(x, 0)
99 101
102def parse_os_version(x):
103 match = re.search(r'^(\d{1,3})(?:\.(\d{1,3})(?:\.(\d{1,3}))?)?', x)
104 if match:
105 a = parse_int(match.group(1))
106 b = c = 0
107 if match.lastindex >= 2:
108 b = parse_int(match.group(2))
109 if match.lastindex == 3:
110 c = parse_int(match.group(3))
111 # 7 bits allocated for each field
112 assert a < 128
113 assert b < 128
114 assert c < 128
115 return (a << 14) | (b << 7) | c
116 return 0
117
118def parse_os_patch_level(x):
119 match = re.search(r'^(\d{4})-(\d{2})-(\d{2})', x)
120 if match:
121 y = parse_int(match.group(1)) - 2000
122 m = parse_int(match.group(2))
123 # 7 bits allocated for the year, 4 bits for the month
124 assert y >= 0 and y < 128
125 assert m > 0 and m <= 12
126 return (y << 4) | m
127 return 0
100 128
101def parse_cmdline(): 129def parse_cmdline():
102 parser = ArgumentParser() 130 parser = ArgumentParser()
@@ -111,6 +139,10 @@ def parse_cmdline():
111 parser.add_argument('--ramdisk_offset', help='ramdisk offset', type=parse_int, default=0x01000000) 139 parser.add_argument('--ramdisk_offset', help='ramdisk offset', type=parse_int, default=0x01000000)
112 parser.add_argument('--second_offset', help='2nd bootloader offset', type=parse_int, 140 parser.add_argument('--second_offset', help='2nd bootloader offset', type=parse_int,
113 default=0x00f00000) 141 default=0x00f00000)
142 parser.add_argument('--os_version', help='operating system version', type=parse_os_version,
143 default=0)
144 parser.add_argument('--os_patch_level', help='operating system patch level',
145 type=parse_os_patch_level, default=0)
114 parser.add_argument('--tags_offset', help='tags offset', type=parse_int, default=0x00000100) 146 parser.add_argument('--tags_offset', help='tags offset', type=parse_int, default=0x00000100)
115 parser.add_argument('--board', help='board name', default='', action=ValidateStrLenAction, 147 parser.add_argument('--board', help='board name', default='', action=ValidateStrLenAction,
116 maxlen=16) 148 maxlen=16)