mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add block erase routine
This commit is contained in:
parent
19455d1bc0
commit
1810825744
4 changed files with 58 additions and 12 deletions
|
|
@ -30,16 +30,11 @@ utralib = { version = "0.1.25", optional = true, default-features = false }
|
||||||
[target.'cfg(any(windows,unix))'.dependencies]
|
[target.'cfg(any(windows,unix))'.dependencies]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
cramium-soc = [
|
cramium-soc = ["utralib/cramium-soc", "loader/cramium-soc", "cramium-api/std"]
|
||||||
"utralib/cramium-soc",
|
|
||||||
"cramium-hal/std",
|
|
||||||
"loader/cramium-soc",
|
|
||||||
"cramium-api/std",
|
|
||||||
]
|
|
||||||
cramium-fpga = ["utralib/cramium-fpga"]
|
cramium-fpga = ["utralib/cramium-fpga"]
|
||||||
board-baosec = ["cramium-hal/board-baosec"]
|
board-baosec = ["cramium-hal/board-baosec", "cramium-soc"]
|
||||||
board-baosor = ["cramium-hal/board-baosor"]
|
board-baosor = ["cramium-hal/board-baosor", "cramium-soc"]
|
||||||
board-dabao = ["cramium-hal/board-dabao"]
|
board-dabao = ["cramium-hal/board-dabao", "cramium-soc"]
|
||||||
|
|
||||||
precursor = ["utralib/precursor", "precursor-hal"]
|
precursor = ["utralib/precursor", "precursor-hal"]
|
||||||
hosted = ["utralib/hosted"]
|
hosted = ["utralib/hosted"]
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ pub enum SwapAbi {
|
||||||
StealPage = 5,
|
StealPage = 5,
|
||||||
ReleaseMemory = 6,
|
ReleaseMemory = 6,
|
||||||
WritePage = 7,
|
WritePage = 7,
|
||||||
|
BlockErase = 8,
|
||||||
}
|
}
|
||||||
/// SYNC WITH `kernel/src/swap.rs`
|
/// SYNC WITH `kernel/src/swap.rs`
|
||||||
impl SwapAbi {
|
impl SwapAbi {
|
||||||
|
|
@ -34,6 +35,7 @@ impl SwapAbi {
|
||||||
5 => StealPage,
|
5 => StealPage,
|
||||||
6 => ReleaseMemory,
|
6 => ReleaseMemory,
|
||||||
7 => WritePage,
|
7 => WritePage,
|
||||||
|
8 => BlockErase,
|
||||||
_ => Invalid,
|
_ => Invalid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -51,6 +53,7 @@ pub enum Opcode {
|
||||||
/// anyways because the page was read in and mapped into the caller's space at some
|
/// anyways because the page was read in and mapped into the caller's space at some
|
||||||
/// point in time.
|
/// point in time.
|
||||||
WritePage,
|
WritePage,
|
||||||
|
BulkErase,
|
||||||
/// Test messages
|
/// Test messages
|
||||||
#[cfg(feature = "swap-userspace-testing")]
|
#[cfg(feature = "swap-userspace-testing")]
|
||||||
Test0,
|
Test0,
|
||||||
|
|
@ -98,7 +101,7 @@ impl Swapper {
|
||||||
|
|
||||||
/// `offset` is transmitted with the address bank mask for MMAP_VIRT attached to avoid
|
/// `offset` is transmitted with the address bank mask for MMAP_VIRT attached to avoid
|
||||||
/// the first sector falling foul of the NonZero requirement.
|
/// the first sector falling foul of the NonZero requirement.
|
||||||
pub fn write_page(&self, offset: usize, page: FlashPage) -> Result<xous::Result, xous::Error> {
|
pub fn write_page(&self, offset: usize, page: &FlashPage) -> Result<xous::Result, xous::Error> {
|
||||||
if (offset & (cramium_hal::board::SPINOR_ERASE_SIZE as usize - 1)) != 0 {
|
if (offset & (cramium_hal::board::SPINOR_ERASE_SIZE as usize - 1)) != 0 {
|
||||||
return Err(xous::Error::BadAddress);
|
return Err(xous::Error::BadAddress);
|
||||||
}
|
}
|
||||||
|
|
@ -116,6 +119,19 @@ impl Swapper {
|
||||||
// but because we care that the call finished before proceeding.
|
// but because we care that the call finished before proceeding.
|
||||||
xous::send_message(self.conn, xous::Message::Borrow(msg))
|
xous::send_message(self.conn, xous::Message::Borrow(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn block_erase(&self, offset: usize, len: usize) -> Result<xous::Result, xous::Error> {
|
||||||
|
if (offset & (cramium_hal::board::SPINOR_BULK_ERASE_SIZE as usize - 1) != 0)
|
||||||
|
|| len == 0
|
||||||
|
|| (len & (cramium_hal::board::SPINOR_BULK_ERASE_SIZE as usize - 1)) != 0
|
||||||
|
{
|
||||||
|
return Err(xous::Error::BadAddress);
|
||||||
|
}
|
||||||
|
xous::send_message(
|
||||||
|
self.conn,
|
||||||
|
xous::Message::new_blocking_scalar(Opcode::BulkErase as usize, offset, len, 0, 0),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,8 @@ pub enum KernelOp {
|
||||||
HardOom = 3,
|
HardOom = 3,
|
||||||
/// Take the requested page and write it to SPI
|
/// Take the requested page and write it to SPI
|
||||||
WriteToFlash = 4,
|
WriteToFlash = 4,
|
||||||
|
/// Bulk erase
|
||||||
|
BulkErase = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PtPage {
|
pub struct PtPage {
|
||||||
|
|
@ -637,7 +639,7 @@ fn swap_handler(
|
||||||
writeln!(
|
writeln!(
|
||||||
DebugUart {},
|
DebugUart {},
|
||||||
"Exiting HARD OOM swap free loop: freed {} pages; {} requests rejected, {} wired",
|
"Exiting HARD OOM swap free loop: freed {} pages; {} requests rejected, {} wired",
|
||||||
target_pages - pages_to_free - HARD_OOM_RESERVED_PAGES,
|
target_pages - pages_to_free,
|
||||||
errs,
|
errs,
|
||||||
wired
|
wired
|
||||||
)
|
)
|
||||||
|
|
@ -671,6 +673,15 @@ fn swap_handler(
|
||||||
ss.hal.flash_write(buf, offset);
|
ss.hal.flash_write(buf, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some(KernelOp::BulkErase) => {
|
||||||
|
let offset = a2;
|
||||||
|
let len = a3;
|
||||||
|
if !RENODE_TESTING {
|
||||||
|
#[cfg(feature = "debug-print-swapper")]
|
||||||
|
writeln!(DebugUart {}, "BE: PA {:x} len {:x}", offset, len).ok();
|
||||||
|
ss.hal.block_erase(offset, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
writeln!(DebugUart {}, "Unimplemented or unknown opcode: {}", opcode).ok();
|
writeln!(DebugUart {}, "Unimplemented or unknown opcode: {}", opcode).ok();
|
||||||
}
|
}
|
||||||
|
|
@ -793,6 +804,22 @@ fn main() {
|
||||||
))
|
))
|
||||||
.expect("couldn't WritePage");
|
.expect("couldn't WritePage");
|
||||||
}
|
}
|
||||||
|
Some(Opcode::BulkErase) => {
|
||||||
|
if let Some(scalar) = msg.body.scalar_message_mut() {
|
||||||
|
let block = scalar.arg1;
|
||||||
|
let len = scalar.arg2;
|
||||||
|
xous::rsyscall(xous::SysCall::SwapOp(
|
||||||
|
SwapAbi::BlockErase as usize,
|
||||||
|
msg.sender.pid().unwrap().get() as usize,
|
||||||
|
block,
|
||||||
|
len,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
))
|
||||||
|
.expect("couldn't Block Erase region");
|
||||||
|
}
|
||||||
|
}
|
||||||
#[cfg(feature = "swap-userspace-testing")]
|
#[cfg(feature = "swap-userspace-testing")]
|
||||||
Some(Opcode::Test0) => {
|
Some(Opcode::Test0) => {
|
||||||
log::info!("Free mem: {}kiB", get_free_pages() * PAGE_SIZE / 1024);
|
log::info!("Free mem: {}kiB", get_free_pages() * PAGE_SIZE / 1024);
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,11 @@ impl SwapHal {
|
||||||
.chunks_exact(FLASH_PAGE_LEN)
|
.chunks_exact(FLASH_PAGE_LEN)
|
||||||
.zip((preserve_start..(preserve_start + FLASH_SECTOR_LEN)).step_by(FLASH_PAGE_LEN))
|
.zip((preserve_start..(preserve_start + FLASH_SECTOR_LEN)).step_by(FLASH_PAGE_LEN))
|
||||||
{
|
{
|
||||||
self.flash_spim.borrow_mut().mem_flash_write_page(addr as u32, page.try_into().unwrap());
|
// only do the write-page if something is not in the erased state
|
||||||
|
// this allows us to re-use flash_write as a "slow erase" for things smaller than a block
|
||||||
|
if !page.iter().all(|&b| b == 0xff) {
|
||||||
|
self.flash_spim.borrow_mut().mem_flash_write_page(addr as u32, page.try_into().unwrap());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
written += replace_end - preserve_to;
|
written += replace_end - preserve_to;
|
||||||
}
|
}
|
||||||
|
|
@ -272,4 +276,8 @@ impl SwapHal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn block_erase(&mut self, block: usize, len: usize) -> bool {
|
||||||
|
self.flash_spim.borrow_mut().flash_erase_block(block, len)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue