Load app from sdcard on K210, but panicked on qemu.

This commit is contained in:
Yifan Wu 2020-12-20 00:52:14 +08:00
parent 760de97155
commit a3802a4b91
18 changed files with 177 additions and 142 deletions

View file

@ -4,11 +4,7 @@ mod sdcard;
use lazy_static::*;
use alloc::sync::Arc;
use core::any::Any;
pub trait BlockDevice : Send + Sync + Any {
fn read_block(&self, block_id: usize, buf: &mut [u8]);
fn write_block(&self, block_id: usize, buf: &[u8]);
}
use easy_fs::BlockDevice;
#[cfg(feature = "board_qemu")]
type BlockDeviceImpl = virtio_blk::VirtIOBlock;

View file

@ -717,7 +717,7 @@ lazy_static! {
fn init_sdcard() -> SDCard<SPIImpl<SPI0>> {
// wait previous output
usleep(100000);
let peripherals = Peripherals::take().unwrap();
let peripherals = unsafe { Peripherals::steal() };
sysctl::pll_set_freq(sysctl::pll::PLL0, 800_000_000).unwrap();
sysctl::pll_set_freq(sysctl::pll::PLL1, 300_000_000).unwrap();
sysctl::pll_set_freq(sysctl::pll::PLL2, 45_158_400).unwrap();

View file

@ -23,9 +23,12 @@ lazy_static! {
impl BlockDevice for VirtIOBlock {
fn read_block(&self, block_id: usize, buf: &mut [u8]) {
//println!("read block {}", block_id);
self.0.lock().read_block(block_id, buf).expect("Error when reading VirtIOBlk");
//println!("read block OK!");
}
fn write_block(&self, block_id: usize, buf: &[u8]) {
//println!("write block {}", block_id);
self.0.lock().write_block(block_id, buf).expect("Error when writing VirtIOBlk");
}
}
@ -44,6 +47,7 @@ pub extern "C" fn virtio_dma_alloc(pages: usize) -> PhysAddr {
for i in 0..pages {
let frame = frame_alloc().unwrap();
if i == 0 { ppn_base = frame.ppn; }
println!("virtio_dma_alloc {:?}", frame.ppn);
assert_eq!(frame.ppn.0, ppn_base.0 + i);
QUEUE_FRAMES.lock().push(frame);
}