Skip to content

Commit cfe6002

Browse files
Lisra-gitM4xi1m3
authored andcommitted
[bootloader] Enhance Global Stability
1 parent 8da540b commit cfe6002

File tree

2 files changed

+50
-38
lines changed

2 files changed

+50
-38
lines changed

apps/apps_container.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) {
146146
* We do it before switching to USB application to redraw the battery
147147
* pictogram. */
148148
updateBatteryState();
149+
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
150+
//if in exam mode, do not switch to usb connected app
151+
return true;
152+
}
149153
if (switchTo(usbConnectedAppSnapshot())) {
150154
Ion::USB::DFU();
151155
// Update LED when exiting DFU mode

bootloader/slot_exam_mode.cpp

+46-38
Original file line numberDiff line numberDiff line change
@@ -89,47 +89,48 @@ uint32_t SlotsExamMode::getSlotBEndExamAddress(int ExamVersion) {
8989
}
9090

9191
uint8_t SlotsExamMode::FetchSlotExamMode(const char* version, const char* Slot) {
92-
//get start and end from version and slot
93-
uint32_t start = 0;
94-
uint32_t end = 0;
95-
if (Slot == "A") {
96-
//if version under 16 get Old
97-
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
98-
start = getSlotAStartExamAddress(0);
92+
//get start and end from version and slot
93+
uint32_t start = 0;
94+
uint32_t end = 0;
95+
if (Slot == "A") {
96+
//if version under 16 get Old
97+
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
98+
start = getSlotAStartExamAddress(0);
9999
end = getSlotAEndExamAddress(0);
100-
}
101-
//else get new
102-
else {
103-
start = getSlotAStartExamAddress(1);
104-
end = getSlotAEndExamAddress(1);
105-
}
106-
}
107-
else if (Slot == "B") {
108-
//if version under 16 get Old
109-
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
100+
}
101+
//else get new
102+
else {
103+
start = getSlotAStartExamAddress(1);
104+
end = getSlotAEndExamAddress(1);
105+
}
106+
}
107+
else if (Slot == "B") {
108+
//if version under 16 get Old
109+
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
110110
start = getSlotBStartExamAddress(0);
111111
end = getSlotBEndExamAddress(0);
112-
}
113-
//else get new
114-
else {
115-
start = getSlotBStartExamAddress(1);
116-
end = getSlotBEndExamAddress(1);
117-
}
118-
}
119-
120-
if (strcmp("15.9.0", version) >= 0) {
121-
return examFetch15(start, end);
122-
} else if (strcmp("16.9.0", version) > 0) {
123-
return examFetch16(start, end);
124-
}
125-
else if (strcmp("19.0.0", version) > 0) {
126-
return examFetch1718(start, end);
127112
}
113+
//else get new
128114
else {
129-
return examFetch19(start, end);
115+
start = getSlotBStartExamAddress(1);
116+
end = getSlotBEndExamAddress(1);
130117
}
131118
}
132119

120+
if (strcmp("15.9.0", version) >= 0) {
121+
return examFetch15(start, end);
122+
}
123+
else if (strcmp("16.9.0", version) > 0) {
124+
return examFetch16(start, end);
125+
}
126+
else if (strcmp("19.0.0", version) > 0) {
127+
return examFetch1718(start, end);
128+
}
129+
else {
130+
return examFetch19(start, end);
131+
}
132+
}
133+
133134
uint8_t SlotsExamMode::examFetch15(uint32_t start, uint32_t end) {
134135
uint32_t* persitence_start_32 = (uint32_t*)start;
135136
uint32_t* persitence_end_32 = (uint32_t*)end;
@@ -186,11 +187,18 @@ uint8_t SlotsExamMode::examFetch19(uint32_t start, uint32_t end) {
186187
uint16_t* start16 = (uint16_t*)start;
187188
uint16_t* end16 = (uint16_t*)end;
188189

189-
while (start16 + 1 <= end16 && *start16 != 0xFFFF) {
190-
start16++;
191-
}
192-
193-
return *(start16 - 1) >> 8;
190+
for (uint16_t* i = end16 - 2; i > start16; i--) {
191+
if (*i != 0xFFFF) {
192+
uint8_t highByte = *i >> 8;
193+
uint8_t lowByte = *i & 0xFF;
194+
if (highByte > lowByte) {
195+
return highByte;
196+
}
197+
else {
198+
return lowByte;
199+
}
200+
}
201+
}
194202
}
195203

196204

0 commit comments

Comments
 (0)