From cc703a8796d2ccaabd630523b5dd445c5afed73d Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Fri, 8 Jan 2021 16:13:33 -0700 Subject: [PATCH] boot-qemu.sh: Allow the user to supply a kernel image directly There are times where supplying a kernel image directly makes more sense than providing the build output folder. For example, when using tuxmake, the build output folder is automatically cleaned up, leaving just the compiled artifacts. To boot kernels in this way, one would have to make a fake boot folder and copy the image to it. Convert '-k' to either take a kernel image directly or the kernel build output folder. Signed-off-by: Nathan Chancellor --- README.txt | 9 +++++---- boot-qemu.sh | 25 +++++++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.txt b/README.txt index 18fd724..a9978ea 100644 --- a/README.txt +++ b/README.txt @@ -19,10 +19,11 @@ Required parameters: * x86 * x86_64 - -k | --kbuild-folder: - The kernel build folder, as an absolute path or relative path - from wherever the script is being run. This is wherever the - compiled vmlinux image lives, not the architecture's boot folder. + -k | --kernel-location: + The kernel location, which can either be the kernel image itself or + the root of the kernel build output folder. Either option can be + passed as an absolute path or relative path from wherever the script + is being run. Optional parameters: -d | --debug: diff --git a/boot-qemu.sh b/boot-qemu.sh index da3669c..99c81af 100755 --- a/boot-qemu.sh +++ b/boot-qemu.sh @@ -54,8 +54,8 @@ function parse_parameters() { INTERACTIVE=true ;; - -k | --kbuild-folder) - shift && KBUILD_DIR=${1} + -k | --kernel-location) + shift && KERNEL_LOCATION=${1} ;; -t | --timeout) @@ -74,13 +74,10 @@ function parse_parameters() { function sanity_check() { # Kernel build folder and architecture are required paramters [[ -z ${ARCH} ]] && die "Architecture ('-a') is required but not specified!" - [[ -z ${KBUILD_DIR} ]] && die "Kernel build folder ('-k') is required but not specified!" + [[ -z ${KERNEL_LOCATION} ]] && die "Kernel image or kernel build folder ('-k') is required but not specified!" - # KBUILD_DIR could be a relative path; turn it into an absolute one with readlink - KBUILD_DIR=$(readlink -f "${KBUILD_DIR}") - - # Let the user know if the kernel build folder does not exist - [[ -d ${KBUILD_DIR} ]] || die "${KBUILD_DIR} does not exist!" + # KERNEL_LOCATION could be a relative path; turn it into an absolute one with readlink + KERNEL_LOCATION=$(readlink -f "${KERNEL_LOCATION}") # Make sure zstd is install checkbin zstd @@ -223,8 +220,16 @@ function setup_qemu_args() { esac checkbin "${QEMU[*]}" - [[ ${KIMAGE:=zImage} == "vmlinux" ]] || BOOT_DIR=arch/${ARCH}/boot/ - KERNEL=${KBUILD_DIR}/${BOOT_DIR}${KIMAGE} + # If '-k' is an path that ends in the kernel image, we can just use it directly + if [[ ${KERNEL_LOCATION##*/} = "${KIMAGE:=zImage}" ]]; then + KERNEL=${KERNEL_LOCATION} + # If not though, we need to find it based on the kernel build directory + else + # If the image is an uncompressed vmlinux, it is in the root of the build folder + # Otherwise, it is in the architecture's boot directory + [[ ${KIMAGE} == "vmlinux" ]] || BOOT_DIR=arch/${ARCH}/boot/ + KERNEL=${KERNEL_LOCATION}/${BOOT_DIR}${KIMAGE} + fi [[ -f ${KERNEL} ]] || die "${KERNEL} does not exist!" }