blob: e5fe01ed099a88c1978418c3ef71a39134d4894b [file] [edit]
#!/bin/bash
#
# Copyright 2026 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")")"
# shellcheck source=build_library/build_common.sh
. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
DEFINE_string image_path "" \
"Path to image to reset UKI cmdline on"
DEFINE_string board "${DEFAULT_BOARD}" \
"Board of the input image"
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
switch_to_strict_mode
# N.B. Ordering matters for some of the libraries below, because
# some of the files contain initialization used by later files.
# shellcheck source=build_library/board_options.sh
. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
# shellcheck source=build_library/disk_layout_util.sh
. "${BUILD_LIBRARY_DIR}/disk_layout_util.sh" || exit 1
# shellcheck source=build_library/mount_gpt_util.sh
. "${BUILD_LIBRARY_DIR}/mount_gpt_util.sh" || exit 1
# shellcheck source=build_library/build_image_util.sh
. "${BUILD_LIBRARY_DIR}/build_image_util.sh" || exit 1
# shellcheck source=build_library/base_image_util.sh
. "${BUILD_LIBRARY_DIR}/base_image_util.sh" || exit 1
# shellcheck source=build_library/dev_image_util.sh
. "${BUILD_LIBRARY_DIR}/dev_image_util.sh" || exit 1
# shellcheck source=build_library/test_image_util.sh
. "${BUILD_LIBRARY_DIR}/test_image_util.sh" || exit 1
# shellcheck source=build_library/selinux_util.sh
. "${BUILD_LIBRARY_DIR}/selinux_util.sh" || exit 1
reset_cmdline() {
local image=$1
local kernel=$2
local tmpdir="$(mktemp -d)"
local root_fs_dir="${tmpdir}/rootfs"
local stateful_fs_dir="${tmpdir}/stateful"
local esp_fs_dir="${tmpdir}/esp"
local vmlinux="/build/${BOARD}/usr/src/linux/build/vmlinux"
trap "check_full_disk ; unmount_image ; rm -r ${tmpdir}" EXIT
mount_image "${image}" "${root_fs_dir}" "${stateful_fs_dir}" \
"${esp_fs_dir}" --safe
sudo mv "${esp_fs_dir}/${kernel}" "${esp_fs_dir}/efi/boot/bootx64.efi"
unmount_image
trap - EXIT
PATH=$PATH:/sbin cos_kernel_args --vmlinux "${vmlinux}" \
sed --command "s|.*||g" "${image}"
trap "check_full_disk ; unmount_image ; rm -r ${tmpdir}" EXIT
mount_image "${image}" "${root_fs_dir}" "${stateful_fs_dir}" \
"${esp_fs_dir}" --safe
sudo mv "${esp_fs_dir}/efi/boot/bootx64.efi" "${esp_fs_dir}/${kernel}"
sudo cp "${esp_fs_dir}/efi/boot/shimx64.efi" \
"${esp_fs_dir}/efi/boot/bootx64.efi"
unmount_image
trap - EXIT
}
main() {
local image="${FLAGS_image_path}"
if [[ -z "${image}" ]]; then
error "Must set --image_path flag"
exit 1
fi
info "Entering reset_uki_cmdline.sh $*"
reset_cmdline "${image}" "/syslinux/vmlinuz.A"
reset_cmdline "${image}" "/syslinux/vmlinuz.B"
}
main "$@"