-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfslflashgui
executable file
·136 lines (115 loc) · 4.77 KB
/
fslflashgui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/python3
import configparser
import os
import os.path
import sys
import zipfile
from PyQt5.QtCore import Qt, QThread, QDir, QIODevice, QTimer, QSettings, pyqtSignal
from PyQt5.QtGui import QCursor
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QProgressDialog, QMessageBox
from fsl import Ui_main_window
from fsl import flash
from fsl import flash_package
class FlashHandler(QThread):
status = pyqtSignal(str)
success = pyqtSignal()
def __init__(self, package, serial, parent=None):
QThread.__init__(self, parent)
self.package = package
self.serial = serial
def run(self):
if self.package:
flash_package(self.package, statusio=self)
if self.serial:
flash(serial=self.serial, statusio=self)
self.success.emit()
def write(self, text):
self.status.emit(text.rstrip())
def flush(self):
pass
class MainWindow(QMainWindow, Ui_main_window):
def __init__(self):
QMainWindow.__init__(self)
self.setupUi(self)
self.action_open.triggered.connect(self.open_package)
self.action_exit.triggered.connect(self.close)
self.flash_button.setEnabled(False)
self.flash_button.clicked.connect(self.do_flash)
self.program_button.clicked.connect(self.do_program)
self.flash_thread = None
self.flash_dialog = QMessageBox(self)
self.flash_dialog.setWindowModality(Qt.ApplicationModal)
self.flash_dialog.setWindowTitle('Updating Device...')
self.flash_dialog.setStandardButtons(QMessageBox.Cancel)
self.flash_dialog.setMinimumWidth(600)
self.package = None
def open_package(self):
DIR_KEY = 'default_dir'
settings = QSettings()
f, _ = QFileDialog.getOpenFileName(self, 'Open fslflash package file', settings.value('default_dir', type=str), '*.zip')
if len(f) == 0:
return
settings.setValue(DIR_KEY, os.path.dirname(f))
del settings
self.set_package(f)
def set_package(self, f):
self.package = f
self.flash_button.setEnabled(True)
with zipfile.ZipFile(self.package) as package:
with package.open('manifest.txt') as manifest:
for line in manifest:
entry = line.decode('UTF-8').rstrip()
(partition, filename) = entry.split(':')
if partition == 'bootstrap':
self.bootstrap_label.setText(filename)
elif partition == 'u-boot':
self.uboot_label.setText(filename)
elif partition == 'fdt':
self.fdt_label.setText(filename)
elif partition == 'kernel-image':
self.kernel_label.setText(filename)
elif partition == 'rootfs':
self.rootfs_label.setText(filename)
def do_flash(self):
self.flash_thread = FlashHandler(self.package, None, self)
self.flash_thread.status.connect(self.flash_status)
self.flash_thread.success.connect(self.flash_complete)
self.flash_dialog.buttonClicked.connect(self.flash_cancel)
self.flash_dialog.setText('Starting Flash')
self.flash_dialog.show()
self.flash_thread.start()
def do_program(self):
self.flash_thread = FlashHandler(None, self.serial_spinbox.value(), self)
self.flash_thread.status.connect(self.flash_status)
self.flash_thread.success.connect(self.program_complete)
self.flash_dialog.buttonClicked.connect(self.program_cancel)
self.flash_dialog.setText('Programming EEPROM')
self.flash_dialog.show()
self.flash_thread.start()
def flash_status(self, status):
self.flash_dialog.setText(status)
def flash_complete(self):
self.flash_dialog.accept()
self.statusbar.showMessage('Flash Success!')
def flash_cancel(self, button):
if self.flash_thread.isRunning():
self.flash_thread.terminate()
self.statusbar.showMessage('Flash Cancelled')
def program_complete(self):
self.flash_dialog.accept()
self.statusbar.showMessage('Program EEPROM Success!')
self.serial_spinbox.setValue(self.serial_spinbox.value() + 1)
def program_cancel(self, button):
if self.flash_thread.isRunning():
self.flash_thread.terminate()
self.statusbar.showMessage('Program EEPROM Cancelled')
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setApplicationName("fslflash")
app.setOrganizationName("DataSoft")
app.setOrganizationDomain("datasoft.com")
window = MainWindow()
window.show()
if len(sys.argv) > 1:
window.set_package(sys.argv[1])
sys.exit(app.exec_())