Skip to content

Commit 9dd1aed

Browse files
marc-hbItaru Kitayama
authored andcommitted
run_qemu.sh: add new --qmachine argument
Initial support for q35 and "virt". Default to the host architecture. Progress towards supporting ARM64 as discussed in pmem#140, pmem#143 and others. Signed-off-by: Marc Herbert <[email protected]>
1 parent d0ddde0 commit 9dd1aed

File tree

2 files changed

+54
-14
lines changed

2 files changed

+54
-14
lines changed

parser_generator.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
echo "This is just a parsing library template, not the library - pass this file to 'argbash' to fix this." >&2
55
exit 11 #)Created by argbash-init v2.9.0
66
# Rearrange the order of options below according to what you would like to see in the help message.
7+
# ARG_OPTIONAL_SINGLE([qmachine], , [QEMU machine: q35, virt,... Defaults to host architecture])
78
# ARG_OPTIONAL_SINGLE([rootfs], , [Non-default rootfs image to use], [root.img])
89
# ARG_OPTIONAL_SINGLE([rebuild], [r], [Choose one of:\n wipe: wipe builddir, removing package cache\n imgcache: remove mkosi's cached pre-images to rebuild the image without an 'incremental build'\n img: rebuild rootfs from scratch and kernel\n kmod: rebuild kernel, update rootfs modules\n none: don't rebuild anything, start qemu\n], [kmod])
910
# ARG_OPTIONAL_BOOLEAN([strip-modules], , [Strip kernel modules after they are installed], [off])

run_qemu.sh

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ legacy_pmem_size="2" #in GiB
1313
pmem_size="16384" #in MiB
1414
pmem_label_size=2 #in MiB
1515
pmem_final_size="$((pmem_size + pmem_label_size))"
16-
: "${qemu:=qemu-system-x86_64}"
1716
: "${gdb:=gdb}"
1817
: "${ndctl:=$(readlink -e ~/git/ndctl)}"
1918
selftests_home=root/built-selftests
@@ -87,6 +86,51 @@ fail()
8786
exit 1
8887
}
8988

89+
set_qemu_machine()
90+
{
91+
if test -n "$_arg_qmachine"; then
92+
qemu_machine="$_arg_qmachine"
93+
return
94+
fi
95+
96+
case "${host_arch}" in
97+
x86_64)
98+
qemu_machine=q35
99+
;;
100+
aarch)
101+
qemu_machine=virt
102+
;;
103+
*) fail 'Unknown host architecture';;
104+
esac
105+
}
106+
107+
# If this grows too big, switch to sourcing separate ${qemu_machine}.sh files
108+
set_guest_params()
109+
{
110+
case "${qemu_machine}" in
111+
q35)
112+
guest_arch_toolchain=x86_64
113+
guest_arch_linux=x86_64
114+
machine_args=('q35')
115+
;;
116+
virt)
117+
guest_arch_toolchain=aarch64
118+
guest_arch_linux=arm64
119+
machine_args=('virt')
120+
;;
121+
*)
122+
fail "Unknown QEMU machine=%s" "$qemu_machine";;
123+
esac
124+
test -n "$qemu" || qemu=qemu-system-"$guest_arch_linux"
125+
}
126+
127+
arch_init()
128+
{
129+
host_arch=$(uname -m)
130+
set_qemu_machine
131+
set_guest_params
132+
}
133+
90134
script_dir="$(cd "$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")" && pwd)"
91135
parser_generator="${script_dir}/parser_generator.m4"
92136
parser_lib="${script_dir}/run_qemu_parser.sh"
@@ -327,6 +371,9 @@ process_options_logic()
327371
if [[ $_arg_debug == "on" ]]; then
328372
set -x
329373
fi
374+
375+
arch_init
376+
330377
if [[ $_arg_cxl_test_run == "on" ]]; then
331378
_arg_cxl_debug="on"
332379
_arg_cxl_test="on"
@@ -447,11 +494,7 @@ make_install_kernel()
447494
exit 1
448495
}
449496

450-
if [[ $(arch) != "aarch64" ]]; then
451-
cat arch/x86_64/boot/bzImage > "$inst_path"/vmlinuz-"$kver"
452-
else
453-
cat arch/arm64/boot/Image > "$inst_path"/vmlinuz-"$kver"
454-
fi
497+
cat arch/"${guest_arch_linux}"/boot/*Image > "$inst_path"/vmlinuz-"$kver"
455498
cp System.map "$inst_path"/System.map-"$kver"
456499
ln -fs vmlinuz-"$kver" "$inst_path"/vmlinuz
457500
ln -fs System.map-"$kver" "$inst_path"/System.map
@@ -929,7 +972,9 @@ __update_existing_rootfs()
929972
local _trace_sh='-x'
930973
fi
931974
#shellcheck disable=SC2086
932-
sudo -E bash $_trace_sh -e -c "$(declare -f make_install_kernel); kver=$kver make_install_kernel $inst_path"
975+
sudo -E bash $_trace_sh -e -c "$(declare -f make_install_kernel);
976+
kver=$kver guest_arch_linux=$guest_arch_linux
977+
make_install_kernel $inst_path"
933978

934979
if [[ $_arg_cxl_test == "off" ]]; then
935980
sudo rm -f "$inst_prefix"/usr/lib/modules/"$kver"/extra/cxl_*.ko
@@ -1533,13 +1578,7 @@ prepare_qcmd()
15331578
if [[ $_arg_kvm = "off" ]]; then
15341579
accel="tcg" # the default
15351580
fi
1536-
1537-
if [[ $(arch) != "aarch64" ]]; then
1538-
machine_args=("q35" "accel=$accel")
1539-
else
1540-
machine_args=("virt,highmem=on,gic-version=3" "accel=$accel")
1541-
fi
1542-
1581+
machine_args+=("accel=$accel")
15431582
if [[ "$num_pmems" -gt 0 ]]; then
15441583
machine_args+=("nvdimm=on")
15451584
fi

0 commit comments

Comments
 (0)