Skip to content

Commit cca3ad2

Browse files
committed
Add initial support for arm64 "virt". Default to host architecture.
Progress towards supporting ARM64 as discussed in pmem#140, pmem#143 and others. Signed-off-by: Marc Herbert <[email protected]>
1 parent 1b5a0f0 commit cca3ad2

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

run_qemu.sh

Lines changed: 49 additions & 4 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
@@ -89,6 +88,47 @@ fail()
8988
exit 1
9089
}
9190

91+
set_qemu_machine()
92+
{
93+
# In the future we could override this with some new --qmachine option
94+
# ARG_OPTIONAL_SINGLE([qmachine] ...
95+
case "${host_arch}" in
96+
x86_64)
97+
qemu_machine=q35
98+
;;
99+
aarch64)
100+
qemu_machine=virt
101+
;;
102+
*) fail 'Unknown host architecture %s' "${host_arch}";;
103+
esac
104+
}
105+
106+
# If this grows too big, switch to sourcing separate ${qemu_machine}.sh files
107+
set_guest_params()
108+
{
109+
case "${qemu_machine}" in
110+
q35)
111+
guest_arch_toolchain=x86_64
112+
guest_arch_linux=x86_64
113+
;;
114+
virt)
115+
guest_arch_toolchain=aarch64
116+
guest_arch_linux=arm64
117+
;;
118+
*)
119+
fail "Unknown QEMU machine=%s" "$qemu_machine";;
120+
esac
121+
machine_args=("${qemu_machine}")
122+
test -n "$qemu" || qemu=qemu-system-"$guest_arch_linux"
123+
}
124+
125+
arch_init()
126+
{
127+
host_arch=$(uname -m)
128+
set_qemu_machine
129+
set_guest_params
130+
}
131+
92132
script_dir="$(cd "$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")" && pwd)"
93133
parser_generator="${script_dir}/parser_generator.m4"
94134
parser_lib="${script_dir}/run_qemu_parser.sh"
@@ -329,6 +369,9 @@ process_options_logic()
329369
if [[ $_arg_debug == "on" ]]; then
330370
set -x
331371
fi
372+
373+
arch_init
374+
332375
if [[ $_arg_cxl_test_run == "on" ]]; then
333376
_arg_cxl_debug="on"
334377
_arg_cxl_test="on"
@@ -452,7 +495,7 @@ make_install_kernel()
452495
exit 1
453496
}
454497

455-
cat arch/x86_64/boot/bzImage > "$inst_path"/vmlinuz-"$kver"
498+
cat arch/"${guest_arch_linux}"/boot/*Image > "$inst_path"/vmlinuz-"$kver"
456499
cp System.map "$inst_path"/System.map-"$kver"
457500
ln -fs vmlinuz-"$kver" "$inst_path"/vmlinuz
458501
ln -fs System.map-"$kver" "$inst_path"/System.map
@@ -934,7 +977,9 @@ __update_existing_rootfs()
934977
local _trace_sh='-x'
935978
fi
936979
#shellcheck disable=SC2086
937-
sudo -E bash $_trace_sh -e -c "$(declare -f make_install_kernel); kver=$kver make_install_kernel $inst_path"
980+
sudo -E bash $_trace_sh -e -c "$(declare -f make_install_kernel);
981+
kver=$kver guest_arch_linux=$guest_arch_linux
982+
make_install_kernel $inst_path"
938983

939984
if [[ $_arg_cxl_test == "off" ]]; then
940985
sudo rm -f "$inst_prefix"/usr/lib/modules/"$kver"/extra/cxl_*.ko
@@ -1524,7 +1569,7 @@ prepare_qcmd()
15241569
if [[ $_arg_kvm = "off" ]]; then
15251570
accel="tcg" # the default
15261571
fi
1527-
machine_args=("q35" "accel=$accel")
1572+
machine_args+=("accel=$accel")
15281573
if [[ "$num_pmems" -gt 0 ]]; then
15291574
machine_args+=("nvdimm=on")
15301575
fi

0 commit comments

Comments
 (0)