X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fbootloader%2Fbootloader.rs;h=d4a686b5ea83a290f16f4518f251c71a5f3fc03f;hb=ed56d89bbb0692755ed06f18d227d4d1e39e6b05;hp=cf4bca2926638a34be6be5572d9a3a241970f32c;hpb=e3c4f8ce159a91cd90b2d97e23c9a9c707ca1d5d;p=gps-watch.git diff --git a/src/bootloader/bootloader.rs b/src/bootloader/bootloader.rs index cf4bca2..d4a686b 100644 --- a/src/bootloader/bootloader.rs +++ b/src/bootloader/bootloader.rs @@ -46,6 +46,7 @@ enum Error { UnknownCommand = 1, InvalidArgument, ChecksumMismatch, + PermissionDenied, } extern { @@ -121,7 +122,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 +132,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 } } @@ -187,6 +192,11 @@ impl Bootloader { if sector > 0xff { Err(Error::InvalidArgument) + } else if sector == 0x01 { + // The second sector contains the flash configuration field, + // and keeping it in the erased state has the potential + // to brick the device. + Err(Error::PermissionDenied) } else { flash::erase(sector);