From a55a6291a466a3d6dbe07fae68d1f158f6758701 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 18 Jun 2020 11:33:18 +0800 Subject: [PATCH] SD reader: optimized stack and binary size --- src/runtime/Cargo.toml | 4 ++-- src/runtime/src/sd_reader.rs | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/runtime/Cargo.toml b/src/runtime/Cargo.toml index e32ef42..e6c662b 100644 --- a/src/runtime/Cargo.toml +++ b/src/runtime/Cargo.toml @@ -14,7 +14,7 @@ num-traits = { version = "0.2", default-features = false } num-derive = "0.3" cslice = "0.3" log = "0.4" -core_io = { version = "0.1", features = ["alloc", "collections"] } +core_io = { version = "0.1", features = ["collections"] } byteorder = { version = "1.3", default-features = false } void = { version = "1", default-features = false } futures = { version = "0.3", default-features = false, features = ["async-await"] } @@ -24,4 +24,4 @@ libsupport_zynq = { git = "https://git.m-labs.hk/M-Labs/zc706.git" } libcortex_a9 = { git = "https://git.m-labs.hk/M-Labs/zc706.git" } libasync = { git = "https://git.m-labs.hk/M-Labs/zc706.git" } dyld = { path = "../libdyld" } -fatfs = { version = "0.3", features = ["core_io", "alloc"], default-features = false } +fatfs = { version = "0.3", features = ["core_io"], default-features = false } diff --git a/src/runtime/src/sd_reader.rs b/src/runtime/src/sd_reader.rs index add00a1..ace2fff 100644 --- a/src/runtime/src/sd_reader.rs +++ b/src/runtime/src/sd_reader.rs @@ -2,6 +2,7 @@ use core_io::{BufRead, Error, ErrorKind, Read, Result as IoResult, Seek, SeekFro use fatfs; use libboard_zynq::sdio::{sd_card::SdCard, CmdTransferError}; use log::debug; +use alloc::vec::Vec; fn cmd_error_to_io_error(_: CmdTransferError) -> Error { Error::new(ErrorKind::Other, "Command transfer error") @@ -19,7 +20,7 @@ pub struct SdReader { /// Internal SdCard handle. sd: SdCard, /// Read buffer with the size of 1 block. - buffer: [u8; BLOCK_SIZE], + buffer: Vec, /// Address for the next byte. byte_addr: u32, /// Internal index for the next byte. @@ -47,9 +48,13 @@ pub enum PartitionEntry { impl SdReader { /// Create SdReader from SdCard pub fn new(sd: SdCard) -> SdReader { + let mut vec: Vec = Vec::with_capacity(BLOCK_SIZE); + unsafe { + vec.set_len(vec.capacity()); + } SdReader { sd, - buffer: [0; BLOCK_SIZE], + buffer: vec, byte_addr: 0, index: BLOCK_SIZE, dirty: false,