diff --git a/Cargo.lock b/Cargo.lock index a198265..7b84edc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,6 +94,7 @@ dependencies = [ "i2c-linux", "income", "nix 0.26.2", + "retry", ] [[package]] @@ -635,6 +636,12 @@ version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "767eb9f07d4a5ebcb39bbf2d452058a93c011373abf6832e24194a1c3f004794" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -669,6 +676,36 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.3.5" @@ -687,6 +724,15 @@ dependencies = [ "uninitialized", ] +[[package]] +name = "retry" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9166d72162de3575f950507683fac47e30f6f2c3836b71b7fbc61aa517c9c5f4" +dependencies = [ + "rand", +] + [[package]] name = "rustix" version = "0.37.20" diff --git a/Cargo.toml b/Cargo.toml index 1348492..5742722 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ howudoin = {version="0.1.*", features=["term-line"]} i2c-linux = "0.1.*" income = "0.1.*" nix = "0.26.*" +retry = "2.0.0" diff --git a/src/bin/sdcard.rs b/src/bin/sdcard.rs index 2a95197..152622d 100644 --- a/src/bin/sdcard.rs +++ b/src/bin/sdcard.rs @@ -13,6 +13,8 @@ use nix::errno::Errno; use nix::mount::{mount, MsFlags}; +use retry::{delay::Fixed, retry}; + use std::{ fs, io::{self, Read, Seek}, @@ -253,7 +255,6 @@ fn rtl8370mb_led_thread(rx: mpsc::Receiver<[bool; 4]>) { } } - /// This runs in a thread and manages the LED blinking. /// /// Send new blink patterns through the MPSC channel to change the active pattern. @@ -464,10 +465,16 @@ fn main() -> ! { let nand_ubi = MtdNand::open_named("ubi").unwrap_or_else(|e| init_error(e)); // Locate the rootfs and bootloader to be written - let mut rootfs = fs::File::open(ROOTFS_PATH).unwrap_or_else(|e| init_error(e.into())); + let mut rootfs = retry(Fixed::from_millis(100).take(10), || { + fs::File::open(ROOTFS_PATH) + }) + .unwrap_or_else(|e| init_error(e.into())); let rootfs_size = image::erofs_size(&mut rootfs).unwrap_or_else(|e| init_error(e)); - let mut bootloader = fs::File::open(BOOTLOADER_PATH).unwrap_or_else(|e| init_error(e.into())); + let mut bootloader = retry(Fixed::from_millis(100).take(10), || { + fs::File::open(BOOTLOADER_PATH) + }) + .unwrap_or_else(|e| init_error(e.into())); bootloader .seek(io::SeekFrom::Start(BOOTLOADER_OFFSET)) .unwrap_or_else(|e| init_error(e.into()));