2018-08-07 12:11:48 +04:00
|
|
|
# Commands:
|
2018-12-07 16:48:44 +04:00
|
|
|
# make build Build
|
|
|
|
# make run Build and run in QEMU
|
|
|
|
# make justrun Run the last build
|
|
|
|
# make doc Generate docs
|
|
|
|
# make asm Open the deassemble file of the last build
|
|
|
|
# make header Open 'objdump -h' of the last build
|
2019-01-08 15:04:34 +04:00
|
|
|
# make addr2line Use addr2line to recover line info in backtrace
|
2018-12-07 16:48:44 +04:00
|
|
|
# make clean Clean
|
2018-08-07 12:11:48 +04:00
|
|
|
#
|
|
|
|
# Options:
|
2019-01-03 14:21:13 +04:00
|
|
|
# arch = x86_64 | riscv32 | riscv64 | aarch64
|
2018-12-07 16:48:44 +04:00
|
|
|
# d = int | in_asm | ... QEMU debug info
|
2018-08-07 12:11:48 +04:00
|
|
|
# mode = debug | release
|
|
|
|
# LOG = off | error | warn | info | debug | trace
|
2019-01-03 14:21:13 +04:00
|
|
|
# SFSIMG = <sfsimg> SFS image path of user programs
|
2018-12-20 13:34:24 +04:00
|
|
|
# smp = 1 | 2 | ... SMP core number
|
|
|
|
# graphic = on | off enable/disable qemu graphical output
|
2019-01-03 14:21:13 +04:00
|
|
|
# board = none Running on QEMU
|
2018-12-28 13:51:18 +04:00
|
|
|
# | k210 Only available on riscv64, build without bbl, run on K210
|
2019-02-15 12:10:12 +04:00
|
|
|
# | u540 Only available on riscv64, run on HiFive U540, use Sv39
|
2018-12-07 16:48:44 +04:00
|
|
|
# | raspi3 Only available on aarch64, run on Raspberry Pi 3 Model B/B+
|
|
|
|
# m_mode Only available on riscv32, build for M-Mode, without MMU
|
2018-05-21 20:31:50 +04:00
|
|
|
|
2018-07-04 12:23:11 +04:00
|
|
|
arch ?= riscv32
|
2018-12-07 16:48:44 +04:00
|
|
|
board ?= none
|
2018-08-07 12:11:48 +04:00
|
|
|
mode ?= debug
|
|
|
|
LOG ?= debug
|
2019-01-23 18:11:41 +04:00
|
|
|
graphic ?= off
|
2018-10-19 13:11:08 +04:00
|
|
|
smp ?= 4
|
2018-12-01 13:37:37 +04:00
|
|
|
m_mode ?=
|
2018-08-07 12:11:48 +04:00
|
|
|
|
2018-12-31 21:53:33 +04:00
|
|
|
target := $(arch)
|
2019-01-03 15:37:04 +04:00
|
|
|
kernel := target/$(target)/$(mode)/rcore
|
2018-09-18 14:05:37 +04:00
|
|
|
bin := target/$(target)/$(mode)/kernel.bin
|
|
|
|
bootimage := target/$(target)/bootimage.bin
|
2018-12-31 21:53:33 +04:00
|
|
|
bbl_path := $(PWD)/../riscv-pk
|
2018-11-28 20:39:44 +04:00
|
|
|
user_dir := ../user
|
2019-02-15 13:00:34 +04:00
|
|
|
k210_lib := ../tools/k210/libkendryte.a
|
2018-11-28 20:39:44 +04:00
|
|
|
|
2018-12-31 14:44:16 +04:00
|
|
|
### export environments ###
|
2018-11-28 20:39:44 +04:00
|
|
|
export ARCH = $(arch)
|
2019-02-15 13:00:34 +04:00
|
|
|
export BOARD = $(board)
|
2018-12-15 16:17:02 +04:00
|
|
|
export SMP = $(smp)
|
2018-12-15 16:04:22 +04:00
|
|
|
#export SFSIMG = $(user_dir)/build/user-$(arch).img
|
|
|
|
ifeq ($(arch), x86_64)
|
|
|
|
export SFSIMG = $(user_dir)/img/ucore-i386.img
|
|
|
|
else
|
|
|
|
export SFSIMG = $(user_dir)/img/ucore-$(arch).img
|
|
|
|
endif
|
2018-12-28 13:51:18 +04:00
|
|
|
ifeq ($(arch), aarch64)
|
|
|
|
board := raspi3
|
|
|
|
endif
|
2018-12-31 14:44:16 +04:00
|
|
|
ifeq ($(board), k210)
|
|
|
|
m_mode := 1
|
|
|
|
endif
|
|
|
|
# crate 'process' use this to set interrupt (MIE or SIE)
|
|
|
|
export M_MODE = $(m_mode)
|
2018-10-26 07:20:03 +04:00
|
|
|
|
2018-12-20 13:34:24 +04:00
|
|
|
ifeq ($(arch), aarch64)
|
|
|
|
graphic ?= on
|
|
|
|
else
|
|
|
|
graphic ?= off
|
|
|
|
endif
|
|
|
|
|
2018-10-26 07:20:03 +04:00
|
|
|
### qemu options ###
|
2018-09-18 14:05:37 +04:00
|
|
|
qemu_opts := \
|
2018-12-20 13:34:24 +04:00
|
|
|
-smp cores=$(smp)
|
2018-11-29 17:39:43 +04:00
|
|
|
|
|
|
|
ifeq ($(arch), x86_64)
|
|
|
|
qemu_opts += \
|
|
|
|
-drive format=raw,file=$(bootimage) \
|
2018-12-03 08:30:03 +04:00
|
|
|
-drive format=raw,file=$(SFSIMG),media=disk,cache=writeback \
|
2018-11-29 17:39:43 +04:00
|
|
|
-serial mon:stdio \
|
|
|
|
-device isa-debug-exit
|
|
|
|
|
2018-10-26 07:20:03 +04:00
|
|
|
else ifeq ($(arch), riscv32)
|
2018-11-29 17:39:43 +04:00
|
|
|
qemu_opts += \
|
2018-10-21 17:35:28 +04:00
|
|
|
-machine virt \
|
2019-01-25 06:28:38 +04:00
|
|
|
-kernel $(bin) \
|
|
|
|
-drive file=$(SFSIMG),format=raw,id=sfs \
|
|
|
|
-device virtio-blk-device,drive=sfs
|
2018-12-01 13:37:37 +04:00
|
|
|
ifdef m_mode
|
2018-11-29 17:39:43 +04:00
|
|
|
qemu_opts += -cpu rv32imacu-nommu
|
2018-11-28 19:59:55 +04:00
|
|
|
endif
|
2018-11-29 17:39:43 +04:00
|
|
|
|
2018-12-28 18:20:21 +04:00
|
|
|
else ifeq ($(arch), riscv64)
|
|
|
|
qemu_opts += \
|
|
|
|
-machine virt \
|
2019-01-25 06:28:38 +04:00
|
|
|
-kernel $(bin) \
|
|
|
|
-drive file=$(SFSIMG),format=raw,id=sfs \
|
|
|
|
-device virtio-blk-device,drive=sfs
|
2018-12-28 18:20:21 +04:00
|
|
|
ifdef m_mode
|
|
|
|
qemu_opts += -cpu rv64imacu-nommu
|
|
|
|
endif
|
|
|
|
|
2018-10-26 07:20:03 +04:00
|
|
|
else ifeq ($(arch), aarch64)
|
2018-11-29 17:39:43 +04:00
|
|
|
qemu_opts += \
|
2018-10-26 07:20:03 +04:00
|
|
|
-machine $(board) \
|
2019-01-25 06:28:38 +04:00
|
|
|
-serial null -serial mon:stdio \
|
2018-10-26 07:20:03 +04:00
|
|
|
-kernel $(bin)
|
2018-07-14 13:41:45 +04:00
|
|
|
endif
|
2018-10-26 07:20:03 +04:00
|
|
|
|
|
|
|
ifdef d
|
2018-11-29 17:39:43 +04:00
|
|
|
qemu_opts += -d $(d)
|
2018-07-04 12:23:11 +04:00
|
|
|
endif
|
2018-04-09 17:20:47 +04:00
|
|
|
|
2019-01-23 18:11:41 +04:00
|
|
|
ifeq ($(graphic), off)
|
|
|
|
qemu_opts += -nographic
|
|
|
|
endif
|
|
|
|
|
2018-10-26 07:20:03 +04:00
|
|
|
### build args ###
|
2018-12-20 13:34:24 +04:00
|
|
|
ifneq ($(graphic), on)
|
|
|
|
features += nographic
|
|
|
|
endif
|
|
|
|
|
2018-12-11 12:52:50 +04:00
|
|
|
ifeq ($(board), raspi3)
|
|
|
|
# qemu only has generic timer
|
|
|
|
# TODO: configure system/generic timer automatically
|
|
|
|
raspi3_timer ?= generic
|
|
|
|
ifeq ($(raspi3_timer), generic)
|
|
|
|
features += raspi3_use_generic_timer
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2018-12-01 13:37:37 +04:00
|
|
|
ifdef m_mode
|
|
|
|
features += no_mmu m_mode
|
2019-01-31 21:09:23 +04:00
|
|
|
riscv_pk_args := --enable-boot-machine
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(board), u540)
|
|
|
|
features += sv39
|
|
|
|
riscv_pk_args += --enable-sv39
|
2018-07-14 13:41:45 +04:00
|
|
|
endif
|
|
|
|
|
2018-12-07 16:48:44 +04:00
|
|
|
ifneq ($(board), none)
|
2018-11-29 17:39:43 +04:00
|
|
|
features += board_$(board)
|
2018-12-07 16:48:44 +04:00
|
|
|
endif
|
2018-12-31 21:53:33 +04:00
|
|
|
build_args := --target targets/$(target).json --features "$(features)"
|
2018-05-21 20:31:50 +04:00
|
|
|
|
|
|
|
ifeq ($(mode), release)
|
2018-11-29 17:39:43 +04:00
|
|
|
build_args += --release
|
2018-05-21 20:31:50 +04:00
|
|
|
endif
|
|
|
|
|
2018-04-19 11:57:34 +04:00
|
|
|
|
2018-04-02 13:48:07 +04:00
|
|
|
|
2018-10-26 07:20:03 +04:00
|
|
|
### prefix ###
|
2018-11-19 21:08:39 +04:00
|
|
|
ifeq ($(arch), x86_64)
|
|
|
|
ifeq ($(uname), Darwin)
|
|
|
|
prefix := x86_64-elf-
|
|
|
|
endif
|
|
|
|
else ifeq ($(arch), riscv32)
|
|
|
|
prefix := riscv64-unknown-elf-
|
2018-12-28 18:20:21 +04:00
|
|
|
else ifeq ($(arch), riscv64)
|
|
|
|
prefix := riscv64-unknown-elf-
|
2018-11-19 21:08:39 +04:00
|
|
|
else ifeq ($(arch), aarch64)
|
|
|
|
prefix ?= aarch64-none-elf-
|
2019-01-08 09:27:53 +04:00
|
|
|
ifeq (,$(shell which $(prefix)ld))
|
|
|
|
prefix := aarch64-elf-
|
|
|
|
endif
|
2018-11-19 21:08:39 +04:00
|
|
|
endif
|
|
|
|
|
|
|
|
ld := $(prefix)ld
|
|
|
|
objdump := $(prefix)objdump
|
|
|
|
objcopy := $(prefix)objcopy
|
|
|
|
cc := $(prefix)gcc
|
|
|
|
as := $(prefix)as
|
2019-01-23 18:11:41 +04:00
|
|
|
gdb := gdb
|
2019-01-03 15:37:04 +04:00
|
|
|
export CC=$(cc)
|
2018-04-02 13:48:07 +04:00
|
|
|
|
2019-01-23 18:11:41 +04:00
|
|
|
.PHONY: all clean run build asm doc justrun debug kernel sfsimg install runnet
|
2017-04-11 11:02:09 +04:00
|
|
|
|
2018-10-26 07:20:03 +04:00
|
|
|
all: kernel
|
2017-04-11 11:02:09 +04:00
|
|
|
|
|
|
|
clean:
|
2018-09-18 14:05:37 +04:00
|
|
|
@cargo clean
|
2018-12-02 15:56:29 +04:00
|
|
|
@cd $(user_dir) && make clean
|
2017-04-11 11:02:09 +04:00
|
|
|
|
2018-05-21 12:05:36 +04:00
|
|
|
doc:
|
|
|
|
@cargo rustdoc -- --document-private-items
|
|
|
|
|
2018-12-28 18:20:21 +04:00
|
|
|
run: build justrun
|
2019-01-23 18:11:41 +04:00
|
|
|
runnet: build justrunnet
|
|
|
|
runui: build justrunui
|
2018-07-04 12:23:11 +04:00
|
|
|
|
2018-12-02 15:51:52 +04:00
|
|
|
justrun:
|
2018-12-28 18:20:21 +04:00
|
|
|
@qemu-system-$(arch) $(qemu_opts)
|
2017-04-11 11:02:09 +04:00
|
|
|
|
2019-01-23 18:11:41 +04:00
|
|
|
justrunnet: build
|
|
|
|
@sudo qemu-system-$(arch) $(qemu_opts) \
|
|
|
|
-netdev type=tap,id=net0,script=no,downscript=no \
|
|
|
|
-device virtio-net-device,netdev=net0 \
|
|
|
|
|
|
|
|
justrunui: build
|
|
|
|
@qemu-system-$(arch) $(qemu_opts) \
|
|
|
|
-device virtio-gpu-device \
|
2019-01-25 06:28:38 +04:00
|
|
|
-device virtio-mouse-device
|
2019-01-23 18:11:41 +04:00
|
|
|
|
2018-12-02 15:51:52 +04:00
|
|
|
debug: $(kernel) $(bin)
|
2018-05-18 07:49:27 +04:00
|
|
|
@qemu-system-$(arch) $(qemu_opts) -s -S &
|
2018-10-26 18:02:24 +04:00
|
|
|
@sleep 1
|
|
|
|
@$(gdb) $(kernel) -x ../tools/gdbinit
|
2018-05-18 07:49:27 +04:00
|
|
|
|
2018-09-18 14:05:37 +04:00
|
|
|
build: $(bin)
|
2018-04-09 17:20:47 +04:00
|
|
|
|
2018-05-21 20:31:50 +04:00
|
|
|
asm:
|
2018-04-12 19:44:25 +04:00
|
|
|
@$(objdump) -dS $(kernel) | less
|
|
|
|
|
2018-10-19 13:11:08 +04:00
|
|
|
header:
|
2018-07-13 21:11:47 +04:00
|
|
|
@$(objdump) -h $(kernel)
|
|
|
|
|
2018-10-19 13:11:08 +04:00
|
|
|
sym:
|
|
|
|
@$(objdump) -t $(kernel) | less
|
|
|
|
|
2018-09-19 16:43:49 +04:00
|
|
|
$(bin): kernel
|
2018-10-26 07:20:03 +04:00
|
|
|
ifeq ($(arch), riscv32)
|
2018-12-31 21:53:33 +04:00
|
|
|
@mkdir -p target/$(target)/bbl && \
|
|
|
|
cd target/$(target)/bbl && \
|
|
|
|
$(bbl_path)/configure \
|
2019-01-31 21:09:23 +04:00
|
|
|
$(riscv_pk_args) \
|
2018-11-28 19:59:55 +04:00
|
|
|
--with-arch=rv32imac \
|
2018-10-26 07:20:03 +04:00
|
|
|
--disable-fp-emulation \
|
|
|
|
--host=riscv64-unknown-elf \
|
|
|
|
--with-payload=$(abspath $(kernel)) && \
|
2018-12-26 09:57:26 +04:00
|
|
|
make -j32 && \
|
2018-12-31 21:53:33 +04:00
|
|
|
cp bbl $(abspath $@)
|
2018-12-28 18:20:21 +04:00
|
|
|
else ifeq ($(arch), riscv64)
|
|
|
|
ifeq ($(board), k210)
|
|
|
|
@$(objcopy) $(kernel) --strip-all -O binary $@
|
|
|
|
else
|
2018-12-31 21:53:33 +04:00
|
|
|
@mkdir -p target/$(target)/bbl && \
|
|
|
|
cd target/$(target)/bbl && \
|
|
|
|
$(bbl_path)/configure \
|
2019-01-31 21:09:23 +04:00
|
|
|
$(riscv_pk_args) \
|
2018-12-28 18:20:21 +04:00
|
|
|
--with-arch=rv64imac \
|
|
|
|
--disable-fp-emulation \
|
|
|
|
--host=riscv64-unknown-elf \
|
|
|
|
--with-payload=$(abspath $(kernel)) && \
|
|
|
|
make -j32 && \
|
2018-12-31 21:53:33 +04:00
|
|
|
cp bbl $(abspath $@)
|
2018-10-26 07:20:03 +04:00
|
|
|
endif
|
|
|
|
else ifeq ($(arch), aarch64)
|
2018-11-19 21:08:39 +04:00
|
|
|
@$(objcopy) $(kernel) --strip-all -O binary $@
|
2018-08-07 12:11:48 +04:00
|
|
|
endif
|
2018-07-04 12:23:11 +04:00
|
|
|
|
2018-11-28 20:39:44 +04:00
|
|
|
kernel:
|
2018-12-28 18:20:21 +04:00
|
|
|
ifeq ($(arch), x86_64)
|
2018-09-18 14:05:37 +04:00
|
|
|
@bootimage build $(build_args)
|
2018-12-28 18:20:21 +04:00
|
|
|
else ifeq ($(arch), riscv32)
|
2018-10-26 10:56:06 +04:00
|
|
|
@-patch -p0 -N -b \
|
|
|
|
$(shell rustc --print sysroot)/lib/rustlib/src/rust/src/libcore/sync/atomic.rs \
|
|
|
|
src/arch/riscv32/atomic.patch
|
2019-01-03 15:37:04 +04:00
|
|
|
@cargo xbuild $(build_args)
|
2018-12-28 18:20:21 +04:00
|
|
|
else ifeq ($(arch), riscv64)
|
2019-02-15 13:00:34 +04:00
|
|
|
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
|
2019-02-15 10:54:42 +04:00
|
|
|
@-patch -p0 -N -b \
|
|
|
|
$(shell rustc --print sysroot)/lib/rustlib/src/rust/src/libcore/sync/atomic.rs \
|
|
|
|
src/arch/riscv32/atomic.patch
|
|
|
|
@cargo xbuild $(build_args)
|
2018-12-28 18:20:21 +04:00
|
|
|
else ifeq ($(arch), aarch64)
|
2019-01-03 15:37:04 +04:00
|
|
|
@cargo xbuild $(build_args)
|
2018-09-18 14:05:37 +04:00
|
|
|
endif
|
2018-04-02 11:28:32 +04:00
|
|
|
|
2018-11-28 20:39:44 +04:00
|
|
|
|
|
|
|
### user programs ###
|
2018-12-02 15:51:52 +04:00
|
|
|
sfsimg:
|
2018-11-28 20:39:44 +04:00
|
|
|
@cd $(user_dir) && make sfsimg
|
|
|
|
|
2018-10-29 15:14:54 +04:00
|
|
|
|
|
|
|
### install ###
|
|
|
|
ifeq ($(board), raspi3)
|
|
|
|
sd_card ?=
|
|
|
|
|
|
|
|
ifeq ($(shell uname), Darwin)
|
|
|
|
sd_card := /Volumes/boot
|
|
|
|
else ifeq ($(shell uname), Linux)
|
|
|
|
sd_card := /media/$(shell whoami)/boot
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef sd_card
|
|
|
|
.PHONY:
|
|
|
|
install: $(bin)
|
|
|
|
cp $(bin) $(sd_card)/kernel8.img
|
|
|
|
sudo umount $(sd_card)
|
|
|
|
endif
|
|
|
|
|
|
|
|
endif
|
2018-12-31 21:53:33 +04:00
|
|
|
|
|
|
|
ifeq ($(board), k210)
|
|
|
|
.PHONY:
|
|
|
|
install: $(bin)
|
|
|
|
## baudrate no more than 600000
|
|
|
|
@python3 ../tools/k210/kflash.py $(bin) -b 600000
|
2019-01-08 08:57:24 +04:00
|
|
|
endif
|
2019-01-08 15:04:34 +04:00
|
|
|
|
|
|
|
.PHONY:
|
|
|
|
addr2line:
|
|
|
|
@python3 ../tools/addr2line.py $(prefix)addr2line $(arch)
|