[Bootloader] Enhance Global Stability

This commit is contained in:
Lisra-git
2023-04-07 23:58:28 +02:00
committed by Yaya-Cout
parent b4820d52e4
commit 0916996121
3 changed files with 61 additions and 53 deletions

View File

@@ -152,7 +152,10 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) {
* We do it before switching to USB application to redraw the battery
* pictogram. */
updateBatteryState();
if (switchTo(usbConnectedAppSnapshot())) {
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
// If we are in exam mode, we don't switch to usb connected app
didProcessEvent = true;
} else if (switchTo(usbConnectedAppSnapshot())) {
Ion::USB::DFU(true);
// Update LED when exiting DFU mode
Ion::LED::updateColorWithPlugAndCharge();

View File

@@ -72,7 +72,7 @@ public:
constexpr static const char * aboutMessage4 = "and select the OS";
constexpr static const char * aboutMessage5 = "to boot.";
constexpr static const char * bootloaderVersion = "Version 1.0.4 - FREED0M.20.4";
constexpr static const char * bootloaderVersion = "Version 1.0.5 - FREED0M.20.4";
//USB NAMES
constexpr static const char * usbUpsilonBootloader = "Upsilon Bootloader";

View File

@@ -41,48 +41,46 @@ size_t numberOfBitsAfterLeadingZeroes(int i) {
}
uint8_t SlotsExamMode::FetchSlotExamMode(const char * version, const char * Slot) {
// Get start and end from version and slot
uint32_t start = 0;
uint32_t end = 0;
// Get start and end from version and slot
uint32_t start = 0;
uint32_t end = 0;
if (Slot == "A") {
// If version under 16 get old addresses
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
start = getSlotAStartExamAddress(0);
// If version under 16 get old addresses
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
start = getSlotAStartExamAddress(0);
end = getSlotAEndExamAddress(0);
}
// Else get new addresses
else {
}
// Else get new addresses
else {
start = getSlotAStartExamAddress(1);
end = getSlotAEndExamAddress(1);
}
}
else if (Slot == "B") {
// If version under 16 get old
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
}
}
else if (Slot == "B") {
// If version under 16 get old
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
start = getSlotBStartExamAddress(0);
end = getSlotBEndExamAddress(0);
}
// Else get new
else {
}
// Else get new
else {
start = getSlotBStartExamAddress(1);
end = getSlotBEndExamAddress(1);
}
} else if (Slot == "Khi") {
end = getSlotBEndExamAddress(1);
}
} else if (Slot == "Khi") {
// We directly get the address of the Khi exam mode without checking the
// version, because on Khi, version is KhiCAS version, not the OS version
start = getSlotKhiStartExamAddress();
end = getSlotKhiEndExamAddress();
}
if (strcmp("15.9.0", version) >= 0) {
if (strcmp("15.9.0", version) >= 0) {
return examFetch15(start, end);
} else if (strcmp("16.9.0", version) > 0) {
return examFetch16(start, end);
}
else if (strcmp("19.0.0", version) > 0) {
} else if (strcmp("19.0.0", version) > 0) {
return examFetch1718(start, end);
}
else {
} else {
return examFetch19(start, end);
}
}
@@ -157,47 +155,54 @@ uint8_t SlotsExamMode::examFetch19(uint32_t start, uint32_t end) {
uint16_t* start16 = (uint16_t*)start;
uint16_t* end16 = (uint16_t*)end;
while (start16 + 1 <= end16 && *start16 != 0xFFFF) {
start16++;
for (uint16_t* i = end16 - 2; i > start16; i--) {
if (*i != 0xFFFF) {
uint8_t highByte = *i >> 8;
uint8_t lowByte = *i & 0xFF;
if (highByte > lowByte) {
return highByte;
}
else {
return lowByte;
}
}
}
return *(start16 - 1) >> 8;
}
uint32_t SlotsExamMode::getSlotAStartExamAddress(int ExamVersion) {
if (ExamVersion == 0) {
if (ExamVersion == 0) {
return SlotAExamModeBufferStartOldVersions;
}
else {
return SlotAExamModeBufferStartNewVersions;
}
}
else {
return SlotAExamModeBufferStartNewVersions;
}
}
uint32_t SlotsExamMode::getSlotAEndExamAddress(int ExamVersion) {
if (ExamVersion == 0) {
return SlotAExamModeBufferEndOldVersions;
}
else {
if (ExamVersion == 0) {
return SlotAExamModeBufferEndOldVersions;
}
else {
return SlotAExamModeBufferEndNewVersions;;
}
}
}
uint32_t SlotsExamMode::getSlotBStartExamAddress(int ExamVersion) {
if (ExamVersion == 0) {
return SlotBExamModeBufferStartOldVersions;
}
else {
return SlotBExamModeBufferStartNewVersions;
}
if (ExamVersion == 0) {
return SlotBExamModeBufferStartOldVersions;
}
else {
return SlotBExamModeBufferStartNewVersions;
}
}
uint32_t SlotsExamMode::getSlotBEndExamAddress(int ExamVersion) {
if (ExamVersion == 0) {
return SlotBExamModeBufferEndOldVersions;
}
else {
return SlotBExamModeBufferEndNewVersions;
}
if (ExamVersion == 0) {
return SlotBExamModeBufferEndOldVersions;
}
else {
return SlotBExamModeBufferEndNewVersions;
}
}
uint32_t SlotsExamMode::getSlotKhiStartExamAddress() {