Skip to content

Commit 680ca37

Browse files
committed
buildtools: feat #135: Check the version of QEMU ahead
1 parent b7ce254 commit 680ca37

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

os/Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,23 @@ QEMU_ARGS := -machine virt \
6060
-bios $(BOOTLOADER) \
6161
-device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA)
6262

63-
run-inner: build
63+
QEMU_NAME := qemu-system-riscv64
64+
qemu-version-check:
65+
@sh scripts/qemu-ver-check.sh $(QEMU_NAME)
66+
67+
run-inner: qemu-version-check build
6468
@qemu-system-riscv64 $(QEMU_ARGS)
6569

66-
debug: build
70+
debug: qemu-version-check build
6771
@tmux new-session -d \
6872
"qemu-system-riscv64 $(QEMU_ARGS) -s -S" && \
6973
tmux split-window -h "riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'" && \
7074
tmux -2 attach-session -d
7175

72-
gdbserver: build
76+
gdbserver: qemu-version-check build
7377
@qemu-system-riscv64 $(QEMU_ARGS) -s -S
7478

7579
gdbclient:
7680
@riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'
7781

78-
.PHONY: build env kernel clean disasm disasm-vim run-inner gdbserver gdbclient
82+
.PHONY: build env kernel clean disasm disasm-vim run-inner gdbserver gdbclient qemu-version-check

os/scripts/qemu-ver-check.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
# Argument1: The filename of qemu executable, e.g. qemu-system-riscv64
4+
QEMU_PATH=$(which $1)
5+
RET=$?
6+
MINIMUM_MAJOR_VERSION=7
7+
RED='\033[0;31m'
8+
GREEN='\033[0;32m'
9+
NC='\033[0m'
10+
if [ $RET != 0 ]
11+
then
12+
echo "$1 not found"
13+
exit 1
14+
else
15+
QEMU_VERSION=$($1 --version|head -n 1|awk '{print $4}')
16+
MAJOR_VERSION=$(echo $QEMU_VERSION|cut -c1-1)
17+
if [ $MAJOR_VERSION -lt $MINIMUM_MAJOR_VERSION ]
18+
then
19+
echo "${RED}Error: Required major version of QEMU is ${MINIMUM_MAJOR_VERSION}, " \
20+
"but current is ${QEMU_VERSION}.${NC}"
21+
exit 1
22+
else
23+
echo "${GREEN}QEMU version is ${QEMU_VERSION}(>=${MINIMUM_MAJOR_VERSION}), OK!${NC}"
24+
exit 0
25+
fi
26+
fi

0 commit comments

Comments
 (0)