Commit b3a246ab authored by SSSTTTLLL's avatar SSSTTTLLL
Browse files

修改la64.mk和preload_app.S文件

parent be303d5a
No related merge requests found
Showing with 139 additions and 175 deletions
+139 -175
......@@ -30,6 +30,12 @@ rv64-run:
la64-only:
make -f make/la64.mk all BLK_MODE=${BLK_MODE}
la64-kernel-build-only:
make -f make/la64.mk build BLK_MODE=${BLK_MODE} MODE=${MODE} LOG=${LOG}
la64-debug:
make -f make/la64.mk all BLK_MODE=${BLK_MODE} MODE=debug
la64-run-only:
make -f make/la64.mk runsimple
......@@ -44,6 +50,9 @@ clean:
make ARCH=$$arch -f make/$$arch.mk clean; \
done
laclean:
make -f make/la64.mk clean
fs-img:
make -f make/$(CURR_ARCH).mk fs-img FS_MODE=$(FS_MODE)
......@@ -54,4 +63,7 @@ gdb:
make -f make/$(CURR_ARCH).mk gdb
rv64-gdb: rv64-debug
make -f make/rv64.mk comp-gdb
\ No newline at end of file
make -f make/rv64.mk comp-gdb
la64-gdb: la64-debug
make -f make/la64.mk comp-gdb
\ No newline at end of file
# run: 清除编译结果,重新编译,运行
# all: 直接编译,并把.bin内核拷贝到根目录(适配大赛要求)
# gdb: 只运行gdb(需要先通过make run来编译)
# clean: 清除编译结果
SUDO := $(shell if [ "$$(whoami)" = "root" ]; then echo ""; else echo "sudo"; fi)
ARCH := loongarch64
# Target configuration
TARGET := loongarch64-unknown-linux-gnu
MODE := debug
MODE := release
KERNEL_ELF := target/$(TARGET)/$(MODE)/os
KERNEL_BIN := $(KERNEL_ELF).bin
DISASM_TMP := target/$(TARGET)/$(MODE)/asm
BLK_MODE := virt
FS_MODE ?= ext4
CORE_NUM ?= 1
BIOS ?= ../util/qemu-2k1000/gz/u-boot-with-spl.bin
QEMU ?= ../util/qemu-2k1000/tmp/qemu/bin/qemu-system-loongarch64
KERNEL_ELF = target/$(TARGET)/$(MODE)/os
KERNEL_BIN = $(KERNEL_ELF).bin
KERNEL_UIMG = $(KERNEL_ELF).ui
ROOTFS_IMG_NAME := rootfs-la.img
ROOTFS_IMG_DIR := ../fs-img-dir
CORE_NUM := 1
LOG := off
KERNEL_LA := ../kernel-la
SDCARD_LA := ../sdcard-la.img
# BOARD
BOARD ?= laqemu
LDBOARD = la2k1000
COMP ?= yes
LOG := error
# 大写K转小写
ifeq ($(BOARD), 2K1000)
BOARD = 2k1000
else ifeq ($(BOARD), K210)
BOARD = k210
# SBI config (can be simplified later)
SBI ?= opensbi-1.0
ifeq ($(BOARD), laqemu)
ifeq ($(SBI), rustsbi)
BOOTLOADER := ../bootloader/$(SBI)-$(BOARD).bin
else ifeq ($(SBI), default)
BOOTLOADER := default
else
BOOTLOADER := ../bootloader/fw_payload.bin
endif
else ifeq ($(BOARD), vf2)
BOOTLOADER := ../bootloader/rustsbi-$(BOARD).bin
endif
# 块设备类型
BLK_MODE ?= mem
# Logging config
LOG_OPTION := log_$(LOG)
# KERNEL entry address
KERNEL_ENTRY_PA := 0x9000000090000000
# Binutils
OBJCOPY := loongarch64-linux-gnu-objcopy
OBJDUMP := loongarch64-linux-gnu-objdump
READELF := loongarch64-linux-gnu-readelf
OBJDUMP := rust-objdump --arch-name=loongarch64
OBJCOPY := rust-objcopy --binary-architecture=loongarch64
ifndef LOG
LOG_OPTION := "log_off"
# Applications
APPS := ../user/src/bin/*
# FS image
ifeq ($(BOARD), vf2)
ROOTFS_IMG := /dev/sdc
else
LOG_OPTION := "log_${LOG}"
ROOTFS_IMG := ${ROOTFS_IMG_DIR}/${ROOTFS_IMG_NAME}
endif
ifeq ($(MODE), debug)
LA_2k1000_DISABLE_EH_FRAME := -D EH_ENABLED
endif
# Build rules
all: fs-img build
IMG_DIR := ../fs-img-dir
IMG_NAME = rootfs-ubifs-ze.img
IMG := ${IMG_DIR}/$(IMG_NAME)
IMG_LN = $(shell readlink -f $(IMG_DIR))/$(IMG_NAME)
QEMU_2k1000_DIR=../util/qemu-2k1000/gz
QEMU_2k1000=$(QEMU_2k1000_DIR)/runqemu2k1000
U_IMG=$(IMG_DIR)/uImage
LA_DEBUGGER_SERIAL_PORT = $$(python3 -m serial.tools.list_ports 1A86:7523 -q | head -n 1)
LA_DEBUGGER_PORT_FREQ = $(LA_DEBUGGER_SERIAL_PORT) 115200
LA_2k1000_SERIAL_PORT = $$(python3 -m serial.tools.list_ports 067B:2303 -q | head -n 1)
LA_2k1000_PORT_FREQ = $(LA_2k1000_SERIAL_PORT) 115200
MINITERM_START_CMD=python3 -m serial.tools.miniterm --dtr 0 --rts 0 --filter direct
LA_ENTRY_POINT = 0x9000000090000000
LA_LOAD_ADDR = 0x9000000090000000
runsimple: env update-usr
qemu-system-loongarch64 \
-machine virt \
-kernel ${KERNEL_ELF} \
-m 1024 \
-nographic \
-smp threads=${CORE_NUM} \
-no-reboot \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::5555-:5555,hostfwd=udp::5555-:5555 \
-rtc base=utc
run: do-run
mv:
cp -f $(KERNEL_ELF) $(KERNEL_LA)
comp:
qemu-system-loongarch64 \
-kernel ../kernel-la \
-m 1G \
-nographic \
-smp 1 \
-drive file=../sdcard-la.img,if=none,format=raw,id=x0 \
-device virtio-blk-pci,drive=x0 \
-no-reboot \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0 \
-rtc base=utc
comp-1:
qemu-system-loongarch64 \
-kernel {os_file} \
-m {mem} \
-nographic \
-smp {smp} \
-drive file={fs},if=none,format=raw,id=x0 \
-device virtio-blk-pci,drive=x0,bus=virtio-mmio-bus.0 \
-no-reboot \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::5555-:5555,hostfwd=udp::5555-:5555 \
-rtc base=utc \
-drive file=disk-la.img,if=none,format=raw,id=x1 \
-device virtio-blk-pci,drive=x1,bus=virtio-mmio-bus.1
# 更新用户态程序
update-usr: fs-img
# 编译用户态程序
user: env
@cd ../user && make rust-user BOARD=$(BOARD) MODE=$(MODE)
build: env $(KERNEL_BIN) mv
# 生成根文件系统镜像
fs-img: user
ifeq ($(BOARD),laqemu)
@$(SUDO) rm -rf $(IMG)
./buildfs.sh "$(IMG)" "laqemu" $(MODE) $(FS_MODE)
else
./buildfs.sh "$(IMG)" 2k1000 $(MODE) $(FS_MODE)
endif
env:
(rustup target list | grep "$(TARGET) (installed)") || rustup target add $(TARGET)
(rustup target list | grep "loongarch64-unknown-linux-gnu (installed)") || rustup target add loongarch64-unknown-linux-gnu
rustup component add rust-src
rustup component add llvm-tools-preview
# 仅更新内核并运行
run-inner: uimage do-run
# build all user programs
user:
@cd ../user && make rust-user BOARD=$(BOARD) MODE=$(MODE)
# 将内核转换为二进制文件
$(KERNEL_BIN): kernel
@$(OBJCOPY) $(KERNEL_ELF) $@ --strip-all -O binary &
@$(OBJDUMP) $(KERNEL_ELF) -SC > target/$(TARGET)/$(MODE)/asm_all.txt
@$(READELF) -ash $(KERNEL_ELF) > target/$(TARGET)/$(MODE)/sec.txt &
@$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@
fs-img: user
./buildfs.sh "$(ROOTFS_IMG)" "$(BOARD)" $(MODE) $(FS_MODE)
# 编译内核
kernel:
@echo Platform: $(BOARD)
ifeq ($(MODE), debug)
@LOG=$(LOG) cargo build --no-default-features --features "comp board_$(BOARD) block_$(BLK_MODE) $(LOG_OPTION)" --target $(TARGET)
else
@LOG=$(LOG) cargo build --no-default-features --release --features "comp board_$(BOARD) block_$(BLK_MODE) $(LOG_OPTION)" --target $(TARGET)
endif
# 更新内核
uimage: env $(KERNEL_BIN)
../util/mkimage -A loongarch -O linux -T kernel -C none -a $(LA_LOAD_ADDR) -e $(LA_ENTRY_POINT) -n NPUcore+ -d $(KERNEL_BIN) $(KERNEL_UIMG)
-@$(SUDO) rm $(U_IMG)
@$(SUDO) cp -f $$(pwd)/target/$(TARGET)/$(MODE)/os.ui $(U_IMG)
do-run:
ifeq ($(BOARD), laqemu)
# 将镜像链接到指定目录
-ln -sf $(IMG_LN) $(QEMU_2k1000_DIR)/$(IMG_NAME)
@echo "========WARNING!========"
@echo "下一个命令是修改后的runqemu2k1000脚本,其中任何潜在的和隐式的“当前工作目录”已被生成的脚本存储路径所替换。"
@./run_script $(QEMU_2k1000)
else ifeq ($(BOARD), 2k1000)
@./run_script $(MINITERM_START_CMD) $(LA_2k1000_PORT_FREQ)
ifeq ($(MODE), debug)
@LOG=$(LOG) cargo build --features "board_$(BOARD) $(LOG_OPTION) block_$(BLK_MODE) oom_handler" --no-default-features --target loongarch64-unknown-linux-gnu
else
@LOG=$(LOG) cargo build --release --features "board_$(BOARD) $(LOG_OPTION) block_$(BLK_MODE) oom_handler" --no-default-features --target loongarch64-unknown-linux-gnu
endif
# 生成根文件系统镜像并编译内核
all: fs-img uimage mv
mv:
cp -f $(KERNEL_ELF) ../kernel-la
clean:
@cargo clean
@rm -rf $(KERNEL_LA)
gdb:
ifeq ($(BOARD),laqemu)
./run_script $(QEMU_2k1000) "-S"
else ifeq ($(BOARD), 2k1000)
@./la_gdbserver minicom -D $(LA_DEBUGGER_PORT_FREQ)
run: build
ifeq ($(BOARD), laqemu)
@qemu-system-loongarch64 \
-machine virt \
-nographic \
-bios $(BOOTLOADER) \
-device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA) \
-drive if=none,file=$(ROOTFS_IMG),format=raw,id=x0 \
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \
-m 1024 \
-smp threads=$(CORE_NUM)
endif
env: # 切换工具链
-(rustup target list | grep "$(TARGET) (installed)") || rustup target add $(TARGET)
ifeq ($(COMP), no)
@if command -v pacman >/dev/null 2>&1; then \
if ! pacman -Q expect >/dev/null 2>&1; then \
sudo pacman -S --noconfirm expect; \
fi \
elif command -v apt >/dev/null 2>&1; then \
if ! dpkg -s expect >/dev/null 2>&1; then \
sudo apt update && sudo apt install -y expect; \
fi \
else \
echo "Error: System has neither pacman nor apt package manager."; \
echo "Please install expect manually and ensure it's in PATH"; \
exit 1; \
fi
else
@echo "COMP is not set to 'no', skipping environment setup"
endif
monitor:
loongarch64-unknown-elf-gdb -ex 'file target/loongarch64-unknown-linux-gnu/debug/os' -ex 'set arch loongarch64' -ex 'target remote localhost:1234'
clean:
@cargo clean
@cd ../user && make clean
gdb:
@qemu-system-loongarch64 \
-machine virt \
-nographic \
-bios $(BOOTLOADER) \
-device loader,file=target/loongarch64-unknown-linux-gnu/debug/os,addr=$(KERNEL_ENTRY_PA) \
-drive file=$(ROOTFS_IMG),if=none,format=raw,id=x0 \
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \
-m 1024 \
-smp threads=$(CORE_NUM) -S -s | tee qemu.log
runsimple:
@qemu-system-loongarch64 \
-machine virt \
-nographic \
-bios $(BOOTLOADER) \
-device loader,file=$(KERNEL_ELF),addr=$(KERNEL_ENTRY_PA) \
-drive file=$(ROOTFS_IMG),if=none,format=raw,id=x0 \
-m 1024 \
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \
-smp threads=$(CORE_NUM)
.PHONY: user update gdb new-gdb monitor .FORCE
comp:
@qemu-system-loongarch64 \
-machine virt \
-kernel $(KERNEL_LA) \
-m 1024 \
-nographic \
-smp 1 \
-drive file=$(SDCARD_LA),if=none,format=raw,id=x0 \
-device virtio-blk-pci,drive=x0\
-no-reboot \
-rtc base=utc
comp-gdb:
@qemu-system-loongarch64 \
-machine virt \
-kernel $(KERNEL_LA) \
-m 1024 \
-nographic \
-smp 1 \
-drive file=$(SDCARD_LA),if=none,format=raw,id=x0 \
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \
-no-reboot \
-rtc base=utc \
-S \
-s
.PHONY: all build kernel fs-img user clean run gdb comp comp-gdb
\ No newline at end of file
......@@ -12,6 +12,6 @@ einitproc:
.global ebash
.align 12
sbash:
.incbin "./bash"
.incbin "./bash-la"
ebash:
.align 12
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment