Repository navigation
Expand file tree
/
Copy pathmainwindow.h
More file actions
235 lines (199 loc) · 6.19 KB
/
Copy pathmainwindow.h
File metadata and controls
235 lines (199 loc) · 6.19 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QProcess>
#include <QSettings>
#include <QTimer>
#include <QFile>
#include <QDir>
#include <QDateTime>
#include <QDebug>
#include <QVector>
#include <QPair>
#include <QTextCursor>
#include <QTextCharFormat>
#include "serialmonitor.h"
QT_BEGIN_NAMESPACE
class QLabel;
class QPushButton;
class QComboBox;
class QCheckBox;
class QTextEdit;
class QGroupBox;
class QProgressBar;
class QLineEdit;
class QTabWidget;
class QSpinBox;
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void onGenerateKey();
void onSelectKey();
void onSelectBootloader();
void onSelectPartition();
void onSelectFirmware();
void onFlash();
void onEraseFlash();
void onClearAll();
void onRefreshPorts();
void onReadFuseStatus();
void onBurnSecurityFuses();
void onPortDetected(const SimplePortInfo &port);
void onPortRemoved(const QString &portName);
void onProcessOutput();
void onProcessError();
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
void updateProgress();
void checkEncryptionStatus();
void updateFlashButton();
void onUpdateFlashButtonClicked();
void saveSettings();
void loadSettings();
void checkAndInstallDependencies();
void installEspressifTools();
private:
void setupUI();
void createConnections();
void setupAutoSave();
void populateBaudRates();
void updateStatus(const QString &status);
void enableControls(bool enable);
void appendLog(const QString &message, const QString &color = "");
QString sanitizeEspOutput(const QString &raw);
void runModuleCommand(const QString &module, const QStringList &args);
QString getPythonPath();
bool checkPythonAvailable();
bool checkModuleAvailable(const QString &module);
void parseChipInfo(const QString &output);
void parseFlashSize(const QString &output);
void parseEncryptionStatus(const QString &output);
void parseFuseStatus(const QString &output);
void executeNextCommand();
void performEncryptionSetup();
void handleEncryptionStepComplete();
void encryptFirmwareWithKey();
void encryptNextFile();
void flashWithEncryption();
void flashEncryptedFirmwareDirectly();
void flashWithoutEncryption();
void checkAndHandleKeyBurned();
void resetESP32();
void burnSecurityFuses();
void burnNextFuse();
QString formatOffset(quint32 offset);
QString getEncryptedFirmwarePath();
QString getEncryptedFilePath(const QString &originalPath, const QString &suffix);
QString ensureNoSpacePath(const QString &originalPath);
void cleanupEncryptedFile();
void cleanupTempDirectory();
void updateEncryptionStatusLabel(bool configured, const QString &details = "");
QString getFlashMode();
QString getFlashFreq();
QString getFlashSize();
// UI - Flash tab
QTabWidget *mainTabs;
QWidget *flashTab;
QWidget *fuseTab;
QWidget *aboutTab;
QComboBox *portComboBox;
QLabel *portStatusLabel;
QLabel *statusLabel;
QGroupBox *chipInfoGroup;
QLabel *chipModelLabel;
QLabel *chipRevisionLabel;
QLabel *chipCoresLabel;
QLabel *chipFeaturesLabel;
QLabel *chipMacLabel;
QLabel *flashSizeLabel;
QLabel *encryptionStatusLabel;
QPushButton *generateKeyBtn;
QPushButton *selectKeyBtn;
QLineEdit *keyFileEdit;
QPushButton *selectBootloaderBtn;
QPushButton *selectPartitionBtn;
QPushButton *selectFirmwareBtn;
QLineEdit *bootloaderFileEdit;
QLineEdit *partitionFileEdit;
QLineEdit *firmwareFileEdit;
QSpinBox *bootloaderOffsetSpin;
QSpinBox *partitionOffsetSpin;
QSpinBox *firmwareOffsetSpin;
QComboBox *baudRateComboBox;
QCheckBox *encryptFlashCheckBox;
QCheckBox *compressCheckBox;
QPushButton *flashBtn;
QPushButton *eraseFlashBtn;
QPushButton *clearAllBtn;
QProgressBar *progressBar;
QTextEdit *logTextEdit;
// UI - Fuse tab
QLabel *uartFuseStatus;
QLabel *jtagFuseStatus;
QLabel *dlEncryptStatus;
QLabel *dlDecryptStatus;
QLabel *cacheStatus;
QLabel *consoleDebugStatus;
QLabel *flashCryptCntStatus;
QLabel *flashCryptConfigStatus;
QPushButton *readFuseStatusBtn;
QGroupBox *fuseOptionsGroup;
QPushButton *burnSecurityFusesBtn;
QCheckBox *uartDownloadDisCheckBox;
QCheckBox *jtagDisableCheckBox;
QCheckBox *disableDlEncryptCheckBox;
QCheckBox *disableDlDecryptCheckBox;
QCheckBox *disableCacheCheckBox;
QCheckBox *consoleDebugDisableCheckBox;
// State
bool isFlashing;
bool isSettingLoaded;
bool isEncryptionConfigured;
bool encryptionSetupInProgress;
bool isCheckingEncryption;
bool isFirstEncryptionCheck;
bool isEncryptionDetectionParsed;
bool chipInfoReceived;
bool flashSizeReceived;
bool commandQueueRunning;
bool keyBurnSkipped;
bool isBurningFuses;
bool dependenciesChecked;
bool isFlashMode;
bool flashingEncryptedImages; // dedicated flag for encrypted flash detection
bool handlingKeyBurned; // guard against double-calling checkAndHandleKeyBurned()
bool pendingEncryptionSuccessDialog = false;
int fuseBurnIndex;
int flashRetryCount;
int encryptionStepIndex;
int commandQueueIndex;
static const int MAX_FLASH_RETRIES = 3;
QProcess *esptoolProcess;
SerialMonitor *serialMonitor;
QSettings *settings;
QTimer *encryptionCheckTimer;
QString currentPort;
QString selectedKeyPath;
QString selectedBootloaderPath;
QString selectedPartitionPath;
QString selectedFirmwarePath;
QString pendingModule;
QStringList pendingArgs;
QString processOutputBuffer;
QString pendingKeyPath;
QString encryptedFirmwarePath;
QString encryptedBootloaderPath;
QString encryptedPartitionPath;
QString pendingEncryptedSourcePath;
QString pendingEncryptedOutputPath;
QVector<QPair<QString, quint32>> encryptionFileQueue;
int encryptionFileIndex = 0;
QStringList commandQueue;
QStringList pendingEncryptionSteps;
QStringList fuseBurnQueue;
};
#endif // MAINWINDOW_H