system reset improvements (#21844)

* reset improvements

* cleanup

Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
Adeeb Shihadeh
2021-08-03 17:44:27 -07:00
committed by GitHub
parent 31a4b55218
commit 4f9e568019

View File

@@ -12,22 +12,22 @@
#define USERDATA "/dev/disk/by-partlabel/userdata"
void Reset::doReset() {
std::vector<const char*> cmds = {
"sudo umount " NVME " || true",
"yes | sudo mkfs.ext4 " NVME " || true",
"sudo umount " USERDATA " || true",
"yes | sudo mkfs.ext4 " USERDATA,
"sudo reboot",
};
// best effort to wipe nvme
std::system("sudo umount " NVME);
std::system("yes | sudo mkfs.ext4 " NVME);
for (auto &cmd : cmds) {
int ret = std::system(cmd);
if (ret != 0) {
body->setText("Reset failed. Reboot to try again.");
rebootBtn->show();
return;
}
// we handle two cases here
// * user-prompted factory reset
// * recovering from a corrupt userdata by formatting
int rm = std::system("sudo rm -rf /data/*");
std::system("sudo umount " USERDATA);
int fmt = std::system("yes | sudo mkfs.ext4 " USERDATA);
if (rm == 0 || fmt == 0) {
std::system("sudo reboot");
}
body->setText("Reset failed. Reboot to try again.");
rebootBtn->show();
}
void Reset::confirm() {