|
@@ -5,58 +5,86 @@ import os
|
|
|
import shutil
|
|
import shutil
|
|
|
import re
|
|
import re
|
|
|
import json
|
|
import json
|
|
|
-import zlib
|
|
|
|
|
|
|
+import csv
|
|
|
|
|
|
|
|
import argparse
|
|
import argparse
|
|
|
parser = argparse.ArgumentParser()
|
|
parser = argparse.ArgumentParser()
|
|
|
-parser.add_argument('target', type=str, help='the target of idf')
|
|
|
|
|
|
|
+parser.add_argument('config_json', type=str, help='the config_json of idf')
|
|
|
|
|
|
|
|
|
|
+# 打包路径
|
|
|
out_path = os.path.dirname(os.path.abspath(__file__))
|
|
out_path = os.path.dirname(os.path.abspath(__file__))
|
|
|
pack_path = os.path.join(out_path,"pack")
|
|
pack_path = os.path.join(out_path,"pack")
|
|
|
-
|
|
|
|
|
|
|
+# bin路径
|
|
|
bootloader_bin = os.path.join(out_path,"build","bootloader","bootloader.bin")
|
|
bootloader_bin = os.path.join(out_path,"build","bootloader","bootloader.bin")
|
|
|
partition_table_bin = os.path.join(out_path,"build","partition_table","partition-table.bin")
|
|
partition_table_bin = os.path.join(out_path,"build","partition_table","partition-table.bin")
|
|
|
luatos_bin = os.path.join(out_path,"build","luatos.bin")
|
|
luatos_bin = os.path.join(out_path,"build","luatos.bin")
|
|
|
|
|
+info_json = os.path.join(pack_path,"info.json")
|
|
|
|
|
+soc_download_exe = os.path.join(pack_path,"soc_download.exe")
|
|
|
|
|
|
|
|
if __name__=='__main__':
|
|
if __name__=='__main__':
|
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
|
- bsp = args.target.upper()
|
|
|
|
|
-
|
|
|
|
|
- fo = open(os.path.join(out_path,"include","luat_conf_bsp.h"), "r", encoding="UTF-8")
|
|
|
|
|
- for line in fo.readlines(): #依次读取每行
|
|
|
|
|
- find_data = re.findall(r'#define LUAT_BSP_VERSION "(.+?)"', line)#[0]
|
|
|
|
|
- if find_data:
|
|
|
|
|
- bsp_version = find_data[0]
|
|
|
|
|
- fo.close()# 关闭文件
|
|
|
|
|
- out_file="LuatOS-SoC_{}_{}".format(bsp_version, bsp)
|
|
|
|
|
-
|
|
|
|
|
- if os.path.exists(out_path+"\\"+out_file+'.soc'):
|
|
|
|
|
- os.remove(out_path+"\\"+out_file+'.soc')
|
|
|
|
|
- if os.path.exists(out_path+"\\"+out_file+'_USB.soc'):
|
|
|
|
|
- os.remove(out_path+"\\"+out_file+'_USB.soc')
|
|
|
|
|
-
|
|
|
|
|
- with open(pack_path + "/info.json", "rb") as f :
|
|
|
|
|
- fdata = f.read()
|
|
|
|
|
- with open(pack_path + "/info.json") as f :
|
|
|
|
|
- info_json = json.load(f)
|
|
|
|
|
|
|
+ config_json = args.config_json
|
|
|
|
|
|
|
|
- # 首先, 生成不带USB后缀的soc文件
|
|
|
|
|
- shutil.copy(bootloader_bin, pack_path+'/')
|
|
|
|
|
- shutil.copy(partition_table_bin, pack_path+'/')
|
|
|
|
|
- shutil.copy(luatos_bin, pack_path+'/')
|
|
|
|
|
|
|
+ with open(config_json) as f :
|
|
|
|
|
+ config_json_data = json.load(f)
|
|
|
|
|
+ bsp = config_json_data["IDF_TARGET"].upper()
|
|
|
|
|
+ partition_table_name = config_json_data["PARTITION_TABLE_FILENAME"]
|
|
|
|
|
+ partition_table_csv = os.path.join(out_path,partition_table_name)
|
|
|
|
|
+
|
|
|
|
|
+ with open(partition_table_csv) as f :
|
|
|
|
|
+ reader = csv.DictReader(f)
|
|
|
|
|
+ for row in reader:
|
|
|
|
|
+ if row['# Name']=="app0":
|
|
|
|
|
+ core_addr = row[' Offset']
|
|
|
|
|
+ elif row['# Name']=="script":
|
|
|
|
|
+ script_addr = row[' Offset']
|
|
|
|
|
+ elif row['# Name']=="spiffs":
|
|
|
|
|
+ fs_addr = row[' Offset']
|
|
|
|
|
+
|
|
|
|
|
+ with open(os.path.join(out_path,"include","luat_conf_bsp.h"), "r", encoding="UTF-8") as f :
|
|
|
|
|
+ for line in f.readlines(): #依次读取每行
|
|
|
|
|
+ find_data = re.findall(r'#define LUAT_BSP_VERSION "(.+?)"', line)#[0]
|
|
|
|
|
+ if find_data:
|
|
|
|
|
+ bsp_version = find_data[0]
|
|
|
|
|
+ out_file_name="LuatOS-SoC_{}_{}".format(bsp_version, bsp)
|
|
|
|
|
+ out_file = os.path.join(out_path,out_file_name)
|
|
|
|
|
+
|
|
|
|
|
+ temp = os.path.join(pack_path,"temp")
|
|
|
|
|
+ if os.path.exists(temp):
|
|
|
|
|
+ shutil.rmtree(temp)
|
|
|
|
|
+ os.mkdir(temp)
|
|
|
|
|
+ shutil.copy(bootloader_bin, temp)
|
|
|
|
|
+ shutil.copy(partition_table_bin, temp)
|
|
|
|
|
+ shutil.copy(luatos_bin, temp)
|
|
|
|
|
+ shutil.copy(info_json, temp)
|
|
|
|
|
+ shutil.copy(soc_download_exe, temp)
|
|
|
|
|
+ info_json_temp = os.path.join(temp,"info.json")
|
|
|
|
|
|
|
|
- shutil.make_archive(out_path+"\\"+out_file, 'zip', root_dir=pack_path)
|
|
|
|
|
- os.rename(out_path+"\\"+out_file+'.zip',out_path+"\\"+out_file+'.soc')
|
|
|
|
|
|
|
+ with open(info_json_temp, "r") as f :
|
|
|
|
|
+ info_json_data = json.load(f)
|
|
|
|
|
+ with open(info_json_temp, "w") as f :
|
|
|
|
|
+ info_json_data["download"]["core_addr"] = core_addr.replace("0x", "00")
|
|
|
|
|
+ info_json_data["download"]["script_addr"] = script_addr.replace("0x", "00")
|
|
|
|
|
+ info_json_data["download"]["fs_addr"] = fs_addr.replace("0x", "00")
|
|
|
|
|
+ json.dump(info_json_data, f)
|
|
|
|
|
+
|
|
|
|
|
+ if os.path.exists(out_file+'.soc'):
|
|
|
|
|
+ os.remove(out_file+'.soc')
|
|
|
|
|
+ if os.path.exists(out_file+'_USB.soc'):
|
|
|
|
|
+ os.remove(out_file+'_USB.soc')
|
|
|
|
|
|
|
|
|
|
+ # 首先, 生成不带USB后缀的soc文件
|
|
|
|
|
+ shutil.make_archive(out_file, 'zip', root_dir=temp)
|
|
|
|
|
+ os.rename(out_file+'.zip',out_file+'.soc')
|
|
|
|
|
+
|
|
|
# 然后生成USB版本的soc文件
|
|
# 然后生成USB版本的soc文件
|
|
|
- with open(pack_path + "/info.json", "w") as f :
|
|
|
|
|
- info_json["download"]["force_br"] = "0"
|
|
|
|
|
- json.dump(info_json, f)
|
|
|
|
|
- shutil.make_archive(out_path+"\\"+out_file, 'zip', root_dir=pack_path)
|
|
|
|
|
- os.rename(out_path+"\\"+out_file+'.zip',out_path+"\\"+out_file+'_USB.soc')
|
|
|
|
|
-
|
|
|
|
|
- # 还原info.json
|
|
|
|
|
- with open(pack_path + "/info.json", "wb") as f :
|
|
|
|
|
- f.write(fdata)
|
|
|
|
|
|
|
+ with open(info_json_temp, "w") as f :
|
|
|
|
|
+ info_json_data["download"]["force_br"] = "0"
|
|
|
|
|
+ json.dump(info_json_data, f)
|
|
|
|
|
+
|
|
|
|
|
+ shutil.make_archive(out_file, 'zip', root_dir=temp)
|
|
|
|
|
+ os.rename(out_file+'.zip',out_file+'_USB.soc')
|
|
|
|
|
|
|
|
- print('done', out_file)
|
|
|
|
|
|
|
+ shutil.rmtree(temp)
|
|
|
|
|
+
|
|
|
|
|
+ print(__file__,'done')
|