import os import sys import shutil import struct def update_file(path, list_value): content = bytes() for value in list_value: content = content + value if os.path.exists(path): file = open(path, mode='rb') content = content + file.read() file.close() file = open(os.path.dirname(path) + '/pack.app', mode='wb') file.write(content) file.close() else: print('Error: ' + path + ' is not exists.') def main(): root = os.path.dirname(os.path.realpath(__file__)) + '/../../..' path = root + '/PLAT/appsdk/gccout/speaker/speaker.bin' appAddress = 0x00B81000 headLength = 80 name = b'app0' + bytes(4) size = struct.pack('I', os.path.getsize(path)) reserved0 = bytes(4) reserved1 = bytes(16) textOffset = struct.pack('I', headLength) textSize = struct.pack('I', os.path.getsize(path)) textRelocation = struct.pack('I', appAddress + headLength) dataOffset = bytes(4) dataSize = bytes(4) dataRelocation = bytes(4) resourceOffset = bytes(4) resourceSize = bytes(4) resourceRelocation = bytes(4) reserved3 = bytes(12) list_value = [name, size, reserved0, reserved1, textOffset, textSize, textRelocation, dataOffset, dataSize, dataRelocation, resourceOffset, resourceSize, resourceRelocation, reserved3] update_file(path, list_value) if __name__ == '__main__': file_name = os.path.basename(__file__) print(file_name, 'begin') main() print(file_name, 'end')