mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-09-30 19:33:42 +08:00
add recover mode to factory resetter (#21492)
* recover mode * clean up * less margin * use inter * little nicer Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
@@ -2,82 +2,89 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QTimer>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
#include "selfdrive/ui/qt/qt_window.h"
|
#include "selfdrive/ui/qt/qt_window.h"
|
||||||
|
#include "selfdrive/ui/qt/setup/reset.h"
|
||||||
|
|
||||||
#define USERDATA "/dev/disk/by-partlabel/userdata"
|
|
||||||
#define NVME "/dev/nvme0n1"
|
#define NVME "/dev/nvme0n1"
|
||||||
|
#define USERDATA "/dev/disk/by-partlabel/userdata"
|
||||||
|
|
||||||
bool do_reset() {
|
void Reset::doReset() {
|
||||||
std::vector<const char*> cmds = {
|
std::vector<const char*> cmds = {
|
||||||
"sudo umount " NVME,
|
"sudo umount " NVME " || true",
|
||||||
"yes | sudo mkfs.ext4 " NVME,
|
"yes | sudo mkfs.ext4 " NVME " || true",
|
||||||
"sudo umount " USERDATA,
|
"sudo umount " USERDATA " || true",
|
||||||
"yes | sudo mkfs.ext4 " USERDATA,
|
"yes | sudo mkfs.ext4 " USERDATA,
|
||||||
"sudo reboot",
|
"sudo reboot",
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto &cmd : cmds) {
|
for (auto &cmd : cmds) {
|
||||||
int ret = std::system(cmd);
|
int ret = std::system(cmd);
|
||||||
if (ret != 0) return false;
|
if (ret != 0) {
|
||||||
|
body->setText("Reset failed. Reboot to try again.");
|
||||||
|
rebootBtn->show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
void Reset::confirm() {
|
||||||
QApplication a(argc, argv);
|
const QString confirm_txt = "Are you sure you want to reset your device?";
|
||||||
QWidget window;
|
if (body->text() != confirm_txt) {
|
||||||
setMainWindow(&window);
|
body->setText(confirm_txt);
|
||||||
|
} else {
|
||||||
|
body->setText("Resetting device...");
|
||||||
|
rejectBtn->hide();
|
||||||
|
rebootBtn->hide();
|
||||||
|
confirmBtn->hide();
|
||||||
|
#ifdef __aarch64__
|
||||||
|
QTimer::singleShot(100, this, &Reset::doReset);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QVBoxLayout *main_layout = new QVBoxLayout(&window);
|
Reset::Reset(bool recover, QWidget *parent) : QWidget(parent) {
|
||||||
main_layout->setContentsMargins(125, 125, 125, 125);
|
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||||
|
main_layout->setContentsMargins(100, 100, 100, 100);
|
||||||
|
|
||||||
QLabel *title = new QLabel("System Reset");
|
QLabel *title = new QLabel("System Reset");
|
||||||
title->setStyleSheet(R"(
|
title->setStyleSheet(R"(font-weight: 500; font-size: 100px;)");
|
||||||
font-weight: 500;
|
|
||||||
font-size: 100px;
|
|
||||||
)");
|
|
||||||
main_layout->addWidget(title, 0, Qt::AlignTop);
|
main_layout->addWidget(title, 0, Qt::AlignTop);
|
||||||
|
|
||||||
QLabel *body = new QLabel("System reset triggered. Press confirm to erase all content and settings. Press cancel to resume boot.");
|
body = new QLabel("System reset triggered. Press confirm to erase all content and settings. Press cancel to resume boot.");
|
||||||
body->setWordWrap(true);
|
body->setWordWrap(true);
|
||||||
body->setAlignment(Qt::AlignCenter);
|
body->setAlignment(Qt::AlignCenter);
|
||||||
body->setStyleSheet("font-size: 65px;");
|
body->setStyleSheet("font-size: 80px;");
|
||||||
main_layout->addWidget(body, 1, Qt::AlignCenter);
|
main_layout->addWidget(body, 1, Qt::AlignCenter);
|
||||||
|
|
||||||
QHBoxLayout *btn_layout = new QHBoxLayout();
|
QHBoxLayout *blayout = new QHBoxLayout();
|
||||||
|
main_layout->addLayout(blayout);
|
||||||
|
|
||||||
QPushButton *cancel_btn = new QPushButton("Cancel");
|
rejectBtn = new QPushButton("Cancel");
|
||||||
btn_layout->addWidget(cancel_btn, 0, Qt::AlignLeft);
|
blayout->addWidget(rejectBtn, 0, Qt::AlignLeft);
|
||||||
QObject::connect(cancel_btn, &QPushButton::released, &a, &QApplication::quit);
|
QObject::connect(rejectBtn, &QPushButton::released, QCoreApplication::instance(), &QCoreApplication::quit);
|
||||||
|
|
||||||
QPushButton *confirm_btn = new QPushButton("Confirm");
|
rebootBtn = new QPushButton("Reboot");
|
||||||
btn_layout->addWidget(confirm_btn, 0, Qt::AlignRight);
|
blayout->addWidget(rebootBtn, 0, Qt::AlignLeft);
|
||||||
QObject::connect(confirm_btn, &QPushButton::released, [=]() {
|
QObject::connect(rebootBtn, &QPushButton::released, [=]{
|
||||||
const QString confirm_txt = "Are you sure you want to reset your device?";
|
std::system("sudo reboot");
|
||||||
if (body->text() != confirm_txt) {
|
|
||||||
body->setText(confirm_txt);
|
|
||||||
} else {
|
|
||||||
body->setText("Resetting device...");
|
|
||||||
cancel_btn->hide();
|
|
||||||
confirm_btn->hide();
|
|
||||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
|
|
||||||
#ifdef __aarch64__
|
|
||||||
bool ret = do_reset();
|
|
||||||
if (!ret) {
|
|
||||||
body->setText("Reset failed.");
|
|
||||||
cancel_btn->show();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
main_layout->addLayout(btn_layout);
|
confirmBtn = new QPushButton("Confirm");
|
||||||
|
blayout->addWidget(confirmBtn, 0, Qt::AlignRight);
|
||||||
|
QObject::connect(confirmBtn, &QPushButton::released, this, &Reset::confirm);
|
||||||
|
|
||||||
window.setStyleSheet(R"(
|
rejectBtn->setVisible(!recover);
|
||||||
|
rebootBtn->setVisible(recover);
|
||||||
|
if (recover) {
|
||||||
|
body->setText("Unable to mount data partition. Press confirm to reset your device.");
|
||||||
|
}
|
||||||
|
|
||||||
|
setStyleSheet(R"(
|
||||||
* {
|
* {
|
||||||
|
font-family: Inter;
|
||||||
color: white;
|
color: white;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
}
|
}
|
||||||
@@ -90,6 +97,12 @@ int main(int argc, char *argv[]) {
|
|||||||
font-size: 50px;
|
font-size: 50px;
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
bool recover = argc > 1 && strcmp(argv[1], "--recover") == 0;
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
Reset reset(recover);
|
||||||
|
setMainWindow(&reset);
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#include <QLabel>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class Reset : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Reset(bool recover = false, QWidget *parent = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QLabel *body;
|
||||||
|
QPushButton *rejectBtn;
|
||||||
|
QPushButton *rebootBtn;
|
||||||
|
QPushButton *confirmBtn;
|
||||||
|
void doReset();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void confirm();
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user