From 2b1b0dc49fa80d3afeb90d4508ab90a2fbc79e45 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 18 Jun 2020 11:32:23 +0800 Subject: [PATCH] Load PL: simplify logic by using fatfs find_file directly. --- src/runtime/src/load_pl.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/runtime/src/load_pl.rs b/src/runtime/src/load_pl.rs index cdb47e1..d138b99 100644 --- a/src/runtime/src/load_pl.rs +++ b/src/runtime/src/load_pl.rs @@ -161,16 +161,11 @@ pub fn load_bitstream_from_sd() -> Result<(), PlLoadingError> { let fs = reader.mount_fatfs(sd_reader::PartitionEntry::Entry1)?; let root_dir = fs.root_dir(); - for entry in root_dir.iter() { - if let Ok(entry) = entry { - if entry.is_file() && entry.short_file_name() == "BOOT.BIN" { - info!("Found boot image!"); - return load_bitstream(&mut entry.to_file()); - } - } - } + let mut file = root_dir.open_file("/BOOT.BIN").map_err(|_| PlLoadingError::BootImageNotFound)?; + info!("Found boot image!"); + load_bitstream(&mut file) } else { - info!("SD card not inserted. Bitstream cannot be loaded.") + info!("SD card not inserted. Bitstream cannot be loaded."); + Err(PlLoadingError::BootImageNotFound) } - Err(PlLoadingError::BootImageNotFound) }