diff --git a/kernel/Makefile b/kernel/Makefile index 7538688..fcee52d 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -36,9 +36,11 @@ bin := target/$(target)/$(mode)/kernel.bin bootimage := target/$(target)/bootimage.bin bbl_path := $(PWD)/../riscv-pk user_dir := ../user +k210_lib := ../tools/k210/libkendryte.a ### export environments ### export ARCH = $(arch) +export BOARD = $(board) export SMP = $(smp) #export SFSIMG = $(user_dir)/build/user-$(arch).img ifeq ($(arch), x86_64) @@ -247,6 +249,12 @@ else ifeq ($(arch), riscv32) src/arch/riscv32/atomic.patch @cargo xbuild $(build_args) else ifeq ($(arch), riscv64) +ifeq ($(board), k210) + @[[ -f $(k210_lib) ]] || wget https://github.com/wangrunji0408/RustOS/releases/download/v0.1/libkendryte.a -O $(k210_lib) + @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 diff --git a/kernel/build.rs b/kernel/build.rs index 5adf240..7573489 100644 --- a/kernel/build.rs +++ b/kernel/build.rs @@ -6,8 +6,10 @@ use std::io::{Result, Write}; fn main() { println!("cargo:rerun-if-env-changed=LOG"); + println!("cargo:rerun-if-env-changed=BOARD"); let arch: String = std::env::var("ARCH").unwrap(); + let board: String = std::env::var("BOARD").unwrap(); match arch.as_str() { "x86_64" => { gen_vector_asm().unwrap(); @@ -29,6 +31,10 @@ fn main() { .flag("-mabi=lp64") .compile("sfsimg"); } + if board == "k210" { + println!("cargo:rustc-link-search=native={}", "../tools/k210"); + println!("cargo:rustc-link-lib=static=kendryte"); + } } "aarch64" => { if let Ok(file_path) = gen_sfsimg_asm() { diff --git a/kernel/src/arch/riscv32/timer.rs b/kernel/src/arch/riscv32/timer.rs index 65f0ac9..5b39cb9 100644 --- a/kernel/src/arch/riscv32/timer.rs +++ b/kernel/src/arch/riscv32/timer.rs @@ -58,6 +58,7 @@ pub fn set_next() { pub fn set_next() { unsafe { assert_eq!(clint_timer_start(10, true), 0); + mstatus::clear_mie(); // mie is set on 'clint_timer_start' } } diff --git a/tools/k210/kflash.py b/tools/k210/kflash.py old mode 100644 new mode 100755 index 46910c9..c6e8fae --- a/tools/k210/kflash.py +++ b/tools/k210/kflash.py @@ -15,7 +15,7 @@ import re import os BASH_TIPS = dict(NORMAL='\033[0m',BOLD='\033[1m',DIM='\033[2m',UNDERLINE='\033[4m', - DEFAULT='\033[39', RED='\033[31m', YELLOW='\033[33m', GREEN='\033[32m', + DEFAULT='\033[39m', RED='\033[31m', YELLOW='\033[33m', GREEN='\033[32m', BG_DEFAULT='\033[49m', BG_WHITE='\033[107m') ERROR_MSG = BASH_TIPS['RED']+BASH_TIPS['BOLD']+'[ERROR]'+BASH_TIPS['NORMAL'] @@ -465,18 +465,18 @@ class MAIXLoader: return data def reset_to_isp_kd233(self): - self._port.dtr = False - self._port.rts = False + self._port.setDTR (False) + self._port.setRTS (False) time.sleep(0.01) #print('-- RESET to LOW, IO16 to HIGH --') # Pull reset down and keep 10ms - self._port.dtr = True - self._port.rts = False + self._port.setDTR (True) + self._port.setRTS (False) time.sleep(0.01) #print('-- IO16 to LOW, RESET to HIGH --') # Pull IO16 to low and release reset - self._port.rts = True - self._port.dtr = False + self._port.setRTS (True) + self._port.setDTR (False) time.sleep(0.01) def reset_to_isp_dan(self): @@ -495,18 +495,18 @@ class MAIXLoader: time.sleep(0.01) def reset_to_boot(self): - self._port.dtr = False - self._port.rts = False + self._port.setDTR (False) + self._port.setRTS (False) time.sleep(0.01) #print('-- RESET to LOW --') # Pull reset down and keep 10ms - self._port.dtr = True - self._port.rts = False + self._port.setRTS (False) + self._port.setDTR (True) time.sleep(0.01) #print('-- RESET to HIGH, BOOT --') # Pull IO16 to low and release reset - self._port.rts = False - self._port.dtr = False + self._port.setRTS (False) + self._port.setDTR (False) time.sleep(0.01) def greeting(self): @@ -709,7 +709,7 @@ class MAIXLoader: if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-p", "--port", help="COM Port", default="DEFAULT") - parser.add_argument("-c", "--chip", help="SPI Flash type, 1 for in-chip, 0 for on-board", default=1) + parser.add_argument("-c", "--chip", help="SPI Flash type, 0 for in-chip, 1 for on-board", default=1) parser.add_argument("-b", "--baudrate", type=int, help="UART baudrate for uploading firmware", default=115200) parser.add_argument("-l", "--bootloader", help="bootloader bin path", required=False, default=None) parser.add_argument("-k", "--key", help="AES key in hex, if you need encrypt your firmware.", required=False, default=None)