Skip to content

Commit d2ceaed

Browse files
committed
buildtools: feat #135: Check the version of QEMU ahead
1 parent c105637 commit d2ceaed

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
@@ -61,19 +61,23 @@ QEMU_ARGS := -machine virt \
6161
-bios $(BOOTLOADER) \
6262
-device loader,file=$(KERNEL_BIN),addr=$(KERNEL_ENTRY_PA)
6363

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

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

73-
gdbserver: build
77+
gdbserver: qemu-version-check build
7478
@qemu-system-riscv64 $(QEMU_ARGS) -s -S
7579

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

79-
.PHONY: build env kernel clean disasm disasm-vim run-inner gdbserver gdbclient
83+
.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)