update kflash.py, fix build k210

master
WangRunji 6 years ago
parent 2766f49986
commit 95dfb7684f

@ -36,9 +36,11 @@ bin := target/$(target)/$(mode)/kernel.bin
bootimage := target/$(target)/bootimage.bin bootimage := target/$(target)/bootimage.bin
bbl_path := $(PWD)/../riscv-pk bbl_path := $(PWD)/../riscv-pk
user_dir := ../user user_dir := ../user
k210_lib := ../tools/k210/libkendryte.a
### export environments ### ### export environments ###
export ARCH = $(arch) export ARCH = $(arch)
export BOARD = $(board)
export SMP = $(smp) export SMP = $(smp)
#export SFSIMG = $(user_dir)/build/user-$(arch).img #export SFSIMG = $(user_dir)/build/user-$(arch).img
ifeq ($(arch), x86_64) ifeq ($(arch), x86_64)
@ -247,6 +249,12 @@ else ifeq ($(arch), riscv32)
src/arch/riscv32/atomic.patch src/arch/riscv32/atomic.patch
@cargo xbuild $(build_args) @cargo xbuild $(build_args)
else ifeq ($(arch), riscv64) 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 \ @-patch -p0 -N -b \
$(shell rustc --print sysroot)/lib/rustlib/src/rust/src/libcore/sync/atomic.rs \ $(shell rustc --print sysroot)/lib/rustlib/src/rust/src/libcore/sync/atomic.rs \
src/arch/riscv32/atomic.patch src/arch/riscv32/atomic.patch

@ -6,8 +6,10 @@ use std::io::{Result, Write};
fn main() { fn main() {
println!("cargo:rerun-if-env-changed=LOG"); println!("cargo:rerun-if-env-changed=LOG");
println!("cargo:rerun-if-env-changed=BOARD");
let arch: String = std::env::var("ARCH").unwrap(); let arch: String = std::env::var("ARCH").unwrap();
let board: String = std::env::var("BOARD").unwrap();
match arch.as_str() { match arch.as_str() {
"x86_64" => { "x86_64" => {
gen_vector_asm().unwrap(); gen_vector_asm().unwrap();
@ -29,6 +31,10 @@ fn main() {
.flag("-mabi=lp64") .flag("-mabi=lp64")
.compile("sfsimg"); .compile("sfsimg");
} }
if board == "k210" {
println!("cargo:rustc-link-search=native={}", "../tools/k210");
println!("cargo:rustc-link-lib=static=kendryte");
}
} }
"aarch64" => { "aarch64" => {
if let Ok(file_path) = gen_sfsimg_asm() { if let Ok(file_path) = gen_sfsimg_asm() {

@ -58,6 +58,7 @@ pub fn set_next() {
pub fn set_next() { pub fn set_next() {
unsafe { unsafe {
assert_eq!(clint_timer_start(10, true), 0); assert_eq!(clint_timer_start(10, true), 0);
mstatus::clear_mie(); // mie is set on 'clint_timer_start'
} }
} }

@ -15,7 +15,7 @@ import re
import os import os
BASH_TIPS = dict(NORMAL='\033[0m',BOLD='\033[1m',DIM='\033[2m',UNDERLINE='\033[4m', 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') BG_DEFAULT='\033[49m', BG_WHITE='\033[107m')
ERROR_MSG = BASH_TIPS['RED']+BASH_TIPS['BOLD']+'[ERROR]'+BASH_TIPS['NORMAL'] ERROR_MSG = BASH_TIPS['RED']+BASH_TIPS['BOLD']+'[ERROR]'+BASH_TIPS['NORMAL']
@ -465,18 +465,18 @@ class MAIXLoader:
return data return data
def reset_to_isp_kd233(self): def reset_to_isp_kd233(self):
self._port.dtr = False self._port.setDTR (False)
self._port.rts = False self._port.setRTS (False)
time.sleep(0.01) time.sleep(0.01)
#print('-- RESET to LOW, IO16 to HIGH --') #print('-- RESET to LOW, IO16 to HIGH --')
# Pull reset down and keep 10ms # Pull reset down and keep 10ms
self._port.dtr = True self._port.setDTR (True)
self._port.rts = False self._port.setRTS (False)
time.sleep(0.01) time.sleep(0.01)
#print('-- IO16 to LOW, RESET to HIGH --') #print('-- IO16 to LOW, RESET to HIGH --')
# Pull IO16 to low and release reset # Pull IO16 to low and release reset
self._port.rts = True self._port.setRTS (True)
self._port.dtr = False self._port.setDTR (False)
time.sleep(0.01) time.sleep(0.01)
def reset_to_isp_dan(self): def reset_to_isp_dan(self):
@ -495,18 +495,18 @@ class MAIXLoader:
time.sleep(0.01) time.sleep(0.01)
def reset_to_boot(self): def reset_to_boot(self):
self._port.dtr = False self._port.setDTR (False)
self._port.rts = False self._port.setRTS (False)
time.sleep(0.01) time.sleep(0.01)
#print('-- RESET to LOW --') #print('-- RESET to LOW --')
# Pull reset down and keep 10ms # Pull reset down and keep 10ms
self._port.dtr = True self._port.setRTS (False)
self._port.rts = False self._port.setDTR (True)
time.sleep(0.01) time.sleep(0.01)
#print('-- RESET to HIGH, BOOT --') #print('-- RESET to HIGH, BOOT --')
# Pull IO16 to low and release reset # Pull IO16 to low and release reset
self._port.rts = False self._port.setRTS (False)
self._port.dtr = False self._port.setDTR (False)
time.sleep(0.01) time.sleep(0.01)
def greeting(self): def greeting(self):
@ -709,7 +709,7 @@ class MAIXLoader:
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-p", "--port", help="COM Port", default="DEFAULT") 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("-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("-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) parser.add_argument("-k", "--key", help="AES key in hex, if you need encrypt your firmware.", required=False, default=None)

Loading…
Cancel
Save