bootloader: Make run() function return a bool.
authorTilman Sauerbeck <tilman@code-monkey.de>
Sun, 7 Jul 2019 07:57:33 +0000 (09:57 +0200)
committerTilman Sauerbeck <tilman@code-monkey.de>
Sun, 5 Jan 2020 19:38:11 +0000 (20:38 +0100)
The return value indicates if the caller should continue to call
the function. It only returns false once COMMAND_START_APP is seen.

The idea is that after run() returns false, the we can jump to the
application code.

src/bootloader/bootloader.rs

index cf4bca2926638a34be6be5572d9a3a241970f32c..311b1a60e6a2ed491474eecf0d986c10d58d54a3 100644 (file)
@@ -121,7 +121,7 @@ impl Bootloader {
         }
     }
 
-    pub fn run(&mut self) {
+    pub fn run(&mut self) -> bool {
         if self.command_bytes < 4 {
             if let Some(b) = try_read_u8() {
                 self.command >>= 8;
@@ -131,10 +131,14 @@ impl Bootloader {
             }
         }
 
-        if self.command_bytes == 4 {
+        if self.command_bytes != 4 {
+            true
+        } else {
             self.command_bytes = 0;
 
             self.process_command();
+
+            self.command != COMMAND_START_APP
         }
     }