Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0a6b46e

Browse filesBrowse files
committed
Added file check to prevent erroneus upgrade
1 parent db83eb4 commit 0a6b46e
Copy full SHA for 0a6b46e

File tree

2 files changed

+2630
-19
lines changed
Filter options

2 files changed

+2630
-19
lines changed

‎libraries/SSU/extras/SSUBoot/SSUBoot.ino

Copy file name to clipboardExpand all lines: libraries/SSU/extras/SSUBoot/SSUBoot.ino
+23-19Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,31 @@ int main()
6969
MODEM.begin();
7070
fileUtils.begin();
7171
bool update_success = false;
72-
auto size = fileUtils.listFile(filename);
73-
auto cycles = (size / blockSize) + 1;
74-
if (size > SSU_SIZE) {
75-
size -= SSU_SIZE;
76-
77-
/* Erase the MCU flash */
78-
uint32_t flash_address = (uint32_t)SKETCH_START;
79-
mcu_flash.erase((void*)flash_address, size);
80-
81-
for (auto i = 0; i < cycles; i++) {
82-
uint8_t block[blockSize] { 0 };
83-
digitalWrite(LED_BUILTIN,LOW);
84-
auto read = fileUtils.readBlock(filename, (i * blockSize) + SSU_SIZE, blockSize, block);
85-
digitalWrite(LED_BUILTIN,HIGH);
86-
mcu_flash.write((void*)flash_address, block, read);
87-
flash_address += read;
72+
if (fileUtils.listFile("UPDATE.OK") == 1) {
73+
auto size = fileUtils.listFile(filename);
74+
auto cycles = (size / blockSize) + 1;
75+
if (size > SSU_SIZE) {
76+
size -= SSU_SIZE;
77+
78+
/* Erase the MCU flash */
79+
uint32_t flash_address = (uint32_t)SKETCH_START;
80+
mcu_flash.erase((void*)flash_address, size);
81+
82+
for (auto i = 0; i < cycles; i++) {
83+
uint8_t block[blockSize] { 0 };
84+
digitalWrite(LED_BUILTIN,LOW);
85+
auto read = fileUtils.readBlock(filename, (i * blockSize) + SSU_SIZE, blockSize, block);
86+
digitalWrite(LED_BUILTIN,HIGH);
87+
mcu_flash.write((void*)flash_address, block, read);
88+
flash_address += read;
89+
}
90+
update_success = true;
91+
}
92+
if (update_success) {
93+
fileUtils.deleteFile(filename);
94+
fileUtils.deleteFile("UPDATE.OK");
8895
}
89-
update_success = true;
9096
}
91-
if (update_success) { fileUtils.deleteFile(filename); }
92-
9397
/* Jump to the sketch */
9498
__set_MSP(*SKETCH_START);
9599

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.