diff --git a/.gitignore b/.gitignore index b7b91e95..ba8ec73a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ os/target/* os/.idea/* os/src/link_app.S -user/ +os/Cargo.lock diff --git a/bootloader/rustsbi-k210.bin b/bootloader/rustsbi-k210.bin index 5a9fa7d1..e696137a 100755 Binary files a/bootloader/rustsbi-k210.bin and b/bootloader/rustsbi-k210.bin differ diff --git a/bootloader/rustsbi-qemu.bin b/bootloader/rustsbi-qemu.bin index 72742c20..5ccab433 100755 Binary files a/bootloader/rustsbi-qemu.bin and b/bootloader/rustsbi-qemu.bin differ diff --git a/os/Cargo.lock b/os/Cargo.lock deleted file mode 100644 index b85588b1..00000000 --- a/os/Cargo.lock +++ /dev/null @@ -1,5 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "os" -version = "0.1.0" diff --git a/os/Makefile b/os/Makefile index ed60f63c..90a87a54 100644 --- a/os/Makefile +++ b/os/Makefile @@ -3,13 +3,20 @@ TARGET := riscv64gc-unknown-none-elf MODE := release KERNEL_ELF := target/$(TARGET)/$(MODE)/os KERNEL_BIN := $(KERNEL_ELF).bin -KERNEL_ENTRY_PA := 0x80020000 DISASM_TMP := target/$(TARGET)/$(MODE)/asm # BOARD BOARD ?= qemu SBI ?= rustsbi BOOTLOADER := ../bootloader/$(SBI)-$(BOARD).bin +K210_BOOTLOADER_SIZE := 131072 + +# KERNEL ENTRY +ifeq ($(BOARD), qemu) + KERNEL_ENTRY_PA := 0x80200000 +else ifeq ($(BOARD), k210) + KERNEL_ENTRY_PA := 0x80020000 +endif # Run K210 K210-SERIALPORT = /dev/ttyUSB0 @@ -34,7 +41,10 @@ $(KERNEL_BIN): kernel @$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@ kernel: + @echo Platform: $(BOARD) + @cp src/linker-$(BOARD).ld src/linker.ld @cargo build --release + @rm src/linker.ld clean: @cargo clean @@ -58,7 +68,7 @@ ifeq ($(BOARD),qemu) -device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) else @cp $(BOOTLOADER) $(BOOTLOADER).copy - @dd if=$(KERNEL_BIN) of=$(BOOTLOADER).copy bs=131072 seek=1 + @dd if=$(KERNEL_BIN) of=$(BOOTLOADER).copy bs=$(K210_BOOTLOADER_SIZE) seek=1 @mv $(BOOTLOADER).copy $(KERNEL_BIN) @sudo chmod 777 $(K210-SERIALPORT) python3 $(K210-BURNER) -p $(K210-SERIALPORT) -b 1500000 $(KERNEL_BIN) diff --git a/os/src/linker.ld b/os/src/linker-k210.ld similarity index 100% rename from os/src/linker.ld rename to os/src/linker-k210.ld diff --git a/os/src/linker-qemu.ld b/os/src/linker-qemu.ld new file mode 100644 index 00000000..8348a385 --- /dev/null +++ b/os/src/linker-qemu.ld @@ -0,0 +1,45 @@ +OUTPUT_ARCH(riscv) +ENTRY(_start) +BASE_ADDRESS = 0x80200000; + +SECTIONS +{ + . = BASE_ADDRESS; + skernel = .; + + stext = .; + .text : { + *(.text.entry) + *(.text .text.*) + } + + . = ALIGN(4K); + etext = .; + srodata = .; + .rodata : { + *(.rodata .rodata.*) + } + + . = ALIGN(4K); + erodata = .; + sdata = .; + .data : { + *(.data .data.*) + } + + . = ALIGN(4K); + edata = .; + .bss : { + *(.bss.stack) + sbss = .; + *(.bss .bss.*) + } + + . = ALIGN(4K); + ebss = .; + ekernel = .; + + /DISCARD/ : { + *(.eh_frame) + } +} \ No newline at end of file