1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-24 00:46:17 +04:00

works on K210!

This commit is contained in:
WangRunji 2019-04-21 23:47:00 +08:00
parent 1e5f901926
commit 45c2ec0b17
14 changed files with 968 additions and 16 deletions

View File

@ -23,6 +23,7 @@ default = ["sv39"]
# Page table sv39 or sv48 (for riscv64)
sv39 = []
board_u540 = ["sv39", "link_user"]
board_k210 = ["sv39", "link_user"]
# (for aarch64 RaspberryPi3)
nographic = []
board_raspi3 = ["bcm2837", "link_user"]

View File

@ -25,6 +25,7 @@
# board = none Running on QEMU
# | pc Only available on x86_64, run on real pc
# | u540 Only available on riscv64, run on HiFive U540, use Sv39
# | k210 Only available on riscv64, run on K210, use Sv39
# | raspi3 Only available on aarch64, run on Raspberry Pi 3 Model B/B+
# pci_passthru = 0000:00:00.1 Only available on x86_64, passthrough the specified PCI device
# init = /bin/ls Only available on riscv64, run specified program instead of user shell
@ -59,7 +60,7 @@ ifeq ($(arch), $(filter $(arch), aarch64 mipsel))
export SFSIMG = $(user_dir)/build/$(arch).img
else
# board is pc or qemu?
ifeq ($(board), pc)
ifeq ($(board), $(filter $(board), pc u540 k210))
#link user img, so use original image
export SFSIMG = $(user_dir)/build/$(arch).img
else
@ -201,11 +202,6 @@ features += raspi3_use_generic_timer
endif
endif
ifeq ($(board), u540)
features += sv39
riscv_pk_args += --enable-sv39
endif
ifneq ($(board), none)
features += board_$(board)
endif
@ -325,6 +321,11 @@ ifeq ($(arch), x86_64)
@bootimage build $(build_args)
@mv target/x86_64/bootimage.bin $(bootimage)
else ifeq ($(arch), $(filter $(arch), riscv32 riscv64))
ifeq ($(board), k210)
@cp src/arch/riscv32/board/k210/linker.ld src/arch/riscv32/boot/linker64.ld
else
@cp src/arch/riscv32/board/u540/linker.ld src/arch/riscv32/boot/linker64.ld
endif
@-patch -p0 -N -b \
$(shell rustc --print sysroot)/lib/rustlib/src/rust/src/libcore/sync/atomic.rs \
src/arch/riscv32/atomic.patch
@ -367,8 +368,16 @@ ifeq ($(board), u540)
.PHONY:
install: $(kernel_img)
@$(objcopy) -S -O binary ../tools/opensbi/fu540.elf $(build_path)/bin
@dd if=$< of=$(build_path)/bin bs=131072 seek=16
@../tools/u540/mkimg.sh $(build_path)/bin $(build_path)/sd.img
@dd if=$< of=$(build_path)/bin bs=0x20000 seek=16
@../tools/u540/mkimg.sh $(build_path)/bin $(build_path)/u540.img
endif
ifeq ($(board), k210)
.PHONY:
install: $(kernel_img)
@$(objcopy) -S -O binary ../tools/opensbi/k210.elf $(build_path)/k210.img
@dd if=$< of=$(build_path)/k210.img bs=0x10000 seek=1
@python3 ../tools/k210/kflash.py -b 600000 $(build_path)/k210.img
endif
.PHONY:

View File

@ -0,0 +1,49 @@
/* Copy from bbl-ucore : https://ring00.github.io/bbl-ucore */
/* Simple linker script for the ucore kernel.
See the GNU ld 'info' manual ("info ld") to learn the syntax. */
OUTPUT_ARCH(riscv)
ENTRY(_start)
BASE_ADDRESS = 0xffffffffc0010000;
SECTIONS
{
/* Load the kernel at this address: "." means the current address */
. = BASE_ADDRESS;
start = .;
.text : {
stext = .;
*(.text.entry)
*(.text .text.*)
. = ALIGN(4K);
etext = .;
}
.rodata : {
srodata = .;
*(.rodata .rodata.*)
. = ALIGN(4K);
erodata = .;
}
.data : {
sdata = .;
*(.data .data.*)
edata = .;
}
.stack : {
*(.bss.stack)
}
.bss : {
sbss = .;
*(.bss .bss.*)
ebss = .;
}
PROVIDE(end = .);
}

View File

@ -0,0 +1,30 @@
.section .text.entry
.globl _start
_start:
# a0 == hartid
# pc == 0x80010000
# sp == 0x8000xxxx
# 1. set sp
# sp = bootstack + (hartid + 1) * 0x10000
add t0, a0, 1
slli t0, t0, 14
lui sp, %hi(bootstack)
add sp, sp, t0
# 1.1 set device tree paddr
# OpenSBI give me 0 ???
li a1, 0x800003b0
# 2. jump to rust_main (absolute address)
lui t0, %hi(rust_main)
addi t0, t0, %lo(rust_main)
jr t0
.section .bss.stack
.align 12 # page align
.global bootstack
bootstack:
.space 4096 * 4 * 2
.global bootstacktop
bootstacktop:

View File

@ -22,10 +22,16 @@ pub const KERNEL_P2_INDEX: usize = (KERNEL_OFFSET >> 12 >> 10) & 0x3ff;
#[cfg(target_arch = "riscv64")]
pub const KERNEL_P4_INDEX: usize = (KERNEL_OFFSET >> 12 >> 9 >> 9 >> 9) & 0o777;
#[cfg(feature = "board_k210")]
pub const KERNEL_HEAP_SIZE: usize = 0x0020_0000;
#[cfg(not(feature = "board_k210"))]
pub const KERNEL_HEAP_SIZE: usize = 0x0080_0000;
pub const MEMORY_OFFSET: usize = 0x8000_0000;
// TODO: get memory end from device tree
#[cfg(feature = "board_k210")]
pub const MEMORY_END: usize = 0x8060_0000;
#[cfg(not(feature = "board_k210"))]
pub const MEMORY_END: usize = 0x8800_0000;
// FIXME: rv64 `sh` and `ls` will crash if stack top > 0x80000000 ???

View File

@ -9,6 +9,8 @@ use riscv::{addr::*, register::sstatus};
/// Initialize the memory management module
pub fn init(dtb: usize) {
// allow user memory access
// NOTE: In K210 priv v1.9.1, sstatus.SUM is PUM which has opposite meaning!
#[cfg(not(feature = "board_k210"))]
unsafe {
sstatus::set_sum();
}

View File

@ -55,6 +55,7 @@ pub extern "C" fn rust_main(hartid: usize, device_tree_paddr: usize) -> ! {
// FIXME: init driver on u540
#[cfg(not(feature = "board_u540"))]
crate::drivers::init(device_tree_vaddr);
#[cfg(not(feature = "board_k210"))]
unsafe {
board::enable_serial_interrupt();
board::init_external_interrupt();
@ -108,6 +109,8 @@ global_asm!(
);
#[cfg(target_arch = "riscv32")]
global_asm!(include_str!("boot/entry32.asm"));
#[cfg(target_arch = "riscv64")]
#[cfg(all(target_arch = "riscv64", not(feature = "board_k210")))]
global_asm!(include_str!("boot/entry64.asm"));
#[cfg(feature = "board_k210")]
global_asm!(include_str!("boot/entry_k210.asm"));
global_asm!(include_str!("boot/trap.asm"));

View File

@ -20,6 +20,15 @@ impl Stdin {
self.pushed.notify_one();
}
pub fn pop(&self) -> char {
#[cfg(feature = "board_k210")]
loop {
// polling
let c = crate::arch::io::getchar();
if c != '\0' {
return c;
}
}
#[cfg(not(feature = "board_k210"))]
loop {
let ret = self.buf.lock().pop_front();
match ret {

View File

@ -16,13 +16,21 @@ pub type MemorySet = rcore_memory::memory_set::MemorySet<InactivePageTable0>;
#[cfg(target_arch = "x86_64")]
pub type FrameAlloc = bitmap_allocator::BitAlloc16M;
// RISCV has 1G memory
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
// RISCV, ARM, MIPS has 1G memory
#[cfg(all(
any(
target_arch = "riscv32",
target_arch = "riscv64",
target_arch = "aarch64",
target_arch = "mips"
),
not(feature = "board_k210")
))]
pub type FrameAlloc = bitmap_allocator::BitAlloc1M;
// Raspberry Pi 3 has 1G memory
#[cfg(any(target_arch = "aarch64", target_arch = "mips"))]
pub type FrameAlloc = bitmap_allocator::BitAlloc1M;
// K210 has 8M memory
#[cfg(feature = "board_k210")]
pub type FrameAlloc = bitmap_allocator::BitAlloc4K;
lazy_static! {
pub static ref FRAME_ALLOCATOR: SpinNoIrqLock<FrameAlloc> =

View File

@ -127,7 +127,7 @@ impl Thread {
Box::new(Thread {
context: Context::null(),
// safety: other fields will never be used
.. core::mem::uninitialized()
..core::mem::uninitialized()
})
}

829
tools/k210/kflash.py Executable file

File diff suppressed because one or more lines are too long

View File

@ -7,3 +7,9 @@ These are binary release of OpenSBI on this [commit](https://github.com/riscv/op
- virt_rv64.elf: opensbi-0.3-rv64-bin/platform/qemu/virt/firmware/fw_jump.elf
NOTE: The [official v0.3 release](https://github.com/riscv/opensbi/releases/tag/v0.3) has bug on serial interrupt.
For K210: It needs some modification. The binary is from this [commit](https://github.com/rcore-os/opensbi/commit/4400a1a7d40b5399b3e07b4bad9fd303885c8c16).
* k210.elf: build/platform/kendryte/k210/firmware/fw_payload.elf

BIN
tools/opensbi/k210.elf Executable file

Binary file not shown.