1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 08:26:17 +04:00
rCore/kernel/Makefile

216 lines
4.6 KiB
Makefile
Raw Normal View History

2018-08-07 12:11:48 +04:00
# Commands:
# 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
# make clean Clean
2018-08-07 12:11:48 +04:00
#
# Options:
# arch = x86_64 | riscv32 | aarch64
# 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
2018-11-28 21:22:44 +04:00
# SFSIMG = SFS image path of user programs
2018-11-29 17:39:43 +04:00
# smp = 1 | 2 | ... SMP core number
# board = none Running on qemu
# | fpga Only available on riscv32, build without bbl, run on board
# | 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-07-04 12:23:11 +04:00
arch ?= riscv32
board ?= none
2018-08-07 12:11:48 +04:00
mode ?= debug
LOG ?= debug
smp ?= 4
2018-12-01 13:37:37 +04:00
# NOTE: crate 'process' use this name 'm_mode' as an environment
# to set interrupt (MIE or SIE)
m_mode ?=
2018-08-07 12:11:48 +04:00
target := $(arch)-blog_os
2018-09-18 14:05:37 +04:00
kernel := target/$(target)/$(mode)/ucore
bin := target/$(target)/$(mode)/kernel.bin
bootimage := target/$(target)/bootimage.bin
2018-11-28 20:39:44 +04:00
user_dir := ../user
user_bin_path := $(user_dir)/target/$(arch)-ucore/debug
user_bins := $(patsubst $(user_bin_path)/%.d, $(user_bin_path)/%, $(wildcard $(user_bin_path)/*.d))
user_obj := build/$(arch)/user.o
2018-11-28 20:39:44 +04:00
export ARCH = $(arch)
2018-12-02 15:51:52 +04:00
export SFSIMG = $(user_dir)/build/user-$(arch).img
### qemu options ###
2018-09-18 14:05:37 +04:00
qemu_opts := \
2018-10-21 17:35:28 +04:00
-smp cores=$(smp) \
-nographic
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
else ifeq ($(arch), riscv32)
2018-11-29 17:39:43 +04:00
qemu_opts += \
2018-10-21 17:35:28 +04:00
-machine virt \
2018-11-29 17:39:43 +04:00
-kernel $(bin)
2018-12-01 13:37:37 +04:00
ifdef m_mode
2018-11-29 17:39:43 +04:00
qemu_opts += -cpu rv32imacu-nommu
endif
2018-11-29 17:39:43 +04:00
else ifeq ($(arch), aarch64)
2018-11-29 17:39:43 +04:00
qemu_opts += \
-machine $(board) \
-serial null -serial mon:stdio \
-kernel $(bin)
endif
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
### build args ###
ifeq ($(arch), riscv32)
ifeq ($(board), fpga)
2018-11-29 17:39:43 +04:00
features += no_bbl
2018-08-07 12:11:48 +04:00
endif
endif
2018-12-01 13:37:37 +04:00
ifdef m_mode
features += no_mmu m_mode
2018-11-29 17:39:43 +04:00
bbl_m_mode := --enable-boot-machine
endif
ifneq ($(board), none)
2018-11-29 17:39:43 +04:00
features += board_$(board)
endif
build_args := --target $(target).json --features "$(features)"
ifeq ($(mode), release)
2018-11-29 17:39:43 +04:00
build_args += --release
endif
2018-04-19 11:57:34 +04:00
2018-04-02 13:48:07 +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 := riscv32-unknown-elf-
2018-11-19 21:08:39 +04:00
else ifeq ($(arch), aarch64)
prefix ?= aarch64-none-elf-
endif
ld := $(prefix)ld
objdump := $(prefix)objdump
objcopy := $(prefix)objcopy
cc := $(prefix)gcc
as := $(prefix)as
gdb := $(prefix)gdb
2018-04-02 13:48:07 +04:00
2018-12-02 15:51:52 +04:00
.PHONY: all clean run build asm doc justrun debug kernel sfsimg install
2017-04-11 11:02:09 +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
2018-11-15 19:42:44 +04:00
@rm -rf ../riscv-pk/build
2017-04-11 11:02:09 +04:00
doc:
@cargo rustdoc -- --document-private-items
2018-12-02 15:51:52 +04:00
run: build sfsimg justrun
2018-07-04 12:23:11 +04:00
2018-12-02 15:51:52 +04:00
justrun:
@qemu-system-$(arch) $(qemu_opts) || [ $$? -eq 11 ] # run qemu and assert it exit 11
2017-04-11 11:02:09 +04:00
2018-12-02 15:51:52 +04:00
debug: $(kernel) $(bin)
@qemu-system-$(arch) $(qemu_opts) -s -S &
2018-10-26 18:02:24 +04:00
@sleep 1
@$(gdb) $(kernel) -x ../tools/gdbinit
2018-09-18 14:05:37 +04:00
ifeq ($(arch), x86_64)
2018-09-19 16:43:49 +04:00
build: kernel
2018-09-18 14:05:37 +04:00
else
build: $(bin)
endif
2018-04-09 17:20:47 +04:00
asm:
2018-04-12 19:44:25 +04:00
@$(objdump) -dS $(kernel) | less
header:
2018-07-13 21:11:47 +04:00
@$(objdump) -h $(kernel)
sym:
@$(objdump) -t $(kernel) | less
2018-09-19 16:43:49 +04:00
$(bin): kernel
ifeq ($(arch), riscv32)
ifeq ($(board), fpga)
2018-09-18 14:05:37 +04:00
@cp $(kernel) $@
2018-08-07 12:11:48 +04:00
else
@cd ../riscv-pk && \
mkdir -p build && \
cd build && \
../configure \
2018-11-29 17:39:43 +04:00
$(bbl_m_mode) \
--with-arch=rv32imac \
--disable-fp-emulation \
--host=riscv32-unknown-elf \
--with-payload=$(abspath $(kernel)) && \
make && \
cp bbl ../../kernel/$@
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-09-18 14:05:37 +04:00
ifeq ($(arch), x86_64)
2018-11-28 20:39:44 +04:00
kernel:
2018-09-18 14:05:37 +04:00
@bootimage build $(build_args)
else
2018-12-02 15:51:52 +04:00
kernel: sfsimg
2018-11-28 20:39:44 +04:00
ifeq ($(arch), riscv32)
@-patch -p0 -N -b \
$(shell rustc --print sysroot)/lib/rustlib/src/rust/src/libcore/sync/atomic.rs \
src/arch/riscv32/atomic.patch
2018-11-28 20:39:44 +04:00
endif
@CC=$(cc) 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
# make user.o from binary files
$(user_obj): $(user_bins)
2018-07-13 21:11:47 +04:00
@cd $(user_bin_path) && \
$(ld) -o $(abspath $@) $(patsubst %, -b binary %, $(notdir $(user_bins)))
### 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