74 lines
2.6 KiB
Python
Executable File
74 lines
2.6 KiB
Python
Executable File
#
|
|
# Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
#
|
|
# This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
# be copied by any method or incorporated into another program without
|
|
# the express written consent of Aerospace C.Power. This Information or any portion
|
|
# thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
# is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
# liability for its use in any way and conveys no license or title under
|
|
# any patent or copyright and makes no representation or warranty that this
|
|
# Information is free from patent or copyright infringement.
|
|
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
len1 = 16384
|
|
len2 = 245760
|
|
split_len = 65536
|
|
|
|
def bin_to_hex(target1, target2):
|
|
with open("romcode_total.bin", 'wb') as tmpf:
|
|
# write romcode_total.bin use target1
|
|
with open(target1, 'rb') as sf1:
|
|
in_size = 0
|
|
b = sf1.read(4)
|
|
while b:
|
|
tmpf.write(b)
|
|
in_size = in_size + len(b)
|
|
b = sf1.read(4)
|
|
while in_size < len1:
|
|
tmpf.write(b'\0')
|
|
in_size = in_size + 1
|
|
|
|
# continue write romcode_total.bin use target2
|
|
with open(target2, 'rb') as sf2:
|
|
in_size = 0
|
|
b = sf2.read(4)
|
|
while b:
|
|
tmpf.write(b)
|
|
in_size = in_size + len(b)
|
|
b = sf2.read(4)
|
|
while in_size < len2:
|
|
tmpf.write(b'\0')
|
|
in_size = in_size + 1
|
|
tmpf.flush()
|
|
tmpf.close()
|
|
|
|
time.sleep(1)
|
|
# split romcode_total use split_len
|
|
with open("romcode_total.bin", 'rb') as out_total:
|
|
file_index = 1
|
|
b = out_total.read(4)
|
|
while b:
|
|
out_name = 'romcode' + str(file_index) + '.hex'
|
|
print("" + out_name)
|
|
with open(out_name, 'w') as outf:
|
|
in_size = 4
|
|
while in_size <= split_len and b:
|
|
outf.write('%02x%02x%02x%02x\n' % (b[3], b[2], b[1], b[0]))
|
|
in_size = in_size + 4
|
|
b = out_total.read(4)
|
|
while in_size <= split_len:
|
|
outf.write('%02x%02x%02x%02x\n' % (0, 0, 0, 0))
|
|
in_size = in_size + 4
|
|
outf.flush()
|
|
outf.close()
|
|
file_index = file_index + 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
bin_to_hex(sys.argv[1], sys.argv[2])
|
|
|