before: just support aarch64 after: easy to support more arch(aarch64, x86_64, riscv64).
Signed-off-by: Liu Yinsi liuyinsi@163.com --- providers/qemu/kvm.sh | 51 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-)
diff --git a/providers/qemu/kvm.sh b/providers/qemu/kvm.sh index c926d3d..0c98065 100755 --- a/providers/qemu/kvm.sh +++ b/providers/qemu/kvm.sh @@ -7,6 +7,9 @@ : ${nr_cpu:=1} : ${memory:=1G}
+bios=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd +helper=/usr/libexec/qemu-bridge-helper + check_logfile() { log_file=/srv/cci/serial/logs/${hostname} @@ -20,8 +23,15 @@ check_logfile()
qemu_command() { - qemu=qemu-system-aarch64 - command -v $qemu >/dev/null || qemu=qemu-kvm + qemu=( + qemu-system-aarch64 + qemu-kvm + ) + + for qemu in "${qemu[@]}" + do + [ -n "$(command -v ${qemu})" ] && break + done }
write_logfile() @@ -72,6 +82,11 @@ get_initrd() cat $initrds > $initrd }
+get_nic() +{ + nic="tap,model=virtio-net-pci,helper=$helper,br=br0,mac=${mac}" +} + print_message() { echo $SCHED_PORT @@ -83,24 +98,42 @@ print_message() sleep 5 }
-run_qemu() +public_option() { kvm=( $qemu - -machine virt-4.0,accel=kvm,gic-version=3 -kernel $kernel -initrd $initrd -smp $nr_cpu -m $memory - -cpu Kunpeng-920 - -bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd - -nic tap,model=virtio-net-pci,helper=/usr/libexec/qemu-bridge-helper,br=br0,mac=${mac} -k en-us -no-reboot -nographic -serial file:${log_file} -monitor null ) +} + +individual_option() +{ + aarch64=( + -machine virt-4.0,accel=kvm,gic-version=3 + -cpu Kunpeng-920 + -bios $bios + -nic $nic + ) +} + +run_qemu() +{ + case $qemu in + qemu-system-aarch64) + kvm=("${kvm[@]}" "${aarch64[@]}") + ;; + qemu-kvm) + [ "$(arch)" == "aarch64" ] && kvm=("${kvm[@]}" "${aarch64[@]}") + ;; + esac
"${kvm[@]}" --append "${append}" } @@ -112,7 +145,11 @@ qemu_command parse_ipxe_script check_option_value get_initrd +get_nic
print_message
+public_option +individual_option + run_qemu
+++ b/providers/qemu/kvm.sh @@ -7,6 +7,9 @@ : ${nr_cpu:=1} : ${memory:=1G}
+bios=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
Current bios var is strongly correlated with aarch64, may be you need a function to prepare `BIOS` var for different arch, such as get_bios()
+individual_option() +{
- aarch64=(
-machine virt-4.0,accel=kvm,gic-version=3
-cpu Kunpeng-920
-bios $bios
-nic $nic
- )
+}
If you want your script support many arch, how about modify `aarch64` to `APPENDS`? it looks more general.
Btw, maybe you can unify the function naming. just as the follow: get_bios() get_helper() get_nic() get_qemu_command() get_public_option() get_individual_option() run_qemu() main() { step_1 step_2 step_3 }
-------- Thanks Yu Chuan
+run_qemu() +{
case $qemu in
qemu-system-aarch64)
kvm=("${kvm[@]}" "${aarch64[@]}")
;;
qemu-kvm)
[ "$(arch)" == "aarch64" ] && kvm=("${kvm[@]}" "${aarch64[@]}")
;;
esac
"${kvm[@]}" --append "${append}"
} @@ -112,7 +145,11 @@ qemu_command parse_ipxe_script check_option_value get_initrd +get_nic
print_message
+public_option +individual_option
run_qemu
2.23.0
+bios=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
Current bios var is strongly correlated with aarch64, may be you need a function to prepare `BIOS` var for different arch, such as get_bios()
ok
+individual_option() +{
- aarch64=(
-machine virt-4.0,accel=kvm,gic-version=3
-cpu Kunpeng-920
-bios $bios
-nic $nic
- )
+}
If you want your script support many arch, how about modify `aarch64` to `APPENDS`? it looks more general.
already have append var from lkp code.
Btw, maybe you can unify the function naming. just as the follow:
good
Thanks, Yinsi
get_bios() get_helper() get_nic() get_qemu_command() get_public_option() get_individual_option() run_qemu() main() { step_1 step_2 step_3 }
Thanks Yu Chuan
+run_qemu() +{
case $qemu in
qemu-system-aarch64)
kvm=("${kvm[@]}" "${aarch64[@]}")
;;
qemu-kvm)
[ "$(arch)" == "aarch64" ] && kvm=("${kvm[@]}" "${aarch64[@]}")
;;
esac
"${kvm[@]}" --append "${append}"
} @@ -112,7 +145,11 @@ qemu_command parse_ipxe_script check_option_value get_initrd +get_nic
print_message
+public_option +individual_option
run_qemu
2.23.0