scripts: Add prepare_linux function

`prepare_linux` checks if a `--build-guest-kernel` option is present,
and build kernel from `cloud-hypervisor/linux.git`. Otherwise, it will
invoke `download_linux` to use pre-built kernel.

Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
This commit is contained in:
Ruoqing He 2024-11-11 10:07:39 +08:00 committed by Rob Bradford
parent c6889388a3
commit 906580ee92

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
hypervisor="kvm" hypervisor="kvm"
test_filter="" test_filter=""
build_kernel=false
# Checkout source code of a GIT repo with specified branch and commit # Checkout source code of a GIT repo with specified branch and commit
# Args: # Args:
@ -75,11 +76,13 @@ cmd_help() {
echo "" echo ""
echo " --hypervisor Underlying hypervisor. Options kvm, mshv" echo " --hypervisor Underlying hypervisor. Options kvm, mshv"
echo " --test-filter Tests to run" echo " --test-filter Tests to run"
echo " --build-guest-kernel Build guest kernel from source instead of downloading pre-built"
echo "" echo ""
echo " --help Display this help message." echo " --help Display this help message."
echo "" echo ""
} }
# shellcheck disable=SC2034
process_common_args() { process_common_args() {
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
@ -93,9 +96,11 @@ process_common_args() {
;; ;;
"--test-filter") "--test-filter")
shift shift
# shellcheck disable=SC2034
test_filter="$1" test_filter="$1"
;; ;;
"--build-guest-kernel")
build_kernel=true
;;
"--") { "--") {
shift shift
break break
@ -149,6 +154,18 @@ download_linux() {
popd || exit popd || exit
} }
prepare_linux() {
if [ "$build_kernel" = true ]; then
echo "Building kernel from source"
build_custom_linux
echo "Using kernel built from source"
else
echo "Downloading pre-built kernel from GitHub"
download_linux
echo "Using kernel downloaded from GitHub"
fi
}
download_ovmf() { download_ovmf() {
OVMF_FW_TAG="ch-6624aa331f" OVMF_FW_TAG="ch-6624aa331f"
OVMF_FW_URL="https://github.com/cloud-hypervisor/edk2/releases/download/$OVMF_FW_TAG/CLOUDHV.fd" OVMF_FW_URL="https://github.com/cloud-hypervisor/edk2/releases/download/$OVMF_FW_TAG/CLOUDHV.fd"