diff --git a/Makefile b/Makefile index 6fc35749..da59b4ff 100755 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ else OBJDUMP = xt-objdump endif -PYTHON?=python2 +PYTHON?=python BOOT?=none APP?=0 SPI_SPEED?=40 diff --git a/examples/gen_patch_bin/gen_bin.sh b/examples/gen_patch_bin/gen_bin.sh index 601e932d..86ac57af 100755 --- a/examples/gen_patch_bin/gen_bin.sh +++ b/examples/gen_patch_bin/gen_bin.sh @@ -20,7 +20,7 @@ xtensa-lx106-elf-objcopy --only-section .data -O binary eagle.app.v6.out eagle.a xtensa-lx106-elf-objcopy --only-section .rodata -O binary eagle.app.v6.out eagle.app.v6.rodata.bin xtensa-lx106-elf-objcopy --only-section .irom0.text -O binary eagle.app.v6.out eagle.app.v6.irom0text.bin -python2 ../../../../tools/gen_appbin_user.py eagle.app.v6.out 0 +python ../../../../tools/gen_appbin_user.py eagle.app.v6.out 0 cp eagle.app.v6.irom0text.bin ../../../../bin/ cp eagle.app.flash.bin ../../../../bin/eagle.app.v6.flash.bin diff --git a/examples/gen_patch_bin/gen_patch_bin.py b/examples/gen_patch_bin/gen_patch_bin.py index e2d0e251..2f63b9d0 100644 --- a/examples/gen_patch_bin/gen_patch_bin.py +++ b/examples/gen_patch_bin/gen_patch_bin.py @@ -1,5 +1,10 @@ +from __future__ import print_function + +import sys import os +PY3 = sys.version_info[0] == 3 + if os.path.exists("./patch_array.h"): os.remove("./patch_array.h") @@ -11,7 +16,13 @@ print("Run gen_bin.sh failed") exit(-1) -with open("bin/eagle.app.v6.flash.bin","r") as fd: +def get_byte_value(data_item): + if PY3: + return data_item + else: + return ord(data_item) + +with open("bin/eagle.app.v6.flash.bin","rb") as fd: with open("./patch_array.h","w+") as patch_fd: patch_fd.write("// This file is a patch for th25q16\r\n\r\n") patch_fd.write("#include \"os_type.h\"\r\n\r\n") @@ -21,16 +32,17 @@ Hex_Str = "" offset = 0 for i in range(0, len1,1): - Hex_Str += "0x"+(hex(ord(mystr[i])).replace('0x','').zfill(2)).upper()+ "," + byte_value = get_byte_value(mystr[i]) + Hex_Str += "0x{:02X},".format(byte_value) offset += 1 if offset == 16: - print Hex_Str + print(Hex_Str) patch_fd.write(" {}\r\n".format(Hex_Str)) Hex_Str = "" offset = 0 if Hex_Str != "": - print Hex_Str + print(Hex_Str) patch_fd.write(" {}\r\n".format(Hex_Str)) patch_fd.write("};\r\n") diff --git a/examples/gen_patch_bin/tools/gen_appbin_user.py b/examples/gen_patch_bin/tools/gen_appbin_user.py index 833bc90c..8e2bd10b 100755 --- a/examples/gen_patch_bin/tools/gen_appbin_user.py +++ b/examples/gen_patch_bin/tools/gen_appbin_user.py @@ -20,6 +20,8 @@ argv[1] is elf file name argv[2] is version num""" +from __future__ import print_function + import string import sys import os @@ -38,10 +40,11 @@ chk_sum = CHECKSUM_INIT blocks = 0 +PY3 = sys.version_info[0] == 3 def write_file(file_name,data): if file_name is None: - print 'file_name cannot be none\n' + print('file_name cannot be none\n') sys.exit(0) fp = open(file_name,'ab') @@ -51,53 +54,60 @@ def write_file(file_name,data): fp.write(data) fp.close() else: - print '%s write fail\n'%(file_name) + print('%s write fail\n'%(file_name)) def combine_bin(file_name,dest_file_name,start_offset_addr,need_chk): global chk_sum global blocks if dest_file_name is None: - print 'dest_file_name cannot be none\n' + print('dest_file_name cannot be none\n') sys.exit(0) if file_name: fp = open(file_name,'rb') if fp: - ########## write text ########## + ########## write text ########## fp.seek(0,os.SEEK_END) data_len = fp.tell() if data_len: - if need_chk: + if need_chk: tmp_len = (data_len + 3) & (~3) - else: - tmp_len = (data_len + 15) & (~15) + else: + tmp_len = (data_len + 15) & (~15) data_bin = struct.pack('> 8)+chr((all_bin_crc & 0x00FF0000) >> 16)+chr((all_bin_crc & 0xFF000000) >> 24)) + if PY3: + data = bytes([ + all_bin_crc & 0xFF, + (all_bin_crc >> 8) & 0xFF, + (all_bin_crc >> 16) & 0xFF, + (all_bin_crc >> 24) & 0xFF + ]) + else: + data = chr(all_bin_crc & 0xFF) + \ + chr((all_bin_crc >> 8) & 0xFF) + \ + chr((all_bin_crc >> 16) & 0xFF) + \ + chr((all_bin_crc >> 24) & 0xFF) + write_file(flash_bin_name,data) cmd = 'rm eagle.app.sym' os.system(cmd) diff --git a/tools/make_cacert.py b/tools/make_cacert.py index 221a3037..6fe5c53c 100644 --- a/tools/make_cacert.py +++ b/tools/make_cacert.py @@ -21,6 +21,8 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +from __future__ import print_function + import os @@ -50,7 +52,7 @@ def main(): for _file in file_list: if _file.endswith(".cer"): cert_file_list.append(_file) - print cert_file_list + print(cert_file_list) for cert_file in cert_file_list: with open(cert_file, 'rb') as f: buff = f.read()