修改上传所有文件

This commit is contained in:
2025-10-21 19:40:27 +08:00
parent 5a84d13ae4
commit 391f81f8fc
8417 changed files with 2995282 additions and 0 deletions

View File

@@ -0,0 +1,286 @@
import sys
import os
import re
import subprocess, shlex
################################################## download ##################################################
def get_sdk_root_path_by_project_path(ProjectPath):
Pattern = r'(.*)/boards/'
SearchResult = re.search(Pattern, ProjectPath, re.S)
if SearchResult != None:
return SearchResult.group(1)
else:
print("Error: correct ssdk root path was not found")
sys.exit(1)
def add_double_quotes(Strings):
return '"' + Strings + '"'
def jlink_exe_file(FilePathName):
JlinkCmd = JlinkExe + add_double_quotes(FilePathName)
args = shlex.split(JlinkCmd)
# subprocess.run(args, check=True, stdout=subprocess.DEVNULL)
subprocess.run(args, check=True)
def download_file(File, Addr):
print("loadfile: %s %s" %(File, Addr))
CmdFilePathName = ProjectPath + "/cmd.txt"
LoadFileString = "LoadFile " + add_double_quotes(File) + " " + Addr + " noreset"
ExitString = "q"
with open(CmdFilePathName, "w") as f:
f.write("h" + "\n")
f.write(LoadFileString + "\n")
f.write(ExitString)
try:
jlink_exe_file(CmdFilePathName)
os.remove(CmdFilePathName)
except Exception as e:
os.remove(CmdFilePathName)
raise Exception("download error:\n %s" %e)
def get_download_info_by_project_file(ProjectPathName, FlashType):
with open(ProjectPathName, "r", encoding="utf-8") as f:
Content = f.read()
Pattern = r'(<configuration\s*Name="Download_{0}"(?:(?!<|hidden).)*/>)'.format(FlashType)
SearchResult = re.search(Pattern, Content, re.S)
if SearchResult != None:
return SearchResult.group(1)
else:
print("Error: no download info find")
sys.exit(1)
def get_multicore_download_info_by_project_file(ProjectPathName, FlashType, Part):
with open(ProjectPathName, "r", encoding="utf-8") as f:
Content = f.read()
Pattern = r'(<configuration\s*Name="(?:Download|Sign)_{0}_Multicore_{1}"(?:(?!<|hidden).)*/>)'.format(FlashType, Part)
SearchResultMulticore = re.search(Pattern, Content, re.S)
if SearchResultMulticore != None:
return SearchResultMulticore.group(1)
else:
return None
def get_str_from_download_info(DownloadInfo, FindString):
Pattern = FindString + r'="(.*?)"'
SearchResult = re.search(Pattern, DownloadInfo, re.S)
if SearchResult != None:
return SearchResult.group(1)
else:
return None
def is_sfs_file(FileName):
Pattern = r'sfs_.*'
SearchResult = re.search(Pattern, FileName, re.S)
if SearchResult != None:
return True
else:
return False
def is_need_sign(FileName):
if is_sfs_file(FileName) == True:
return False
elif FileName == "sf_signed.bin" or FileName == "sp0_signed.bin" or FileName == "sp1_signed.bin" or FileName == "sx0_signed.bin" or FileName == "sx1_signed.bin":
return True
elif FileName == "sf.bin" or FileName == "sp0.bin" or FileName == "sp1.bin" or FileName == "sx0.bin" or FileName == "sx1.bin":
return False
else:
print("Error: %s is error file name" %FileName)
sys.exit(1)
def is_need_download(FileName):
if is_sfs_file(FileName) == True:
return True
elif FileName == "sf_signed.bin" or FileName == "sf.bin" or FileName == "sp0.bin" or FileName == "sp1.bin" or FileName == "sx0.bin" or FileName == "sx1.bin":
return True
elif FileName == "sp0_signed.bin" or FileName == "sp1_signed.bin" or FileName == "sx0_signed.bin" or FileName == "sx1_signed.bin":
return False
else:
print("Error: %s is error file name" %FileName)
sys.exit(1)
def get_unsigned_bin_name(FileName):
DictTmp = {'sf_signed.bin':'sf.bin', 'sp0_signed.bin':'sp0.bin', 'sp1_signed.bin':'sp1.bin', 'sx0_signed.bin':'sx0.bin', 'sx1_signed.bin':'sx1.bin'}
return DictTmp.get(FileName)
def gen_info_from_download_info(DownloadInfo, FileString, AddrString):
if DownloadInfo == None:
return
FilePathName = get_str_from_download_info(DownloadInfo, FileString)
if FilePathName != None and FilePathName != "":
FilePathName = os.path.abspath(FilePathName.replace("$(ProjectDir)", ProjectPath)).replace('\\', '/')
FilePath = os.path.dirname(FilePathName)
FileName = os.path.basename(FilePathName)
if is_need_sign(FileName):
# 签名
UnsignedBinPathName = FilePath + "/" + get_unsigned_bin_name(FileName)
Addr = get_str_from_download_info(DownloadInfo, AddrString)
if Addr != None and Addr != "":
UnsignedBinAddr = Addr
SignInfoDict.update({UnsignedBinPathName:UnsignedBinAddr})
if is_need_download(FileName):
Addr = get_str_from_download_info(DownloadInfo, AddrString)
if Addr != None and Addr != "":
DownloadInfoDict.update({FilePathName:Addr})
def get_sign_and_download_info_by_project_file(ProjectPathName, FlashType, Part):
DownloadInfo = get_download_info_by_project_file(ProjectPathName, FlashType)
MulticoreDownloadInfo = get_multicore_download_info_by_project_file(ProjectPathName, FlashType, Part)
FileString = "debug_additional_load_file"
AddrStr = "debug_additional_load_file_address"
gen_info_from_download_info(DownloadInfo, FileString, AddrStr)
gen_info_from_download_info(MulticoreDownloadInfo, FileString, AddrStr)
FileString = "debug_additional_load_file1"
AddrStr = "debug_additional_load_file_address1"
gen_info_from_download_info(DownloadInfo, FileString, AddrStr)
gen_info_from_download_info(MulticoreDownloadInfo, FileString, AddrStr)
FileString = "debug_additional_load_file2"
AddrStr = "debug_additional_load_file_address2"
gen_info_from_download_info(DownloadInfo, FileString, AddrStr)
gen_info_from_download_info(MulticoreDownloadInfo, FileString, AddrStr)
FileString = "debug_additional_load_file3"
AddrStr = "debug_additional_load_file_address3"
gen_info_from_download_info(DownloadInfo, FileString, AddrStr)
gen_info_from_download_info(MulticoreDownloadInfo, FileString, AddrStr)
FileString = "external_build_file_name"
AddrStr = "external_load_address"
gen_info_from_download_info(DownloadInfo, FileString, AddrStr)
gen_info_from_download_info(MulticoreDownloadInfo, FileString, AddrStr)
def download_file_by_download_info(**DownloadInfoDict):
for key, value in DownloadInfoDict.items():
if not os.path.exists(key):
print("Error: %s does not exist" %key)
sys.exit(1)
download_file(key, value)
################################################## sign ##################################################
def get_core_by_pathname(FilePathName):
FileName = os.path.basename(FilePathName)
DictTmp = {'sf.bin':'0', 'sp0.bin':'2', 'sp1.bin':'3', 'sx0.bin':'4', 'sx1.bin':'5'}
return DictTmp.get(FileName)
def get_entry_by_pathname(FilePathName, PartId):
FileName = os.path.basename(FilePathName)
if PartId == "E3104" or PartId == "E3106" or PartId == "E3205" or PartId == "E3206":
DictTmp = {'sf.bin':'0x504000'}
elif PartId == "E3110" or PartId == "E3210" or PartId == "E3340" or PartId == "D3246" or PartId == "D3248":
DictTmp = {'sf.bin':'0x404000'}
elif PartId == "E3420":
DictTmp = {'sf.bin':'0x404000', 'sx0.bin':'0x500000', 'sx1.bin':'0x580000'}
elif PartId == "E3430":
DictTmp = {'sf.bin':'0x404000', 'sx0.bin':'0x600000', 'sx1.bin':'0x680000'}
elif PartId == "E3640" or PartId == "E3648":
DictTmp = {'sf.bin':'0x404000', 'sp0.bin':'0x700000', 'sp1.bin':'0x780000', 'sx0.bin':'0x600000', 'sx1.bin':'0x680000'}
else:
print("Error: %s does not exist" %PartId)
sys.exit(1)
if DictTmp.get(FileName) == None:
print("Error: %s does not exist" %FileName)
sys.exit(1)
return DictTmp.get(FileName)
def get_bpt_base_by_part(FlashType):
if FlashType == "HYPERFLASH":
return 0x100C0000
elif FlashType == "NORFLASH":
return 0x10007000
else:
print("Error: FlashType error")
sys.exit(1)
def get_dlp_by_addr(Addr, FlashType):
return int((int(Addr, 16) - get_bpt_base_by_part(FlashType)) / 512)
def get_iib_info_by_sign_info(**SignInfoDict):
global SignedBinPathName
IIBInfo = ""
for key, value in SignInfoDict.items():
if not os.path.exists(key):
print("Error: %s does not exist" %key)
sys.exit(1)
if os.path.basename(key) == "sf.bin":
SignedBinPathName = add_double_quotes(os.path.dirname(key) + "/sf_signed.bin")
IIBInfo += "--iib core=%s type=0x0 image=%s dlp=0x%x to=%s entry=%s\n" % (get_core_by_pathname(key), add_double_quotes(key), get_dlp_by_addr(value, FlashType), get_entry_by_pathname(key, Part), get_entry_by_pathname(key, Part))
return IIBInfo
def sign_file_by_sign_info(**SignInfoDict):
SecVer = 0
KeyName = "TestRSA2048_ossl.pem"
PSN = "0x100"
IIBInfo = get_iib_info_by_sign_info(**SignInfoDict)
ATB_SIGNER = "./sign_tool/windows/atb_signer.exe"
os.chdir(os.path.join(SdkRootPath, "tools", "sdtools"))
SignCmd = ATB_SIGNER + " sign --v 2 --sec_ver %s --dgst sha256 --rcp key=sign_tool/keys/%s\n%s--psn %s --of %s" %(SecVer, KeyName, IIBInfo, PSN, SignedBinPathName)
print("SignCmd: %s" %SignCmd)
print("sign file: %s" %SignedBinPathName)
try:
args = shlex.split(SignCmd)
# subprocess.run(args, check=True, stdout=subprocess.DEVNULL)
subprocess.run(args, check=True)
except Exception as e:
raise Exception("sign error:\n %s" %e)
################################################## main ##################################################
if __name__ == "__main__":
# 处理入参
JlinkPath = os.path.abspath(sys.argv[1]).replace('\\', '/')
ProjectPathName = os.path.abspath(sys.argv[2]).replace('\\', '/')
Part = sys.argv[3]
FlashType = sys.argv[4]
OperationType = sys.argv[5]
# 生成需要的变量
ProjectPath = os.path.dirname(ProjectPathName)
SdkRootPath = get_sdk_root_path_by_project_path(ProjectPath)
# 如果是ide进行签名后退出如果是cmd签名后继续下载
if OperationType == "$(OPS)":
OnlySignBin = True
elif OperationType == "download":
OnlySignBin = False
else:
print("Error: %s is unsupport operation type" %OperationType)
sys.exit(1)
SignInfoDict = {}
DownloadInfoDict = {}
get_sign_and_download_info_by_project_file(ProjectPathName, FlashType, Part)
print(SignInfoDict)
print(DownloadInfoDict)
if not SignInfoDict:
print("Error: no signed files info found")
sys.exit(1)
sign_file_by_sign_info(**SignInfoDict)
# 初始化TCM擦除Flash
if OnlySignBin == False:
if not DownloadInfoDict:
print("Error: no download files info found")
sys.exit(1)
DeviceName = Part + "_" + FlashType
JlinkPathName = add_double_quotes(JlinkPath + '/JLink.exe')
JlinkExe = JlinkPathName + " -device " + DeviceName + " -if SWD -speed 4000 -autoconnect 1 -CommandFile "
if FlashType == "HYPERFLASH":
InitFilePathName = os.path.join(SdkRootPath, "devices", Part, "flashloader", "init_before_download_hyperflash.txt").replace('\\', '/')
elif FlashType == "NORFLASH":
InitFilePathName = os.path.join(SdkRootPath, "devices", Part, "flashloader", "init_before_download_norflash.txt").replace('\\', '/')
else:
print("Error: %s is not right type" %FlashType)
sys.exit(1)
print("init tcm and erase flash: %s" %InitFilePathName)
try:
jlink_exe_file(InitFilePathName)
except Exception as e:
raise Exception("download error:\n %s" %e)
download_file_by_download_info(**DownloadInfoDict)

View File

@@ -0,0 +1,12 @@
function init_before_download(cmd_file_path_name)
{
// TargetInterface.message(cmd_file_path_name)
var JLinkDir = TargetInterface.expandMacro("$(JLinkDir)");
var DeviceName = TargetInterface.expandMacro("$(DeviceName)");
var JLinkDir2 = JLinkDir.replace('\\', '/');
// TargetInterface.message(JLinkDir2);
var cmd = '"' + JLinkDir2 + "/JLink.exe" + '"' + " -device " + DeviceName + " -if SWD -speed 4000 -autoconnect 1 -CommandFile " + '"' + cmd_file_path_name + '"';
// TargetInterface.resetAndStop()
// TargetInterface.delay(1000)
CWSys.run(cmd, true);
}

View File

@@ -0,0 +1,104 @@
一、SES FlashDebug模式使用方法
1. 添加SemiDrive devices。
在JLink AppData目录下常见为C:\Users\Administrator\AppData\Roaming\SEGGER添加SemiDrive devices。
具体方法为将ssdk\prebuilts\JLinkDevices目录拷贝到Link AppData目录下的SEGGER文件夹内。
其中包含JLinkDevices.xml文件和Devices\SemiDrive文件夹所有芯片Part的Flashloader。
2. 将Devices信息拷贝到Jlink安装目录Jlink版本大于V7.62不需要这一步)。
如果Jlink版本低于V7.62可以在Windows开始菜单栏搜索Jlink查看还需要额外再将Devices信息拷贝到Jlink安装目录。
先将ssdk_dev\prebuilts\JLinkDevices\Devices\SemiDrive目录拷贝到Jlink安装目录下的Devices文件夹内如C:\Program Files\SEGGER\JLink\Devices
再将ssdk_dev\prebuilts\JLinkDevices\JLinkDevices.xml文件替换Jlink安装目录原有的JLinkDevices.xml文件建议先将原文件备份再替换
3. 重新打开SES工程如在完成第1步之前先打开了SES工程需要关闭后重新打开工程
4. 编译FlashDebug模式工程xip需要先编译bootloader工程再编译app工程的Debug或FlashDebug模式
编译完成后会在SES\Output\FlashDebug\Exe目录中自动生成签名bin文件如sf_signed.bin。
5. 在SES IDE中点击Target——Download xxx。
IDE调用Flashloader完成flash文件下载。
二、FlashDebug模式的配置包含如下内容已默认添加到工程中
1.post-build
"$(ProjectDir)/../../../../../prebuilts/windows/python-3.7.0/python.exe" "$(ProjectDir)/../../../../../devices/script/SES/cmd_download.py" "$(JLinkDir)" "$(SolutionPath)" "$(PART_ID)" "HYPERFLASH" "$(OPS)"
或者
"$(ProjectDir)/../../../../../prebuilts/windows/python-3.7.0/python.exe" "$(ProjectDir)/../../../../../devices/script/SES/cmd_download.py" "$(JLinkDir)" "$(SolutionPath)" "$(PART_ID)" "NORFLASH" "$(OPS)"
2.Target Script
Reset Script:
init_before_download("$(ProjectDir)/../../../../../devices/$(PART_ID)/flashloader/init_before_download_hyperflash.txt")
或者
init_before_download("$(ProjectDir)/../../../../../devices/$(PART_ID)/flashloader/init_before_download_norflash.txt")
Target Script File:
$(ProjectDir)/../../../../../devices/script/SES/init_before_download.js
3.loader
driver类:
所有工程
debug
无需配置
FlashDebug:
Download_HYPERFLASH(Download_NORFLASH):
$(ProjectDir)/Output/FlashDebug/Exe/sf_signed.bin - 0x100C0000(0x10007000)
$(ProjectDir)/../../../../../tools/sdtools/sfs/sfs_s26h-hyperflash.bin - 0x10000000
xip类:签名bootloader所有核的app不签名
bootloader工程
debug
无需配置
FlashDebug:
不支持
sf工程中
debug
配置device name
配置init_before_download
init_before_download("$(ProjectDir)/../../../../../../devices/$(PART_ID)/flashloader/init_before_download.txt")
$(ProjectDir)/../../../../../../devices/script/SES/init_before_download.js
FlashDebug:
Download_HYPERFLASH(Download_NORFLASH):
$(ProjectDir)/../../bootloader/SES/Output/Debug/Exe/sf_signed.bin - 0x100C0000(0x10007000)
$(ProjectDir)/../../../../../../tools/sdtools/sfs/sfs_s26h-hyperflash.bin - 0x10000000
$(ProjectDir)/Output/FlashDebug/Exe/sf.bin - 0x10140000
Download_HYPERFLASH_Multicore(Download_NORFLASH_Multicore):
$(ProjectDir)/../../sp0/SES/Output/FlashDebug/Exe/sp0.bin - 0x10340000(0x10288000)
$(ProjectDir)/../../sp1/SES/Output/FlashDebug/Exe/sp1.bin - 0x103C0000(0x10308000)
$(ProjectDir)/../../sx0/SES/Output/FlashDebug/Exe/sx0.bin - 0x10440000(0x10388000)
$(ProjectDir)/../../sx1/SES/Output/FlashDebug/Exe/sx1.bin - 0x104C0000(0x10408000)
sp/sx工程中
debug:
配置device name
FlashDebug:
Download_HYPERFLASH(Download_NORFLASH):
$(ProjectDir)Output/FlashDebug/Exe/sp0.bin - 0x10340000(0x10288000)
$(ProjectDir)Output/FlashDebug/Exe/sp1.bin - 0x103C0000(0x10308000)
$(ProjectDir)Output/FlashDebug/Exe/sx0.bin - 0x10440000(0x10388000)
$(ProjectDir)Output/FlashDebug/Exe/sx1.bin - 0x104C0000(0x10408000)
多核类:(所有核都签名)
sf工程中
debug
无需配置
FlashDebug:
Download_HYPERFLASH(Download_NORFLASH):
$(ProjectDir)/Output/FlashDebug/Exe/sf_signed.bin - 0x100C0000(0x10007000)
$(ProjectDir)/../../../../../../tools/sdtools/sfs/sfs_s26h-hyperflash.bin - 0x10000000
Download_HYPERFLASH_Multicore(Download_NORFLASH_Multicore):
$(ProjectDir)/../../sp0/SES/Output/FlashDebug/Exe/sp0_signed.bin - 0x10340000(0x10288000)
$(ProjectDir)/../../sp1/SES/Output/FlashDebug/Exe/sp1_signed.bin - 0x103C0000(0x10308000)
$(ProjectDir)/../../sx0/SES/Output/FlashDebug/Exe/sx0_signed.bin - 0x10440000(0x10388000)
$(ProjectDir)/../../sx1/SES/Output/FlashDebug/Exe/sx1_signed.bin - 0x104C0000(0x10408000)
sp/sx工程中
debug
无需配置
FlashDebug:
不支持
4.target device
$(PART_ID)_HYPERFLASH/$(PART_ID)_NORFLASH
注意: norflash和hyperflash下载地址和sfs类型不同
三、命令行下载:
1. 条件:
安装SEGEER Embeded Studio时请在安装对话框Additional Component中确认勾选Install Little Endian Library Files默认已勾选
2. 下载命令:
例:
"D:\Program Files\SEGGER\SEGGER Embedded Studio for ARM 7.10a\bin\emBuild" -config "FlashDebug" -D OPS=download -project "sf" "E:\WSL\git_repo\E3_DEV\boards\e3_gateway\driver_demo\acmp\SES\acmp.emProject"
"D:\Program Files\SEGGER\SEGGER Embedded Studio for ARM 7.10a\bin\emBuild" -config "FlashDebug" -D OPS=download -project "sf" "E:\WSL\git_repo\E3_DEV\boards\e3_gateway\app_demo\xip\sf\SES\sf.emProject"