Skip to content
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

Merged
merged 41 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fbd7a57
WIP add file write to the fat32 fs
alloncm Sep 4, 2023
60246e9
Succesfully initing the fat32 driver caches
alloncm Sep 4, 2023
e0d01d4
Improve the fat32 file read performance.
alloncm Sep 4, 2023
c790a88
Trying to arrange all the fat handling
alloncm Sep 5, 2023
f812c76
Refactor all the fat handling
alloncm Sep 5, 2023
5184118
Add optimization comment
alloncm Sep 5, 2023
cc135f1
WIP
alloncm Sep 16, 2023
24530be
Finished the init of the fat table cacheI
alloncm Sep 16, 2023
88db99b
Still trying to implement writing file
alloncm Sep 17, 2023
8d81449
WIP writing files
alloncm Sep 17, 2023
eef0b3f
WIP - Still debugging
alloncm Sep 24, 2023
2ec9255
Writing and reading a file now working
alloncm Sep 24, 2023
3a42a10
Finish syncing all the other fats
alloncm Sep 24, 2023
809dc97
Trying to implement savefiles for rpibm
alloncm Sep 24, 2023
111f63b
Add the support for saves on baremetal
alloncm Sep 25, 2023
a30f2d7
Self CR clean code fixes
alloncm Sep 27, 2023
41aeb6a
WIP
alloncm Sep 30, 2023
d570013
The disk operations now works with any size buffer
alloncm Sep 30, 2023
ec8825e
The disk changes works now
alloncm Oct 3, 2023
22cc146
Refactor write root dir to use the new disk write
alloncm Oct 3, 2023
16c4bfd
For some reason this is working now
alloncm Oct 4, 2023
c735ef3
Extract FatBuffer to its own module
alloncm Oct 4, 2023
75cc2d4
Remove redundant logs
alloncm Oct 4, 2023
bd60b59
Merge branch 'master' into feature/baremetal_save
alloncm Dec 26, 2024
38e0517
Update bitfield-struct
alloncm Dec 26, 2024
3b9a507
Self cr fixes
alloncm Dec 26, 2024
40f9f2c
Add safety comments to main
alloncm Dec 27, 2024
f9ded37
Self CR fixes and add bm feature properly
alloncm Dec 27, 2024
78b9923
Continue to review fat_buffer
alloncm Dec 27, 2024
b4844f7
Some more refactors
alloncm Dec 28, 2024
69f08f8
Some refactors to fat_buffer
alloncm Dec 28, 2024
71f5ebb
Silent invalid reads logs (made them trace)
alloncm Dec 28, 2024
5180f41
This might fix
alloncm Dec 28, 2024
06c2f33
Try fix CI
alloncm Dec 31, 2024
4964f01
revert ci fix
alloncm Dec 31, 2024
d807e36
Update readme with more accurate instructions for instaltion of barem…
alloncm Jan 3, 2025
ebb9bae
More self cr fixes and comments
alloncm Jan 4, 2025
9bce96f
More fixes
alloncm Jan 4, 2025
f22222b
Merge branch 'feature/baremetal_save' of https://github.com/alloncm/M…
alloncm Jan 5, 2025
880a90e
Self cr fixes
alloncm Jan 5, 2025
49084d4
Remove those for now as they are for nightly 1.84
alloncm Jan 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rpi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
alloncm marked this conversation as resolved.
Show resolved Hide resolved
libc = {version = "0.2", optional = true}
nix = {version = "0.24", optional = true}
crossbeam-channel = {version = "0.5", optional = true}
Expand Down
2 changes: 1 addition & 1 deletion rpi/src/bin/baremetal/link.ld
Original file line number Diff line number Diff line change
@@ -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 = 0x200000; /* 2MB stack */
ENTRY(__rpi_32_phys_binary_load_addr) /* enry point */

SECTIONS
Expand Down
13 changes: 8 additions & 5 deletions rpi/src/bin/baremetal/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub extern "C" fn main()->!{
let mut power_manager = unsafe{PERIPHERALS.take_power()};

let mut fs = Fat32::new();
let mut content = b"alon hagever".clone();
fs.write_file("TEST TXT", &mut content);
let mut gfx = Ili9341GfxDevice::new(RESET_PIN_BCM, LED_PIN_BCM, TURBO, FRAME_LIMITER);
let mut pause_menu_gfx = gfx.clone();
let mut joypad_provider = GpioJoypadProvider::new(button_to_bcm_pin);
Expand Down Expand Up @@ -80,26 +82,27 @@ fn read_menu_options(fs: &mut Fat32, menu_options: &mut [MenuOption<FileEntry, S
let mut menu_options_size = 0;
let mut root_dir_offset = 0;
const FILES_PER_LIST:usize = 20;
'search_dir_loop: loop{
loop{
let dir_entries = fs.root_dir_list::<FILES_PER_LIST>(root_dir_offset);
for entry in dir_entries{
let Some(entry) = entry else {break 'search_dir_loop};
for entry in &dir_entries{
let extension = entry.get_extension();
if extension.eq_ignore_ascii_case("gb") || extension.eq_ignore_ascii_case("gbc"){
menu_options[menu_options_size] = MenuOption{ value: entry.clone(), prompt: StackString::from(entry.get_name()) };
menu_options_size += 1;
log::debug!("Detected ROM: {}", entry.get_name());
}
}
if dir_entries.remaining_capacity() != 0{
break;
}
root_dir_offset += FILES_PER_LIST;
}
return menu_options_size;
}

#[panic_handler]
fn panic(info:&PanicInfo)->!{
log::error!("An error has occoured!");
log::error!("{}", info);
log::error!("An error has occoured!: \r\n{}", info);

unsafe{boot::hang_led()};
}
28 changes: 20 additions & 8 deletions rpi/src/drivers/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,33 @@ impl Disk{
/// Returns the number of blocks the read operation fetched
/// The user knows how much of the buffer is filled
pub fn read(&mut self, block_index:u32, buffer:&mut [u8]) -> u32 {
alloncm marked this conversation as resolved.
Show resolved Hide resolved
let block_size = self.emmc.get_block_size();
let buffer_size = buffer.len();
if buffer_size % block_size as usize != 0{
core::panic!("buffer size must be a division of block size: {}", block_size);
}
self.emmc.seek((block_index * block_size) as u64);
self.prepare_for_disk_operation(block_index, buffer);
if !self.emmc.read(buffer){
core::panic!("Error while reading object of size: {}", buffer_size);
core::panic!("Error while reading object of size: {}", buffer.len());
}
return buffer.len() as u32 / self.get_block_size();
}

/// Returns the number of blocks the write operation modified
pub fn write(&mut self, block_index:u32, buffer:&mut [u8])->u32{
self.prepare_for_disk_operation(block_index, buffer);
if !self.emmc.write(buffer){
core::panic!("Error while writing object of size: {}", buffer.len());
}
return buffer_size as u32 / block_size;
return buffer.len() as u32 / self.get_block_size();
}

pub fn get_partition_first_sector_index(&self, partition_index:u8)->u32{
self.mbr.partitions[partition_index as usize].first_sector_index
}

pub fn get_block_size(&self)->u32{self.emmc.get_block_size()}

fn prepare_for_disk_operation(&mut self, block_index:u32, buffer:&[u8]){
let block_size = self.get_block_size();
if buffer.len() % block_size as usize != 0{
core::panic!("buffer size must be a division of block size: {}, actual buffer_size: {}", block_size, buffer.len());
}
self.emmc.seek((block_index * block_size) as u64);
}
}
Loading