blob: 407a4276a8c8906851753e982abd52515c1f4690 [file] [edit]
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
SCRIPT_ROOT=${SCRIPT_ROOT%cos}
. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
# Script must be run inside the chroot.
restart_in_chroot_if_needed "$@"
DEFINE_string kernel_tree "" \
"In-chroot path to the kernel tree."
DEFINE_string arch "" \
"Architecture of the config."
DEFINE_string config '' \
'Name of the config. The config is assumed to be in the arch/${arch}/configs directory.'
DEFINE_string update_chroot '' \
'Whether or not to update the chroot before running menuconfig. Defaults to true.'
# Parse command line.
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
switch_to_strict_mode
menuconfig() {
local -r config=$1
local -r arch=$2
local tuple
case "${arch}" in
x86_64)
tuple=x86_64-cros-linux-gnu
;;
arm64)
tuple=aarch64-cros-linux-gnu
;;
*)
error "Unknown arch ${arch}"
return 1
;;
esac
local build_dir
build_dir="$(mktemp -d)"
cp "${config}" "${build_dir}/.config"
make -C "${FLAGS_kernel_tree}" O="${build_dir}" ARCH="${arch}" \
CC="${tuple}-clang" LD="${tuple}-ld.lld" CROSS_COMPILE="${tuple}-" \
menuconfig
cp "${build_dir}/.config" "${config}"
rm -rf "${build_dir}"
}
main() {
if [[ -z "${FLAGS_kernel_tree}" ]]; then
error "Please provide a --kernel_tree value"
return 1
fi
local -r config_path="${FLAGS_kernel_tree}/arch/${FLAGS_arch}/configs/${FLAGS_config}"
# The arch used for the config path is not necessarily the one expected
# by the compiler.
local compiler_arch="${FLAGS_arch}"
if [[ "${FLAGS_arch}" == "x86" ]]; then
compiler_arch=x86_64
fi
if [[ "${FLAGS_update_chroot}" != "false" ]]; then
update_chroot
fi
menuconfig "${config_path}" "${compiler_arch}"
}
main "$@"