Add script to resync kernel configs It runs inside the chroot and takes the kernel source dir as an argument. BUG=None TEST=`./cos/resync_kernel_configs.sh --kernel_tree ../third_party/kernel/v6.6` inside the chroot RELEASE_NOTE=None Change-Id: I638b09ce81d3d5c341bcd83dd18700068352120f Reviewed-on: https://cos-review.googlesource.com/c/cos/scripts/+/88619 Tested-by: Robert Kolchmeyer <rkolchmeyer@google.com> Reviewed-by: Kevin Berry <kpberry@google.com>
diff --git a/resync_kernel_configs.sh b/resync_kernel_configs.sh new file mode 100755 index 0000000..29d8e9a --- /dev/null +++ b/resync_kernel_configs.sh
@@ -0,0 +1,67 @@ +# 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 to sync configs in." + +# Parse command line. +FLAGS "$@" || exit 1 +eval set -- "${FLAGS_ARGV}" + +switch_to_strict_mode + +sync_config() { + 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}-" \ + olddefconfig + 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 + update_chroot + sync_config "${FLAGS_kernel_tree}/arch/x86/configs/lakitu_defconfig" x86_64 + sync_config "${FLAGS_kernel_tree}/arch/arm64/configs/lakitu_defconfig" arm64 +} + +main "$@"