blob: 8da64bb9b7d543405d1bbf612b6c6271ea8c2335 [file] [log] [blame]
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Update the common kernel git sha and the GKI kernel prebuilts build ID.
# Tracking bug of aosp update event
GKI_UPDATE_BUG=${GKI_UPDATE_BUG:-"NA"}
# GKI boot image build-id
BOOT_IMAGE_BUILDID=${BOOT_IMAGE_BUILDID:-}
# GKI Kernel Branch (on aosp gerrit)
AOSP_BRANCH=${AOSP_BRANCH:-"android14-5.15"}
# Kernel Manifest
KERNEL_MANIFEST_BRANCH=${KERNEL_MANIFEST:-"android14-5.15-kirkwood-sdk"}
KERNEL_MANIFEST_URL="https://eureka-partner.googlesource.com/kirkwood/manifest"
# Whether or not to push commits to gerrit
PUSH=${PUSH:-0}
# Gerrit Topic
TOPIC=${TOPIC:-WK`date +%U`_AOSP_UPDATE_${KERNEL_MANIFEST_BRANCH}_TO_${AOSP_BRANCH}}
DEVICE_MODULES_DIR=${DEVICE_KERNEL_DIR:-"kernel_device_modules-5.15"}
DEVICE_MODULES_BRANCH="android14-5.15-kirkwood-sdk"
GKI_KERNEL_DIR=${GKI_KERNEL_DIR:-"kernel-5.15"}
CUR_DIR=$(pwd)
KERNEL_VERSION=""
KERNEL_PATCHLEVEL=""
KERNEL_SUBLEVEL=""
AOSP_COMMIT_INFO=""
MANIFEST_DIR="../.repo/manifests"
SDK_MANIFEST="sdk_only.xml"
#-----------------------------------------------------------------------
# Reset color
Color_Off='\033[0m' # Text Reset
# Regular Colors
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
function exit_if_error() {
if [ $1 -ne 0 ]; then
echo "ERROR: $2: retval=$1" >&2
cd ${CUR_DIR}
exit $1
fi
}
function usage() {
cat <<- EOF
Usage:
BOOT_IMAGE_BUILDID: The build ID of the prebuilt boot image to download.
AOSP_BRANCH: The GKI branch that the boot image is from.
KERNEL_MANIFEST_BRANCH: The kernel manifest branch to use for syncing the kernel repos.
PUSH: Optional: Whether or not to automatically push generated commits
to gerrit for review. This is set to 0 by default.
GKI_UPDATE_BUG: Optional: The bug number associated with this update.
Sample invocation:
GKI_UPDATE_BUG=308444147 BOOT_IMAGE_BUILDID=11010967 \\
AOSP_BRANCH=android14-5.15-2023-08 \\
KERNEL_MANIFEST_BRANCH=android14-5.15-kirkwood-sdk $0
Note:
You can set PUSH=1 when invoking $0 to automatically push the generated commits
to gerrit for review.
EOF
}
function sanitize_args() {
if [[ -z "${BOOT_IMAGE_BUILDID}" ]]; then
usage
exit 1
elif [[ ! -d "${CUR_DIR}/${GKI_KERNEL_DIR}" ]]; then
echo "Cannot find GKI kernel directory ${GKI_KERNEL_DIR}/" >&2
exit 1
elif [[ ! -d "${CUR_DIR}/${DEVICE_MODULES_DIR}" ]]; then
echo "Cannot find device kernel directory ${DEVICE_MODULES_DIR}/" >&2
exit 1
fi
}
function sync_kernel_repos() {
echo -e "\n${Yellow}Running repo init and syncing ${KERNEL_MANIFEST_BRANCH}${Color_Off}"
repo init -q -u "${KERNEL_MANIFEST_URL}" -b "${KERNEL_MANIFEST_BRANCH}" -m "${SDK_MANIFEST}"
exit_if_error $? "Failed to initialize kernel repo branch ${KERNEL_MANIFEST_BRANCH}"
repo sync -q -cd -j$(nproc)
exit_if_error $? "Failed to sync kernel repos"
}
function get_gki_kernel_info() {
pushd ${CUR_DIR}/${GKI_KERNEL_DIR} > /dev/null
KERNEL_VERSION=$(grep -r -m 1 "VERSION =" Makefile | sed 's/.*VERSION = //g')
KERNEL_PATCHLEVEL=$(grep -r -m 1 "PATCHLEVEL =" Makefile | \
sed 's/.*PATCHLEVEL = //g')
KERNEL_SUBLEVEL=$(grep -r -m 1 "SUBLEVEL =" Makefile | \
sed 's/.*SUBLEVEL = //g')
AOSP_COMMIT_INFO=$(git log --pretty=format:'%h %s' -1)
popd > /dev/null
}
function update_manifest_and_sync_gki_kernel() {
local rev_current_aosp
local ci_url="https://ci.android.com/builds/submitted/${BOOT_IMAGE_BUILDID}/kernel_aarch64/latest/raw/manifest_${BOOT_IMAGE_BUILDID}.xml"
wget ${ci_url}
exit_if_error $? "Unable to download manifest_${BOOT_IMAGE_BUILDID}.xml"
REV_NEW_AOSP=$(grep -r "=\"kernel/common\""\
manifest_${BOOT_IMAGE_BUILDID}.xml | \
sed 's/.*revision="//g'| sed 's/".*//g')
rm manifest_${BOOT_IMAGE_BUILDID}.xml
rev_current_aosp=$(repo info kernel/common | grep "Current revision" | \
sed 's/Current revision: //g')
pushd ${MANIFEST_DIR} > /dev/null
sed -i "s/${rev_current_aosp}/${REV_NEW_AOSP}/" ${SDK_MANIFEST}
popd > /dev/null
echo -e "\n${Yellow}Syncing the GKI kernel to new revision: ${REV_NEW_AOSP}${Color_Off}"
repo sync -q -cd -j$(nproc) kernel/common
exit_if_error $? "Unable to sync ${GKI_KERNEL_DIR}/"
}
function commit_and_push_manifest_update() {
local merge_msg=$(printf "Update ${AOSP_BRANCH} sync point to (${KERNEL_VERSION}.${KERNEL_PATCHLEVEL}.${KERNEL_SUBLEVEL})\n\nSync SHA:\n${AOSP_COMMIT_INFO}\n\nBug: ${GKI_UPDATE_BUG}")
pushd ${MANIFEST_DIR} > /dev/null
git add ${SDK_MANIFEST}
git commit --quiet -s -m "${merge_msg}"
if [[ $PUSH -eq 1 ]]; then
echo -e "\n${Yellow}Pushing manifest updates...${Color_Off}"
git push origin HEAD:refs/for/${KERNEL_MANIFEST_BRANCH} -o topic=${TOPIC}
fi
popd > /dev/null
}
function update_gki_kernel() {
get_gki_kernel_info
echo -e "\n${Green}Current GKI Kernel Info${Color_Off}"
echo -e "KERNEL_VERSION = [${Green}${KERNEL_VERSION}${Color_Off}]"
echo -e "KERNEL_PATCHLEVEL = [${Green}${KERNEL_PATCHLEVEL}${Color_Off}]"
echo -e "KERNEL_SUBLEVEL = [${Green}${KERNEL_SUBLEVEL}${Color_Off}]"
echo -e "AOSP_COMMIT_INFO = [${Green}${AOSP_COMMIT_INFO}${Color_Off}]\n"
update_manifest_and_sync_gki_kernel
get_gki_kernel_info
echo -e "\n${Green}New GKI Kernel Info:${Color_Off}"
echo -e "KERNEL_VERSION = [${Green}${KERNEL_VERSION}${Color_Off}]"
echo -e "KERNEL_PATCHLEVEL = [${Green}${KERNEL_PATCHLEVEL}${Color_Off}]"
echo -e "KERNEL_SUBLEVEL = [${Green}${KERNEL_SUBLEVEL}${Color_Off}]"
echo -e "AOSP_COMMIT_INFO = [${Green}${AOSP_COMMIT_INFO}${Color_Off}]"
commit_and_push_manifest_update
}
function update_gki_prebuilts_id() {
local current_build_id
local merge_msg=$(printf "Update the GKI prebuilt build ID to ab/${BOOT_IMAGE_BUILDID}\n\nUse GKI prebuilt binaries from ab/${BOOT_IMAGE_BUILDID}\n\nBug: ${GKI_UPDATE_BUG}")
echo -e "\n${Yellow}Updating GKI prebuilts build ID to: ${BOOT_IMAGE_BUILDID} with SHA: ${REV_NEW_AOSP} ...${Color_Off}"
pushd ${CUR_DIR}/${DEVICE_MODULES_DIR} > /dev/null
current_build_id=$(grep -e "gki_prebuilts=[0-9]*" ./device.bazelrc | grep -oe "[0-9]*")
sed -i "s/${current_build_id}/${BOOT_IMAGE_BUILDID}/" ./device.bazelrc
git add device.bazelrc
git commit --quiet -s -m "${merge_msg}"
if [[ $PUSH -eq 1 ]]; then
echo -e "\n${Yellow}Pushing updates to GKI build ID${Color_Off}"
git push eureka-partner HEAD:refs/for/${DEVICE_MODULES_BRANCH} -o topic=${TOPIC}
fi
popd > /dev/null
}
function log_push_disabled_notice() {
cat <<- EOF
Commits have been generated for integrating ACK SHA ${REV_NEW_AOSP}
but have not been pushed to gerrit.
To ensure that the commits are pushed to gerrit, rerun the script with
PUSH=1 or push each commit to gerrit manually with the following
commands:
# Manifest update
cd ${MANIFEST_DIR}
git push origin HEAD:refs/for/${KERNEL_MANIFEST_BRANCH}
cd ..
# Device modules update
cd ${DEVICE_MODULES_DIR}
git push eureka-partner HEAD:refs/for/${DEVICE_MODULES_BRANCH}
cd ..
EOF
}
sanitize_args
echo -e "\nBegin.\n"
echo -e "TOPIC = [${Green}${TOPIC}${Color_Off}]"
sync_kernel_repos
update_gki_kernel
update_gki_prebuilts_id
echo -e "\nDone.\n"
if [[ $PUSH -ne 1 ]]; then
log_push_disabled_notice
fi