diff options
author | Sami Tolvanen <samitolvanen@google.com> | 2016-03-14 09:08:59 -0700 |
---|---|---|
committer | Sami Tolvanen <samitolvanen@google.com> | 2016-03-15 09:38:36 -0700 |
commit | d162828814b08ada310846a33205befb69ef5799 (patch) | |
tree | 173cacb651d47e91d5e1fac200e029a9a1323adb /mkbootimg | |
parent | ff038574377f183f503362ed03468581ebfc2486 (diff) | |
download | system_core-d162828814b08ada310846a33205befb69ef5799.tar.gz system_core-d162828814b08ada310846a33205befb69ef5799.tar.bz2 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.h | 9 | ||||
-rwxr-xr-x | mkbootimg/mkbootimg | 38 |
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 uint32_t tags_addr; /* physical addr for kernel tags */ uint32_t page_size; /* flash page size we assume */ - uint32_t unused[2]; /* future expansion: should be 0 */ + uint32_t unused; /* reserved for future expansion: MUST be 0 */ + + /* operating system version and security patch level; for + * version "A.B.C" and patch level "Y-M-D": + * ver = A << 14 | B << 7 | C (7 bits for each of A, B, C) + * lvl = ((Y - 2000) & 127) << 4 | M (7 bits for Y, 4 bits for M) + * os_version = ver << 11 | lvl */ + uint32_t os_version; uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */ 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 from struct import pack from hashlib import sha1 import sys +import re def filesize(f): if f is None: @@ -47,7 +48,7 @@ def pad_file(f, padding): def write_header(args): BOOT_MAGIC = 'ANDROID!'.encode() args.output.write(pack('8s', BOOT_MAGIC)) - args.output.write(pack('8I', + args.output.write(pack('10I', filesize(args.kernel), # size in bytes args.base + args.kernel_offset, # physical load addr filesize(args.ramdisk), # size in bytes @@ -55,8 +56,9 @@ def write_header(args): filesize(args.second), # size in bytes args.base + args.second_offset, # physical load addr args.base + args.tags_offset, # physical addr for kernel tags - args.pagesize)) # flash page size we assume - args.output.write(pack('8x')) # future expansion: should be 0 + args.pagesize, # flash page size we assume + 0, # future expansion: MUST be 0 + (args.os_version << 11) | args.os_patch_level)) # os version and patch level args.output.write(pack('16s', args.board.encode())) # asciiz product name args.output.write(pack('512s', args.cmdline[:512].encode())) @@ -97,6 +99,32 @@ def write_padded_file(f_out, f_in, padding): def parse_int(x): return int(x, 0) +def parse_os_version(x): + match = re.search(r'^(\d{1,3})(?:\.(\d{1,3})(?:\.(\d{1,3}))?)?', x) + if match: + a = parse_int(match.group(1)) + b = c = 0 + if match.lastindex >= 2: + b = parse_int(match.group(2)) + if match.lastindex == 3: + c = parse_int(match.group(3)) + # 7 bits allocated for each field + assert a < 128 + assert b < 128 + assert c < 128 + return (a << 14) | (b << 7) | c + return 0 + +def parse_os_patch_level(x): + match = re.search(r'^(\d{4})-(\d{2})-(\d{2})', x) + if match: + y = parse_int(match.group(1)) - 2000 + m = parse_int(match.group(2)) + # 7 bits allocated for the year, 4 bits for the month + assert y >= 0 and y < 128 + assert m > 0 and m <= 12 + return (y << 4) | m + return 0 def parse_cmdline(): parser = ArgumentParser() @@ -111,6 +139,10 @@ def parse_cmdline(): parser.add_argument('--ramdisk_offset', help='ramdisk offset', type=parse_int, default=0x01000000) parser.add_argument('--second_offset', help='2nd bootloader offset', type=parse_int, default=0x00f00000) + parser.add_argument('--os_version', help='operating system version', type=parse_os_version, + default=0) + parser.add_argument('--os_patch_level', help='operating system patch level', + type=parse_os_patch_level, default=0) parser.add_argument('--tags_offset', help='tags offset', type=parse_int, default=0x00000100) parser.add_argument('--board', help='board name', default='', action=ValidateStrLenAction, maxlen=16) |