From 436e8c8bcdec63239b3f90b0942f4f3478402594 Mon Sep 17 00:00:00 2001 From: Axel Heider Date: Thu, 4 Jan 2024 14:29:57 +0100 Subject: [PATCH 1/3] make script more generic - remove redundancy - check if config file exists - remove unnecessary CMake parameters - use separate build folder for non-MCS and MCS - improve comments Signed-off-by: Axel Heider --- standalone-kernel/compile_kernel.sh | 147 +++++++++++++++------------- 1 file changed, 81 insertions(+), 66 deletions(-) diff --git a/standalone-kernel/compile_kernel.sh b/standalone-kernel/compile_kernel.sh index 23f81078..c8f31118 100755 --- a/standalone-kernel/compile_kernel.sh +++ b/standalone-kernel/compile_kernel.sh @@ -8,84 +8,99 @@ echo "Arch: $INPUT_ARCH" echo "Comp: $INPUT_COMPILER" -set -e +set -eu -extra_config="" - -case $INPUT_ARCH in - ARM*) - case $INPUT_COMPILER in - gcc) - extra_config="${extra_config} -DAARCH32=TRUE" - ;; - llvm) - extra_config="${extra_config} -DTRIPLE=arm-linux-gnueabi" - ;; - *) - echo "Unknown input compiler" - exit 1 - esac +gcc_cfg="" +llvm_triple="" +case "${INPUT_ARCH}" in + ARM|ARM_HYP) + gcc_cfg="AARCH32" + llvm_triple="arm-linux-gnueabi" ;; AARCH64) - case $INPUT_COMPILER in - gcc) - extra_config="${extra_config} -DAARCH64=TRUE" - ;; - llvm) - extra_config="${extra_config} -DTRIPLE=aarch64-linux-gnu" - ;; - *) - echo "Unknown input compiler" - exit 1 - esac + gcc_cfg="AARCH64" + llvm_triple="aarch64-linux-gnu" ;; RISCV64) - case $INPUT_COMPILER in - gcc) - extra_config="${extra_config} -DRISCV64=TRUE" - ;; - llvm) - extra_config="${extra_config} -DTRIPLE=riscv64-unknown-elf" - ;; - *) - echo "Unknown input compiler" - exit 1 - esac + gcc_cfg="RISCV64" + llvm_triple="riscv64-unknown-elf" ;; X64) - # no config needed + # just use the standard host compiler ;; *) - echo "Unknown ARCH" + echo "Unknown ARCH '${INPUT_ARCH}'" exit 1 + ;; esac -echo "::group::Run CMake" -mkdir build -cd build -set -x -cmake -DCMAKE_TOOLCHAIN_FILE="$INPUT_COMPILER".cmake -G Ninja -C ../configs/"$INPUT_ARCH"_verified.cmake $extra_config ../ -set +x -echo "::endgroup::" +toolchain_flags="" +case "${INPUT_COMPILER}" in + gcc) + if [ ! -z "${gcc_cfg}" ]; then + toolchain_flags="-D${gcc_cfg}=TRUE" + fi + ;; + llvm) + if [ ! -z "${llvm_triple}" ]; then + toolchain_flags="-DTRIPLE=${llvm_triple}" + fi + ;; + *) + echo "Unknown COMPILER '${INPUT_COMPILER}'" + exit 1 + ;; +esac +toolchain_flags="-DCMAKE_TOOLCHAIN_FILE=${INPUT_COMPILER}.cmake ${toolchain_flags}" + +do_compile_kernel() +{ + variant=${1:-} + + build_folder="build" + config_file="configs/${INPUT_ARCH}_verified.cmake" + variant_info="" + extra_params="" + + if [ ! -z "${variant}" ]; then + case "${variant}" in + MCS) + build_folder="${build_folder}-${variant}" + variant_info=" (${variant})" + extra_params="${extra_params} -DKernelIsMCS=TRUE" + ;; + *) + echo "Unknown variant '${variant}'" + exit 1 + ;; + esac + fi + + # Unfortunately, CMake does not halt with a nice and clear error if the + # config file does not exist. Instead, it logs an error that it could not + # process the file and continues as if the file was empty. This causes some + # rather odd errors then, so it's better to fail here with a clear message. + if [ ! -f "${config_file}" ]; then + echo "missing config file '${config_file}'" + exit 1 + fi -echo "::group::Run Ninja" -set -x -ninja kernel.elf -set +x -echo "::endgroup::" + echo "::group::Run CMake${variant_info}" + ( # run in sub shell + set -x + cmake -G Ninja -B ${build_folder} -C ${config_file} ${toolchain_flags} ${extra_params} + ) + echo "::endgroup::" -echo "::group::Run CMake (MCS)" -cd .. -rm -rf build -mkdir build -cd build -set -x -cmake -DCMAKE_TOOLCHAIN_FILE="$INPUT_COMPILER".cmake -G Ninja -C ../configs/"$INPUT_ARCH"_verified.cmake $extra_config -DKernelIsMCS=TRUE ../ -set +x -echo "::endgroup::" + echo "::group::Run Ninja${variant_info}" + ( # run in sub shell + set -x + ninja -C ${build_folder} kernel.elf + ) + echo "::endgroup::" +} -echo "::group::Run Ninja (MCS)" -set -x -ninja kernel.elf -set +x -echo "::endgroup::" +# build standard kernel +do_compile_kernel +# build MCS kernel +do_compile_kernel "MCS" From 2fb17aadd5f81cbda561c178f522573d155f7f58 Mon Sep 17 00:00:00 2001 From: Axel Heider Date: Thu, 4 Jan 2024 19:49:01 +0100 Subject: [PATCH 2/3] support RISCV32 and IA32 Signed-off-by: Axel Heider --- standalone-kernel/compile_kernel.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/standalone-kernel/compile_kernel.sh b/standalone-kernel/compile_kernel.sh index c8f31118..3a2e5642 100755 --- a/standalone-kernel/compile_kernel.sh +++ b/standalone-kernel/compile_kernel.sh @@ -21,11 +21,16 @@ case "${INPUT_ARCH}" in gcc_cfg="AARCH64" llvm_triple="aarch64-linux-gnu" ;; + RISCV32) + gcc_cfg="RISCV32" + # the 64-bit toolchain can build for 32-bit also. + llvm_triple="riscv64-unknown-elf" + ;; RISCV64) gcc_cfg="RISCV64" llvm_triple="riscv64-unknown-elf" ;; - X64) + IA32|X64) # just use the standard host compiler ;; *) From 818e07e185bec9eee195e0047ba3d1596ca977c9 Mon Sep 17 00:00:00 2001 From: Axel Heider Date: Thu, 4 Jan 2024 18:26:53 +0100 Subject: [PATCH 3/3] use MCS verified config if available Signed-off-by: Axel Heider --- standalone-kernel/compile_kernel.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/standalone-kernel/compile_kernel.sh b/standalone-kernel/compile_kernel.sh index 3a2e5642..2fd8437e 100755 --- a/standalone-kernel/compile_kernel.sh +++ b/standalone-kernel/compile_kernel.sh @@ -72,7 +72,14 @@ do_compile_kernel() MCS) build_folder="${build_folder}-${variant}" variant_info=" (${variant})" - extra_params="${extra_params} -DKernelIsMCS=TRUE" + # Use a dedicated config file if available, otherwise just use + # the default config and enable MCS. + try_config_file="configs/${INPUT_ARCH}_MCS_verified.cmake" + if [ -f "${try_config_file}" ]; then + config_file=${try_config_file} + else + extra_params="${extra_params} -DKernelIsMCS=TRUE" + fi ;; *) echo "Unknown variant '${variant}'"