日常分享 python 烧录 Xilinx BOOT BIN 方便小工具
... ...
·
# This Python file uses the following encoding: utf-8
#AUTHOR HONGDAYU
import sys
from PySide6.QtWidgets import QApplication, QWidget, QFileDialog, QMessageBox
from PySide6.QtCore import QThread, QDir
# Important:
# You need to run the following command to generate the ui_form.py file
# pyside6-uic form.ui -o ui_form.py, or
# pyside2-uic form.ui -o ui_form.py
from ui_form import Ui_Widget
import os
import subprocess
class DosThread(QThread):
def __init__(self):
super().__init__()
def run(self, execFUNC, args):
return execFUNC(args)
def quit(self) -> None:
return super().quit()
class Widget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_Widget()
self.ui.setupUi(self)
def upgrade(self):
self.ui.start.setDisabled(True)
self.__boot_bin = self.ui.BootBin.text()
self.__xilinx_vists_path = self.ui.VitisPath.text()
self.__use_burn_mode = self.ui.BurnMode.currentText()
self.__fsbl_path = self.ui.BootBin_2.text()
if self.__boot_bin == "" or self.__xilinx_vists_path == "" or self.__fsbl_path == "":
QMessageBox.information(self,
"error", "Inivald Args: Xilinx Vists Path or Boot bin is null or fsbl path is null ")
self.ui.start.setDisabled(False)
return None
self.__flash_offset = self.ui.SetOffset.text()
if self.__flash_offset != "" and self.__flash_offset.find("0x") == -1:
QMessageBox.information(self,
"error", "Inivald Args: flash offset must be hex number"
)
self.ui.start.setDisabled(False)
return None
if self.ui.SetOffset.text() == "":
self.__flash_offset = 0x0
cmd_type = "qspi-x4-single" if self.__use_burn_mode == "QSPI" else "emmc"
cmd_head = self.__xilinx_vists_path+"/bin/" + \
"program_flash -f " + self.__boot_bin + " -offset " + \
str(self.__flash_offset) + " -flash_type " + cmd_type + \
" -fsbl " + self.__fsbl_path
try:
# popen 不管是windows 还是 linux 都难用
# p = subprocess.Popen(cmd_head, shell=True, close_fds=True,
# bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# while True:
# res = p.stdout.readline()
# if not res:
# break
# self.ui.textBrowser.append(str(res, encoding='utf-8'))
# p.wait()
# self.ui.start.setDisabled(False)
QMessageBox.information(self, "open dos exec burn", cmd_head)
os.system("start cmd.exe /k " +
cmd_head + " && exit ")
QMessageBox.information(
self, "info", "close burn config tools,open terminal to burn firmware")
sys.exit(0)
except Exception as e:
# p.kill()
# p.wait()
QMessageBox.information(self, "err", "dos cmd open error")
self.ui.start.setDisabled(False)
def selpath(self):
self.__rootPath = QFileDialog(self, "Select Xilinx Vitis Path")
self.__rootPath.setDirectory(".\\")
self.__rootPath.setFileMode(QFileDialog.FileMode.Directory)
self.__rootPath.setOption(QFileDialog.ShowDirsOnly, True)
self.__rootPath.exec()
self.dir = self.__rootPath.selectedFiles()
self.ui.VitisPath.setText(str(self.dir[0]))
def selfile(self):
self.__rootPath = QFileDialog(self, "Select Burn File")
self.__rootPath.setDirectory(".\\")
self.__rootPath.setFileMode(QFileDialog.FileMode.AnyFile)
self.__rootPath.setOption(QFileDialog.ShowDirsOnly, True)
self.__rootPath.exec()
self.file = self.__rootPath.selectedFiles()
self.ui.BootBin.setText(str(self.file[0]))
def selfile_2(self):
self.__rootPath = QFileDialog(self, "Select Burn File")
self.__rootPath.setDirectory(".\\")
self.__rootPath.setFileMode(QFileDialog.FileMode.AnyFile)
self.__rootPath.setOption(QFileDialog.ShowDirsOnly, True)
self.__rootPath.exec()
self.file = self.__rootPath.selectedFiles()
self.ui.BootBin_2.setText(str(self.file[0]))
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = Widget()
widget.show()
sys.exit(app.exec())
Windows下 图形界面找路径方便快捷
这个工具临时写的,应该再加一个,烧录脚本自动生成
算了,我可以命令行的方式,太慢了,没有效率
更多推荐
所有评论(0)