Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
complete configuration system based on kconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhainebula committed Jul 2, 2022
1 parent 83f431c commit fbbb389
Show file tree
Hide file tree
Showing 12 changed files with 447 additions and 47 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@
.vScode*
.Vscode*
.VScode*
/config/.config
/config/.config.old
.config
.config.old
/include/config
/include/generated

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "opensbi"]
path = opensbi
url = https://github.com/riscv-software-src/opensbi
[submodule "support/scripts/kconfig"]
path = support/scripts/kconfig
url = https://github.com/linux-kdevops/kconfig.git
140 changes: 140 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
mainmenu "Runikraft/0.1.0 Configuration"

menu "Memory and CPU Configuration"
config HEAP_SIZE
int "Heap size(MiB)"
default 16

config STACK_SIZE_PAGE_ORDER
int "Page order of stack size(log STACK_SIZE)"
default 4

menu "Limit Configuration"
config MEMORY_SIZE
int "the maximum size of memory(B)"
default -1
help
-1: unlimited

config OPEN_FILES
int "the maximum size of open files"
default 1024

config PIPE_FILES
int "the maximum size of pipe files"
default 4096

config CPU_TIME
int "the limit of CPU time(ms)"
default -1
help
-1: Duration::MAX
endmenu

config LCPU_MAXCOUNT
int "the maximum count of CPU(less than 8)"
default 8

config MAIN_STACK_SIZE
int "the main stack size(B)"
default 65536

config PAGE_SZIE
int "the page size(B)"
default 4096
endmenu

menu "Library Configuration"
menu "rkplat features"
config has_smp
bool "Symmetric multiprocessor support"
default y

config save_fp
bool "Save floating point registers when thread switches"
default n

config driver_uart
bool "Uart device driver"
default n

config driver_ns16550
bool "ns16550 driver"
default y
select driver_uart

config driver_virtio
bool "Virtio driver"
default n
help
Depend on volatile-v0.3 and bitflags-v1.3

config driver_virtio_blk
bool "Virtio block driver"
default y
select driver_virtio

config driver_virtio_console
bool "Virtio console driver"
default y
select driver_virtio

config driver_virtio_gpu
bool "Virtio GPU driver"
default y
select driver_virtio

config driver_virtio_input
bool "Virtio input driver"
default y
select driver_virtio

config driver_virtio_net
bool "Virtio net driver"
default y
select driver_virtio

config driver_rtc
bool "Real time clock driver"
default n

config driver_goldfish_rtc
bool "Goldfish real time clock driver"
default y
select driver_rtc

config bios_io
bool "Use BIOS to output"
default n
endmenu

menu "rkboot features"
config have_scheduler
bool "Have scheduler"
help
Depend on rksched

config sched_coop
bool "Cooperative scheduler"
default y
select have_scheduler
help
Depend on rksched and rkschedcoop
endmenu
endmenu

menu "Make Build Configuration"
choice
prompt "Make build type"
default debug

config debug
bool "debug type"
help
Compile without "--release"
config release
bool "release type"
help
Compile with "--release"
endchoice
endmenu
76 changes: 57 additions & 19 deletions makefile → Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# makefile for Runikraft

# Authors: 张子辰 <[email protected]>
# 陈建绿 <[email protected]>

# Copyright (C) 2022 吴骏东, 张子辰, 蓝俊玮, 郭耸霄 and 陈建绿.

Expand Down Expand Up @@ -39,37 +40,49 @@ export MAKE_ROOT_DIR := $(PWD)/build
export REPORT_ROOT_DIR := $(PWD)/report
export TEST_ROOT_DIR := $(PWD)/test
export SRC_ROOT_DIR := $(PWD)
export MAKE_BUILD_TYPE := debug
export CROSS_COMPILE := riscv64-linux-gnu-
TEST_LIST := @all
IGNORED_LIST :=

.PHONY: all
export PROJECT = Runikraft
export VERSION = 0
export PATCHLEVEL = 1
export SUBLEVEL = 0
export EXTRAVERSION =

CONFIG_DIR := $(MAKE_ROOT_DIR)/config
SUPPORT_DIR := $(SRC_ROOT_DIR)/support
SCRIPTS_DIR := $(SUPPORT_DIR)/scripts
export KCONFIG_DIR := $(SCRIPTS_DIR)/kconfig

PHNOY += all
all: test

.PHONY: everything
PHNOY += everything
everything: all report

.PHONY: report
PHNOY += report
report: $(MAKE_ROOT_DIR)/report/makefile
cd "$(MAKE_ROOT_DIR)/report" && $(MAKE)

$(MAKE_ROOT_DIR)/report/makefile: makefiles/report.mk
-mkdir --parents "$(MAKE_ROOT_DIR)/report"
cp makefiles/report.mk "$(MAKE_ROOT_DIR)/report/makefile"

.PHONY: test build_test $(MAKE_ROOT_DIR)/test/makefile
PHNOY += test
test: $(MAKE_ROOT_DIR)/test/makefile opensbi
cd "$(MAKE_ROOT_DIR)/test" && $(MAKE)

PHNOY += build_test
build_test: $(MAKE_ROOT_DIR)/test/makefile
cd "$(MAKE_ROOT_DIR)/test" && $(MAKE) build

PHNOY += $(MAKE_ROOT_DIR)/test/makefile
$(MAKE_ROOT_DIR)/test/makefile: makefiles/test.mk.sh makefiles/test.mk.0 makefiles/test.mk.1
-mkdir --parents "$(MAKE_ROOT_DIR)/test"
makefiles/test.mk.sh makefiles/test.mk "$(MAKE_ROOT_DIR)/test/makefile" "$(TEST_ROOT_DIR)" "$(TEST_LIST)" "$(IGNORED_LIST)" "$(MAKE_ROOT_DIR)/opensbi/platform/generic/firmware/fw_jump.bin"

.PHONY: opensbi
PHNOY += opensbi
opensbi:
#FW_OPTIONS=1 indicates quiet boot
-mkdir --parents "$(MAKE_ROOT_DIR)/opensbi"
Expand All @@ -78,26 +91,51 @@ opensbi:
$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib: $(SRC_ROOT_DIR)/lib/rkalloc/alloc_error_handler.rs
@env RUSTC_BOOTSTRAP=1 rustc --edition=2021 $(SRC_ROOT_DIR)/lib/rkalloc/alloc_error_handler.rs --crate-type lib --target riscv64gc-unknown-none-elf -o $(MAKE_ROOT_DIR)/liballoc_error_handler.rlib

$(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(MAKE_BUILD_TYPE)/deps/liballoc_error_handler.rlib: $(MAKE_ROOT_DIR)/liballoc_error_handler.rlib
@-mkdir --parents $(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(MAKE_BUILD_TYPE)/deps/
@cp $(MAKE_ROOT_DIR)/liballoc_error_handler.rlib $(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(MAKE_BUILD_TYPE)/deps/liballoc_error_handler.rlib

$(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(shell cat $(CONFIG_DIR)/features2.txt)/deps/liballoc_error_handler.rlib: $(MAKE_ROOT_DIR)/liballoc_error_handler.rlib $(CONFIG_DIR)/features2.txt
@-mkdir --parents $(TEST_BUILD_DIR)/deps
@cp $(MAKE_ROOT_DIR)/liballoc_error_handler.rlib $(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(shell cat $(CONFIG_DIR)/features2.txt)/deps/liballoc_error_handler.rlib

.PHONY: example run
example: $(MAKE_ROOT_DIR)/liballoc_error_handler.rlib $(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(MAKE_BUILD_TYPE)/deps/liballoc_error_handler.rlib
ifeq ($(MAKE_BUILD_TYPE), release)
cd example/sudoku && env RUSTFLAGS="-Clink-arg=-T$(SRC_ROOT_DIR)/linker.ld --cfg __alloc_error_handler --extern __alloc_error_handler=$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib" cargo build --release
PHNOY += example
example: $(MAKE_ROOT_DIR)/liballoc_error_handler.rlib $(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(shell cat $(CONFIG_DIR)/features2.txt)/deps/liballoc_error_handler.rlib $(CONFIG_DIR)/features1.txt $(CONFIG_DIR)/features2.txt
ifeq ($(shell cat $(CONFIG_DIR)/features2.txt), release)
cd example/sudoku && env RUSTFLAGS="-Clink-arg=-T$(SRC_ROOT_DIR)/linker.ld --cfg __alloc_error_handler --extern __alloc_error_handler=$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib" cargo build --release $(shell cat $(CONFIG_DIR)/features1.txt)
else
ifeq ($(MAKE_BUILD_TYPE), debug)
cd example/sudoku && env RUSTFLAGS="-Clink-arg=-T$(SRC_ROOT_DIR)/linker.ld --cfg __alloc_error_handler --extern __alloc_error_handler=$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib" cargo build
ifeq ($(shell cat $(CONFIG_DIR)/features2.txt), debug)
cd example/sudoku && env RUSTFLAGS="-Clink-arg=-T$(SRC_ROOT_DIR)/linker.ld --cfg __alloc_error_handler --extern __alloc_error_handler=$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib" cargo build $(shell cat $(CONFIG_DIR)/features1.txt)
else
@echo "Unknown build type, expect release/debug."
false
endif
endif
$(CROSS_COMPILE)objcopy --strip-all "$(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(MAKE_BUILD_TYPE)/sudoku" -O binary "$(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(MAKE_BUILD_TYPE)/sudoku.bin"

$(CROSS_COMPILE)objcopy --strip-all "$(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(shell cat $(CONFIG_DIR)/features2.txt)/sudoku" -O binary "$(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(shell cat $(CONFIG_DIR)/features2.txt)/sudoku.bin"

PHNOY += run
run:
qemu-system-riscv64 -machine virt -kernel "$(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(MAKE_BUILD_TYPE)/sudoku.bin" -device virtio-gpu-device,xres=1280,yres=800 -serial mon:stdio -device virtio-keyboard-device -device virtio-rng-device -bios "$(MAKE_ROOT_DIR)/opensbi/platform/generic/firmware/fw_jump.bin"
qemu-system-riscv64 -machine virt -kernel "$(MAKE_ROOT_DIR)/riscv64gc-unknown-none-elf/$(shell cat $(CONFIG_DIR)/features2.txt)/sudoku.bin" -device virtio-gpu-device,xres=1280,yres=800 -serial mon:stdio -device virtio-keyboard-device -device virtio-rng-device -bios "$(MAKE_ROOT_DIR)/opensbi/platform/generic/firmware/fw_jump.bin"

$(CONFIG_DIR)/features1.txt: menuconfig
$(CONFIG_DIR)/features2.txt: menuconfig

PHNOY += menuconfig
menuconfig: $(KCONFIG_DIR)/mconf include/config/project.release $(CONFIG_DIR)/handle_config
@$< Kconfig
@mkdir -p $(CONFIG_DIR)
@$(CONFIG_DIR)/handle_config $(SRC_ROOT_DIR) $(CONFIG_DIR)

include $(SCRIPTS_DIR)/objects.Makefile

$(CONFIG_DIR)/handle_config: $(SUPPORT_DIR)/handle_config.cpp
@mkdir -p $(CONFIG_DIR)
@g++ $(SUPPORT_DIR)/handle_config.cpp -o $(CONFIG_DIR)/handle_config

PHONY += clean
clean:
$(MAKE) -f $(SCRIPTS_DIR)/build.Makefile $@

PHONY += help
help:
@echo "Configuration options:"
@echo "menuconfig - demos the menuconfig functionality"
@echo " configuration options will be written in $(CONFIG_DIR)/config.rs"

.PHONY: $(PHONY)
31 changes: 14 additions & 17 deletions default_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
// permitted in any medium without royalty provided the copyright notice and
// this notice are preserved. This file is offered as-is, without any warranty.

pub const LIBUKNETDEV_MAXNBQUEUES: usize = 1;
pub const RK_NETDEV_SCRATCH_SIZE: usize = 0;
pub const HEAP_SIZE: usize = 16<<20;

pub mod rksched {
pub const STACK_SIZE_PAGE_ORDER: usize = 4;
pub const STACK_SIZE: usize = super::rkplat::PAGE_SIZE*(1<<STACK_SIZE_PAGE_ORDER);
pub mod limit {
use core::time::Duration;
pub const MEMORY_SIZE: usize = usize::MAX;
pub const OPEN_FILES: usize = 1024;
pub const PIPE_SIZE: usize = 4096;
pub const CPU_TIME: Duration = Duration::MAX;
}
}

/// rkplat配置
pub mod rkplat{
/// 处理器的最大数量
pub const LCPU_MAXCOUNT: usize = 16;
pub const LCPU_MAXCOUNT: usize = 8;
/// 主线程的栈的大小
pub const MAIN_STACK_SIZE: usize = 65536;
pub const PAGE_SIZE: usize = 4096;
Expand All @@ -23,17 +34,3 @@ pub const STACK_SIZE_SCALE: usize = 10;

#[cfg(not(debug_assertions))]
pub const STACK_SIZE_SCALE: usize = 1;

pub const HEAP_SIZE: usize = 16<<20;

pub mod rksched {
pub const STACK_SIZE_PAGE_ORDER: usize = 4;
pub const STACK_SIZE: usize = super::rkplat::PAGE_SIZE*(1<<STACK_SIZE_PAGE_ORDER);
pub mod limit {
use core::time::Duration;
pub const MEMORY_SIZE: usize = usize::MAX;
pub const OPEN_FILES: usize = 1024;
pub const PIPE_SIZE: usize = 4096;
pub const CPU_TIME: Duration = Duration::MAX;
}
}
2 changes: 1 addition & 1 deletion makefiles/test.mk.0
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- makefile -*-
# 在运行时,该文件将被复制到build/test

TEST_BUILD_DIR := $(MAKE_ROOT_DIR)/test/riscv64gc-unknown-none-elf/$(MAKE_BUILD_TYPE)
TEST_BUILD_DIR := $(MAKE_ROOT_DIR)/test/riscv64gc-unknown-none-elf/debug

.PHONY: all build run

Expand Down
11 changes: 1 addition & 10 deletions makefiles/test.mk.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
.PHONY: @[email protected]

@[email protected]: $(MAKE_ROOT_DIR)/liballoc_error_handler.rlib $(TEST_BUILD_DIR)/deps/liballoc_error_handler.rlib
ifeq ($(MAKE_BUILD_TYPE), release)
@cd $(TEST_ROOT_DIR)/@testname@ && env RUSTFLAGS="-Clink-arg=-T$(SRC_ROOT_DIR)/linker.ld --cfg __alloc_error_handler --extern __alloc_error_handler=$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib" cargo build --offline --release
else
ifeq ($(MAKE_BUILD_TYPE), debug)
@cd $(TEST_ROOT_DIR)/@testname@ && env RUSTFLAGS="-Clink-arg=-T$(SRC_ROOT_DIR)/linker.ld --cfg __alloc_error_handler --extern __alloc_error_handler=$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib" cargo build --offline
else
@echo "Unknown build type, expect release/debug."
false
endif
endif
@cd $(TEST_ROOT_DIR)/@testname@ && env RUSTFLAGS="-Clink-arg=-T$(SRC_ROOT_DIR)/linker.ld --cfg __alloc_error_handler --extern __alloc_error_handler=$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib" cargo build --offline
@rm $(TEST_ROOT_DIR)/@testname@/Cargo.lock
@$(CROSS_COMPILE)objcopy --strip-all $(TEST_BUILD_DIR)/test-@testname@ -O binary @[email protected]
2 changes: 2 additions & 0 deletions support/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Support
scripts 中的内容修改自 https://github.com/mcgrof/init-kconfig 中的同名文件夹。
Loading

0 comments on commit fbbb389

Please sign in to comment.