Ai-Thinker-Open_RTL8710BX_A.../tools/asr5501/ota.py
2020-06-18 22:04:32 +08:00

18 lines
580 B
Python

import os
import sys
import struct
import shutil
workdir = os.path.dirname(os.path.abspath(sys.argv[0]))
if sys.platform == 'linux2':
xzpath = 'xz'
else:
xzpath = os.path.join(workdir, 'xz', 'osx/xz' if sys.platform == 'darwin' else 'win/xz.exe').replace('\\', '/')
rawfile = sys.argv[1]
rawsize = os.path.getsize(rawfile)
xzfile = rawfile.replace('.bin', '.bin.xz')
otafile = rawfile.replace('.bin', '.ota.bin')
os.system('%s --lzma2=dict=32KiB --check=crc32 -k %s' % (xzpath, rawfile))
open(xzfile, 'ab').write(struct.pack('<L', rawsize))
shutil.move(xzfile, otafile)