-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Files save on baremetal RPI #137
base: master
Are you sure you want to change the base?
Conversation
* Add root_dir cache and fat cache
Also increase the stack size to 2MB
* need to clear all the logs I used for debug * finish the write file impl
hope the little optimization I dd there is fast enough, cause I failed with the actual one
The file apears in root dir but is corrupted (at least in windows)
still need to update the backup FAT table
@@ -12,6 +12,7 @@ magenboy_common = {path = "../common"} | |||
log = "0.4" | |||
cfg-if = "1" | |||
bitfield-struct = "0.5" | |||
arrayvec = {version = "0.7", default-features = false} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why arrayvec
? consider also tinyvec
and smallvec
or heapless
to replace this and the StackString later on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arrayvec
is more popular then heapless
and the rest dont also offer a Stack String struct which Ill need in the near future
@@ -1,7 +1,7 @@ | |||
/* Place _start procedure at the entry address for RPI */ | |||
__rpi_32_phys_binary_load_addr = 0x8000; | |||
__isr_table_addr = 0; | |||
__stack_size = 0x100000; /* 1MB stack */ | |||
__stack_size = 0x300000; /* 3MB stack */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See if I can reduce this size (just for fun though 3MB ram is a lot on RPI's)
rpi/src/drivers/fat32.rs
Outdated
if let Some(existing_entry) = self.root_dir_cache.as_mut_slice().into_iter().find(|d|d.file_name == name && d.file_extension == extension){ | ||
if (existing_entry.size as usize) < content.len(){ | ||
existing_entry.file_name[0] = DELETED_DIR_ENTRY_PREFIX; | ||
// TODO: mark the fat entries as free |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to do this, think how to test this
Also fixed a bunch of typos thanks to a new vscode extension
rpi/src/drivers/mod.rs
Outdated
let buffer = &mut *core::ptr::slice_from_raw_parts_mut(t as *mut T as *mut _, core::mem::size_of::<T>()); | ||
return buffer; | ||
pub(self) fn as_mut_buffer<'a, T>(t:&'a mut T)->&'a mut [u8]{ | ||
unsafe {&mut *core::ptr::slice_from_raw_parts_mut(t as *mut T as *mut _, core::mem::size_of::<T>())} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add safety comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified that this is correct using Miri
} | ||
|
||
fn arrayvec_as_buffer<'a, T, const CAP:usize>(vec:&'a ArrayVec<T, CAP>)->&'a [u8]{ | ||
unsafe{core::slice::from_raw_parts(vec.as_ptr() as *const u8, vec.len() * core::mem::size_of::<T>())} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add safety comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified that this is correct using Miri
The fat buffer still must be aligned for sector size
463ba8c
to
c735ef3
Compare
|
||
#[derive(Clone, Debug)] | ||
pub(super) struct FatIndex{ | ||
sector_number:u32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to sector index
let buffer = &mut *core::ptr::slice_from_raw_parts_mut(t as *mut T as *mut _, core::mem::size_of::<T>()); | ||
return buffer; | ||
pub(crate) fn as_mut_buffer<'a, T>(t:&'a mut T)->&'a mut [u8]{ | ||
unsafe{&mut *core::ptr::slice_from_raw_parts_mut(t as *mut T as *mut _, core::mem::size_of::<T>())} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add safety comment
self.fat_internal_index.sector_offset += FAT_ENTRY_SIZE; | ||
if self.fat_internal_index.sector_offset >= SECTOR_SIZE{ | ||
self.fat_internal_index.sector_number += 1; | ||
self.fat_internal_index.sector_offset = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract those to another function
rpi/src/drivers/mod.rs
Outdated
let buffer = &mut *core::ptr::slice_from_raw_parts_mut(t as *mut T as *mut _, core::mem::size_of::<T>()); | ||
return buffer; | ||
pub(self) fn as_mut_buffer<'a, T>(t:&'a mut T)->&'a mut [u8]{ | ||
unsafe {&mut *core::ptr::slice_from_raw_parts_mut(t as *mut T as *mut _, core::mem::size_of::<T>())} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified that this is correct using Miri
} | ||
|
||
fn arrayvec_as_buffer<'a, T, const CAP:usize>(vec:&'a ArrayVec<T, CAP>)->&'a [u8]{ | ||
unsafe{core::slice::from_raw_parts(vec.as_ptr() as *const u8, vec.len() * core::mem::size_of::<T>())} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified that this is correct using Miri
pub enum FatSegmentState{ | ||
Free, | ||
Allocated, | ||
AllocatedEof, | ||
Reserved, | ||
Bad, | ||
} | ||
|
||
impl From<u32> for FatSegmentState{ | ||
fn from(value: u32) -> Self { | ||
match value{ | ||
0 => Self::Free, | ||
2..=0xFFF_FFF5 => Self::Allocated, | ||
0xFFF_FFFF => Self::AllocatedEof, | ||
0xFFF_FFF7 => Self::Bad, | ||
_ => Self::Reserved | ||
} | ||
} | ||
} | ||
|
||
impl FatSegmentState{ | ||
/// Checks whether a value should be part of this segment or not | ||
pub fn should_continue_segment(&self, other: &Self)->bool{ | ||
// AllocatedEof is should never continue segment | ||
// otherwise fallback to check raw values of the enum | ||
if *self == Self::AllocatedEof || *other == Self::AllocatedEof{ | ||
return false; | ||
} | ||
return self == other; | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct FatSegment{ | ||
pub state:FatSegmentState, | ||
pub len:u32, | ||
pub start_index:u32, | ||
} | ||
|
||
impl FatSegment{ | ||
pub fn new(value:u32, start_index:u32)->Self{ | ||
Self { state: value.into(), len: 1, start_index} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return this to the fat module
let mut root_dir_offset = 0; | ||
const FILES_PER_LIST:usize = 20; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the const to the start of the function
This will mark the save files option in #123