Skip to content

Commit 29db2e2

Browse files
committed
buildtools: feat #135: Check the version of QEMU ahead
1 parent 3e7b5b2 commit 29db2e2

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

os/Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,23 @@ fdt:
9090
@qemu-system-riscv64 -M 128m -machine virt,dumpdtb=virt.out
9191
fdtdump virt.out
9292

93-
run-inner: build
93+
QEMU_NAME := qemu-system-riscv64
94+
qemu-version-check:
95+
@sh scripts/qemu-ver-check.sh $(QEMU_NAME)
96+
97+
run-inner: qemu-version-check build
9498
@qemu-system-riscv64 $(QEMU_ARGS)
9599

96-
debug: build
100+
debug: qemu-version-check build
97101
@tmux new-session -d \
98102
"qemu-system-riscv64 $(QEMU_ARGS) -s -S" && \
99103
tmux split-window -h "riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'" && \
100104
tmux -2 attach-session -d
101105

102-
103-
gdbserver: build
106+
gdbserver: qemu-version-check build
104107
@qemu-system-riscv64 $(QEMU_ARGS) -s -S
105108

106109
gdbclient:
107110
@riscv64-unknown-elf-gdb -ex 'file $(KERNEL_ELF)' -ex 'set arch riscv:rv64' -ex 'target remote localhost:1234'
108111

109-
.PHONY: build env kernel clean disasm disasm-vim run-inner fs-img gdbserver gdbclient fdt
112+
.PHONY: build env kernel clean disasm disasm-vim run-inner fs-img gdbserver gdbclient fdt 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)