101e04c3fSmrg#encoding=utf-8 201e04c3fSmrg# 301e04c3fSmrg# Copyright © 2017 Intel Corporation 401e04c3fSmrg# 501e04c3fSmrg# Permission is hereby granted, free of charge, to any person obtaining a 601e04c3fSmrg# copy of this software and associated documentation files (the "Software"), 701e04c3fSmrg# to deal in the Software without restriction, including without limitation 801e04c3fSmrg# the rights to use, copy, modify, merge, publish, distribute, sublicense, 901e04c3fSmrg# and/or sell copies of the Software, and to permit persons to whom the 1001e04c3fSmrg# Software is furnished to do so, subject to the following conditions: 1101e04c3fSmrg# 1201e04c3fSmrg# The above copyright notice and this permission notice (including the next 1301e04c3fSmrg# paragraph) shall be included in all copies or substantial portions of the 1401e04c3fSmrg# Software. 1501e04c3fSmrg# 1601e04c3fSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1701e04c3fSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1801e04c3fSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1901e04c3fSmrg# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2001e04c3fSmrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2101e04c3fSmrg# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 2201e04c3fSmrg# IN THE SOFTWARE. 2301e04c3fSmrg# 2401e04c3fSmrg 2501e04c3fSmrgimport sys 2601e04c3fSmrgimport zlib 277ec681f3Smrgimport xml.etree.ElementTree as et 2801e04c3fSmrg 2901e04c3fSmrgdef main(): 3001e04c3fSmrg if len(sys.argv) < 2: 3101e04c3fSmrg print("No input xml file specified") 3201e04c3fSmrg sys.exit(1) 3301e04c3fSmrg 3401e04c3fSmrg compress = zlib.compressobj() 3501e04c3fSmrg 3601e04c3fSmrg print("static const struct {") 377ec681f3Smrg print(" uint32_t ver_10;") 3801e04c3fSmrg print(" uint32_t offset;") 3901e04c3fSmrg print(" uint32_t length;") 4001e04c3fSmrg print("} genxml_files_table[] = {") 4101e04c3fSmrg 4201e04c3fSmrg xml_offset = 0 4301e04c3fSmrg compressed_data = b'' 4401e04c3fSmrg for i in range(1, len(sys.argv)): 4501e04c3fSmrg filename = sys.argv[i] 4601e04c3fSmrg xml = open(filename, "rb").read() 4701e04c3fSmrg xml_length = len(xml) 4801e04c3fSmrg root = et.fromstring(xml) 4901e04c3fSmrg 5001e04c3fSmrg print(" { %i, %i, %i }," % 5101e04c3fSmrg (int(float(root.attrib['gen']) * 10), xml_offset, xml_length)) 5201e04c3fSmrg 5301e04c3fSmrg compressed_data += compress.compress(xml) 5401e04c3fSmrg xml_offset += xml_length 5501e04c3fSmrg 5601e04c3fSmrg print("};") 5701e04c3fSmrg 5801e04c3fSmrg compressed_data += compress.flush() 5901e04c3fSmrg 6001e04c3fSmrg print("") 6101e04c3fSmrg print("static const uint8_t compress_genxmls[] = {") 6201e04c3fSmrg print(" ", end='') 6301e04c3fSmrg for i, c in enumerate(bytearray(compressed_data), start=1): 6401e04c3fSmrg print("0x%.2x, " % c, end='\n ' if not i % 12 else '') 6501e04c3fSmrg print('\n};') 6601e04c3fSmrg 6701e04c3fSmrg 6801e04c3fSmrgif __name__ == '__main__': 6901e04c3fSmrg main() 70