diff options
author | Chris Dearman <chris.dearman@imgtec.com> | 2016-01-13 15:32:29 -0800 |
---|---|---|
committer | Mohammed Habibulla <moch@google.com> | 2016-01-14 12:11:35 -0800 |
commit | bb1ae82b9e292cd5a222318472f380ebc69be77c (patch) | |
tree | 7820104ad28e82bcfac2a1b3b21708b8ca150696 | |
parent | e90548bdf0b4136ebc71f46b3207349ebf856dad (diff) | |
download | imagination-bb1ae82b9e292cd5a222318472f380ebc69be77c.tar.gz |
Add gpt.ini creation tool
BUG: 26562387
Change-Id: Idf71f0ab5255d5c4d8bb587eab4b596343bf8a8d
-rw-r--r-- | soc/common/tools/Android.mk | 17 | ||||
-rwxr-xr-x | soc/common/tools/gpt_ini2bin.py | 81 |
2 files changed, 98 insertions, 0 deletions
diff --git a/soc/common/tools/Android.mk b/soc/common/tools/Android.mk new file mode 100644 index 0000000..240887a --- /dev/null +++ b/soc/common/tools/Android.mk @@ -0,0 +1,17 @@ +ifneq ($(CREATORCI41_BOARD_GPT_INI),) + +LOCAL_PATH := $(call my-dir) +PRIVATE_TOOL_PATH := $(LOCAL_PATH)/gpt_ini2bin.py + +include $(CLEAR_VARS) + +LOCAL_MODULE := gpt.bin +LOCAL_MODULE_CLASS := ETC +LOCAL_MODULE_PATH := $(PRODUCT_OUT) + +include $(BUILD_SYSTEM)/base_rules.mk + +$(LOCAL_BUILT_MODULE): $(CREATORCI41_BOARD_GPT_INI) | $(PRIVATE_TOOL_PATH) + $(hide) $(PRIVATE_TOOL_PATH) $^ > $@ + +endif diff --git a/soc/common/tools/gpt_ini2bin.py b/soc/common/tools/gpt_ini2bin.py new file mode 100755 index 0000000..aba8d6d --- /dev/null +++ b/soc/common/tools/gpt_ini2bin.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python + +import ConfigParser +import uuid +import struct +import sys + +type_2_guid = { +# official guid for gpt partition type + 'fat' : 'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7', + 'esp' : 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b', + 'linux' : '0fc63daf-8483-4772-8e79-3d69d8477de4', + 'linux-swap' : '0657fd6d-a4ab-43c4-84e5-0933c84b4f4f', +# generated guid for android + 'boot' : '49a4d17f-93a3-45c1-a0de-f50b2ebe2599', + 'recovery' : '4177c722-9e92-4aab-8644-43502bfd5506', + 'misc' : 'ef32a33b-a409-486c-9141-9ffb711f6266', + 'metadata' : '20ac26be-20b7-11e3-84c5-6cfdb94711e9', + 'tertiary' : '767941d0-2085-11e3-ad3b-6cfdb94711e9', + 'factory' : '9fdaa6ef-4b3f-40d2-ba8d-bff16bfb887b' } + +def zero_pad(s, size): + if (len(s) > size): + print 'error', len(s) + s += '\0' * (size - len(s)) + return s + +def preparse_partitions(gpt_in, cfg): + with open(gpt_in, 'r') as f: + data = f.read() + + partitions = cfg.get('base', 'partitions').split() + + for l in data.split('\n'): + words = l.split() + if len(words) > 2: + if words[0] == 'partitions' and words[1] == '+=': + partitions += words[2:] + + return partitions + +def main(): + if len(sys.argv) != 2: + print 'Usage : ', sys.argv[0], 'gpt_in1.ini' + print ' write binary to stdout' + sys.exit(1) + + gpt_in = sys.argv[1] + + cfg = ConfigParser.SafeConfigParser() + + cfg.read(gpt_in) + + part = preparse_partitions(gpt_in, cfg) + + magic = 0x6a8b0da1 + start_lba = 0 + if cfg.has_option('base', 'start_lba'): + start_lba = cfg.getint('base', 'start_lba') + npart = len(part) + + out = sys.stdout + out.write(struct.pack('<I', magic)) + out.write(struct.pack('<I', start_lba)) + out.write(struct.pack('<I', npart)) + for p in part: + length = cfg.get('partition.' + p, 'len') + out.write(struct.pack('<i', int(length))) + + label = cfg.get('partition.' + p, 'label').encode('utf-16le') + out.write(zero_pad(label, 36 * 2)) + + guid_type = cfg.get('partition.' + p, 'type') + guid_type = uuid.UUID(type_2_guid[guid_type]) + out.write(guid_type.bytes_le) + + guid = uuid.UUID(cfg.get('partition.' + p, 'guid')) + out.write(guid.bytes_le) + +if __name__ == "__main__": + main() |