mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-24 13:13:24 +00:00
使得DragonOS kernel 能为riscv64编译通过(尚未能启动) (#457)
* 使得DragonOS kernel 能为riscv64编译通过(尚未能启动) * 修正了系统调用号声明不正确的问题,同时添加了编译配置文档
This commit is contained in:
@ -15,11 +15,21 @@ LDFLAGS_UNWIND =
|
||||
RUSTFLAGS_UNWIND =
|
||||
ifeq ($(UNWIND_ENABLE), yes)
|
||||
CFLAGS_UNWIND = -funwind-tables
|
||||
ifeq ($(ARCH), x86_64)
|
||||
LDFLAGS_UNWIND = --eh-frame-hdr
|
||||
endif
|
||||
RUSTFLAGS_UNWIND = -Cforce-unwind-tables -Clink-arg=-Wl,eh_frame.ld
|
||||
endif
|
||||
|
||||
CFLAGS = $(GLOBAL_CFLAGS) -fno-pie $(CFLAGS_UNWIND) -I $(shell pwd) -I $(shell pwd)/include -I $(shell pwd)/arch/x86_64/include
|
||||
RUSTFLAGS = $(RUSTFLAGS_UNWIND)
|
||||
|
||||
CFLAGS = $(GLOBAL_CFLAGS) -fno-pie $(CFLAGS_UNWIND) -I $(shell pwd) -I $(shell pwd)/include
|
||||
|
||||
ifeq ($(ARCH), x86_64)
|
||||
CFLAGS += -I $(shell pwd)/arch/x86_64/include
|
||||
else ifeq ($(ARCH), riscv64)
|
||||
CFLAGS += -I $(shell pwd)/arch/riscv64/include
|
||||
endif
|
||||
|
||||
export ASFLAGS := --64
|
||||
|
||||
@ -30,12 +40,47 @@ kernel_subdirs := common driver debug exception smp syscall ktest libs time
|
||||
|
||||
|
||||
kernel_rust:
|
||||
RUSTFLAGS="$(RUSTFLAGS_UNWIND)" cargo +nightly-2023-01-21 build --release --target ./arch/x86_64/x86_64-unknown-none.json
|
||||
ifeq ($(ARCH), riscv64)
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2023-01-21 $(CARGO_ZBUILD) build --release --target riscv64imac-unknown-none-elf
|
||||
else
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2023-01-21 $(CARGO_ZBUILD) build --release --target $(TARGET_JSON)
|
||||
endif
|
||||
|
||||
all: kernel
|
||||
|
||||
# if x86_64
|
||||
ifeq ($(ARCH), x86_64)
|
||||
$(MAKE) __link_x86_64_kernel
|
||||
else ifeq ($(ARCH), riscv64)
|
||||
$(MAKE) __link_riscv64_kernel
|
||||
endif
|
||||
|
||||
@echo "Kernel Build Done."
|
||||
|
||||
ECHO:
|
||||
@echo "$@"
|
||||
|
||||
$(kernel_subdirs): ECHO
|
||||
|
||||
$(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" kernel_root_path="$(shell pwd)"
|
||||
|
||||
kernel: $(kernel_subdirs) kernel_rust
|
||||
|
||||
__link_riscv64_kernel:
|
||||
@echo "Linking kernel..."
|
||||
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds --no-relax
|
||||
$(LD) -b elf64-littleriscv -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/riscv64imac-unknown-none-elf/release/libdragonos_kernel.a -T arch/riscv64/link.ld --no-relax
|
||||
$(OBJCOPY) -I elf64-littleriscv -O elf64-littleriscv -R ".eh_frame" kernel ../../bin/kernel/kernel.elf
|
||||
rm kernel
|
||||
|
||||
# 构建uboot的scr文件
|
||||
@echo "Generating kernel scr file..."
|
||||
@mkdir -p $(ROOT_PATH)/bin/sysroot/boot/
|
||||
@mkimage -A riscv -T script -d arch/riscv64/boot/bootscript.cmd $(ROOT_PATH)/bin/sysroot/boot/boot.scr
|
||||
|
||||
|
||||
__link_x86_64_kernel:
|
||||
@echo "Linking kernel..."
|
||||
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T arch/x86_64/link.lds --no-relax
|
||||
# 生成kallsyms
|
||||
current_dir=$(pwd)
|
||||
|
||||
@ -49,7 +94,7 @@ all: kernel
|
||||
# 重新链接
|
||||
@echo "Re-Linking kernel..."
|
||||
@echo $(shell find . -name "*.o")
|
||||
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T link.lds --no-relax
|
||||
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T arch/x86_64/link.lds --no-relax
|
||||
@echo "Generating kernel ELF file..."
|
||||
# 生成内核文件
|
||||
ifeq ($(UNWIND_ENABLE), yes)
|
||||
@ -57,21 +102,10 @@ ifeq ($(UNWIND_ENABLE), yes)
|
||||
else
|
||||
$(OBJCOPY) -I elf64-x86-64 -O elf64-x86-64 -R ".eh_frame" kernel ../../bin/kernel/kernel.elf
|
||||
endif
|
||||
@echo "Kernel Build Done."
|
||||
|
||||
ECHO:
|
||||
@echo "$@"
|
||||
|
||||
$(kernel_subdirs): ECHO
|
||||
|
||||
$(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" kernel_root_path="$(shell pwd)"
|
||||
|
||||
kernel: $(kernel_subdirs) kernel_rust
|
||||
|
||||
|
||||
rm kernel
|
||||
|
||||
clean:
|
||||
cargo clean
|
||||
@cargo clean
|
||||
rm -rf $(GARBAGE)
|
||||
@list='$(kernel_subdirs)'; for subdir in $$list; do \
|
||||
echo "Clean in dir: $$subdir";\
|
||||
|
Reference in New Issue
Block a user