summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Tolvanen2016-03-04 17:32:59 -0600
committerSami Tolvanen2016-03-07 10:56:01 -0600
commit3edc43234a0c0d592bc67b61f39c45eed238cef2 (patch)
tree3b66f1d9871aafe6d85ec475e1e31fa6bb55bd1f /mkbootimg
parent1cd680ce759effd33602de82197790fb027c1721 (diff)
downloadplatform-system-core-3edc43234a0c0d592bc67b61f39c45eed238cef2.tar.gz
platform-system-core-3edc43234a0c0d592bc67b61f39c45eed238cef2.tar.xz
platform-system-core-3edc43234a0c0d592bc67b61f39c45eed238cef2.zip
mkbootimg: add version and patch level
Adds operating system version and security patch level to the boot image header. This change takes over two existing unused fields to preserve compatibility with existing devices. Bug: 27498078 Bug: 22914603 Change-Id: I57682611e0c27fec5ed284da7d9a788383ff98b1
Diffstat (limited to 'mkbootimg')
-rw-r--r--mkbootimg/bootimg.h6
-rwxr-xr-xmkbootimg/mkbootimg24
2 files changed, 26 insertions, 4 deletions
diff --git a/mkbootimg/bootimg.h b/mkbootimg/bootimg.h
index 5ab619599..2bd823012 100644
--- a/mkbootimg/bootimg.h
+++ b/mkbootimg/bootimg.h
@@ -43,7 +43,11 @@ 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
47 /* operating system version; "1.2.34" -> 010234 */
48 uint32_t os_version;
49 /* operating system patch level; "2016-01-01" -> 20160101 */
50 uint32_t os_patch_level;
47 51
48 uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */ 52 uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */
49 53
diff --git a/mkbootimg/mkbootimg b/mkbootimg/mkbootimg
index f95d7039c..be342c9b5 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 args.os_version, # operating system version
61 args.os_patch_level)) # security 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,18 @@ 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 match_to_int(x):
103 if (x and x.lastindex == 3):
104 return (parse_int(x.group(3)) +
105 parse_int(x.group(2)) * 100 +
106 parse_int(x.group(1)) * 10000)
107 return 0
108
109def parse_os_version(x):
110 return match_to_int(re.search(r'^(\d+)\.(\d{1,2})\.(\d{1,2})', x))
111
112def parse_os_patch_level(x):
113 return match_to_int(re.search(r'^(\d{4,})-(\d{2})-(\d{2})', x))
100 114
101def parse_cmdline(): 115def parse_cmdline():
102 parser = ArgumentParser() 116 parser = ArgumentParser()
@@ -111,6 +125,10 @@ def parse_cmdline():
111 parser.add_argument('--ramdisk_offset', help='ramdisk offset', type=parse_int, default=0x01000000) 125 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, 126 parser.add_argument('--second_offset', help='2nd bootloader offset', type=parse_int,
113 default=0x00f00000) 127 default=0x00f00000)
128 parser.add_argument('--os_version', help='operating system version', type=parse_os_version,
129 default=0)
130 parser.add_argument('--os_patch_level', help='operating system patch level',
131 type=parse_os_patch_level, default=0)
114 parser.add_argument('--tags_offset', help='tags offset', type=parse_int, default=0x00000100) 132 parser.add_argument('--tags_offset', help='tags offset', type=parse_int, default=0x00000100)
115 parser.add_argument('--board', help='board name', default='', action=ValidateStrLenAction, 133 parser.add_argument('--board', help='board name', default='', action=ValidateStrLenAction,
116 maxlen=16) 134 maxlen=16)