-
-
Save lboulard/cfbb388802a22edb011c5b924097af0f to your computer and use it in GitHub Desktop.
A set of repo related functions to speedup AOSP related development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Export repo path | |
export PATH=/mnt/data/src/aosp:$PATH | |
export REPO_MIRROR=isilon.cambridge.arm.com:/ifs/arm/scratch/aosp_mirror | |
export REPO_MOUNT=/mnt/data/src/aosp_mirror | |
# Mount AOSP Cambridge mirror (if required) | |
function repo_mount { | |
mount | grep "$REPO_MOUNT" &>/dev/null | |
[[ $? -eq 1 ]] || return | |
echo "Mounting AOSP mirror..." | |
$(set -x; sudo mount "$REPO_MIRROR" "$REPO_MOUNT") | |
echo -e "\n\n" | |
} | |
function repo_sync { | |
BRANCH=${1:-master} | |
TASKS=${2:-$(( 2*$(nproc --all) ))} | |
echo | |
echo "### Version confirmation..." | |
echo -n "Do you confirm update AOSP to branch [$BRANCH]? [N/y]: " | |
read RESP | |
if [[ "x$RESP" != "xy" ]]; then | |
echo "Update aborted! Pick one of the version reported by "\ | |
"the \"repo_versions\" command" | |
echo -e "\n\n" | |
return 1 | |
fi | |
echo | |
echo "### Checking for AOSP mirror mount..." | |
repo_mount | |
echo | |
echo "### Init AOSP branch [$BRANCH]..." | |
repo init -u "$REPO_MOUNT/platform/manifest.git" -b $BRANCH | |
echo | |
echo "### Synching current branch..." | |
#repo sync -j16 --prune --current-branch | |
repo sync --current-branch --no-clone-bundle --no-tags --prune -j$TASKS | |
echo -e "\n\n" | |
} | |
function repo_versions { | |
cd sdk | |
git --no-pager tag | \ | |
grep -Ev 'wear|studio|gradle|-vts-|-sdk-|-cts-|test' | \ | |
while read TAG; do | |
DESC=$(git show $TAG | grep Release) | |
echo "$TAG ($DESC)" | |
done | |
cd - | |
echo -e "\n\n" | |
} | |
function repo_project_from_patch { | |
PATCH=${1} | |
[[ -f $PATCH ]] || return | |
echo $(basename "$PATCH") | \ | |
awk 'match($0, /[0-9]+-(.*)-cgif-(.*)/, a) {print a[1]}' | \ | |
sed 's|-|/|g' | |
} | |
function repo_projects_from_patches { | |
FOLDER=${1} | |
cd $FOLDER | |
ls | while read PNAME; do \ | |
repo_project_from_patch "$PNAME"; \ | |
done | |
cd - >/dev/null | |
} | |
# GIT_LG_FORMAT="--pretty=format:'%Cred%h%Creset - %s%C(yellow)%d%Creset %Cgreen(%cd %an)%Creset'" | |
# 'git log "$GIT_LG_FORMAT" --abbrev-commit --date=short -n50 ' | |
function repo_status { | |
PROJECTS=${1:-"projects.list"} | |
if [ -f $PROJECTS ]; then | |
repo forall `cat $PROJECTS` \ | |
-c 'echo ; echo "### $(pwd) ($(git describe))" ; git status' | |
else | |
repo status | |
fi | |
echo -e "\n\n" | |
} | |
function repo_lg { | |
PROJECTS=${1:-"projects.list"} | |
if [ -f $PROJECTS ]; then | |
repo forall `cat $PROJECTS` \ | |
-c 'echo ; echo "### $(pwd) ($(git describe))" ; git log --oneline -n10' | |
else | |
repo status | |
fi | |
echo -e "\n\n" | |
} | |
function repo_switch { | |
BRANCH=${1:-"aosp/master"} | |
PROJECTS=${2:-"projects.list"} | |
CMD='echo ; echo "### $(pwd) (switch to: '"$BRANCH"')" ; git checkout '"$BRANCH" | |
if [ -f $PROJECTS -a "x$PROJECTS" != "xall" ]; then | |
echo "Switch to [$BRANCH] only selected projects" | |
repo forall `cat $PROJECTS` -c "$CMD" | |
else | |
echo "Switch to [$BRANCH] all projects" | |
repo forall -c "$CMD" | |
fi | |
echo -e "\n\n" | |
} | |
function repo_format_patch { | |
PROJECTS=${1:-"projects.list"} | |
TOPIC=${TOPIC:-"repo_export"} | |
OUTDIR=${OUTDIR:-"/tmp/$(date +%Y%m%d_%H%M)_${TOPIC}"} | |
BASE=${BASE:-"aosp/master"} | |
TOT=${TOT:-"HEAD"} | |
[[ -d $OUTDIR ]] || mkdir -p $OUTDIR | |
if [ ! -f $PROJECTS ]; then | |
echo | |
echo "FAILED: please specify a list of project [projects.list]" | |
echo -e "\n\n" | |
return -1 | |
fi | |
repo forall `cat $PROJECTS` \ | |
-c 'echo ; echo "### $(pwd) ($(git describe))" ; git format-patch -o '"$OUTDIR ${BASE}..${TOT}" | |
echo | |
echo "Exported patches [$OUTDIR]:" | |
ls -la "$OUTDIR" | |
ARCHIVE="${OUTDIR}.tar.xz" | |
pushd $(dirname "$ARCHIVE") >/dev/null | |
tar cJf "$ARCHIVE" "$(basename $OUTDIR)" | |
popd >/dev/null | |
echo | |
echo "Archive available here::" | |
echo " $ARCHIVE" | |
echo -e "\n\n" | |
} | |
function repo_am_patches { | |
FOLDER=${1} | |
TOPIC=${2:-"devel"} | |
# Update the projects list | |
repo_projects_from_patches "$FOLDER" > projects_${TOPIC}.list | |
ln -fs projects_${TOPIC}.list projects.list | |
# Apply patches | |
for PFILE in $(ls $FOLDER/*.patch); do | |
PNAME=$(basename "$PFILE") | |
PROJECT=`repo_project_from_patch "$PFILE"` | |
if [[ ! -d "./$PRJECT" ]]; then | |
echo "Project [$PROJECT] not found!" | |
echo " Skipping $PFILE" | |
continue | |
fi | |
cd $PROJECT | |
echo | |
echo | |
echo ">>> Project : $PROJECT" | |
git branch | |
echo " Apply : $PFILE ..." | |
# patch -p1 $DRYRUN < $PFILE | |
git am $PFILE || return 1 | |
cd - >/dev/null | |
done | |
} | |
get_sha1_changeid() { | |
SHA1=$1 | |
git show $SHA1 | awk '/Change-Id: /{print $2}' | |
} | |
head_has_changeid() { | |
CID=$1 | |
HEAD=$(git describe --abbrev=0 --all HEAD^) | |
git log $HEAD.. | grep $CID &>/dev/null | |
if [[ $? -eq 0 ]]; then echo 1; else echo 0; fi | |
} | |
function repo_apply_from { | |
SBRANCH=${1} | |
PROJECTS=${2:-"projects.list"} | |
RES=0 | |
for PRJ in $(cat $PROJECTS); do | |
cd $PRJ | |
DBASE=$(git describe --abbrev=0 --all HEAD^) | |
DHEAD=$(git rev-parse --abbrev-ref HEAD) | |
SBASE=$(git describe --abbrev=0 $SBRANCH) | |
echo | |
echo "### $(pwd) ($DHEAD)" | |
git log --oneline $SBASE..$SBRANCH | |
# echo | |
# echo "Cherry pick commits by:" | |
# echo " - skipping changes already applied" | |
# echo " - stopping on conflicts" | |
# echo | |
for SHA1 in $(git rev-list --reverse $SBASE..$SBRANCH .); do | |
COMMIT=$(git log --oneline $SHA1^..$SHA1) | |
CID=$(get_sha1_changeid $SHA1) | |
echo "<<< $COMMIT" | |
echo " Change-Id: $CID" | |
SKIP=$(head_has_changeid $CID) | |
if [[ $SKIP -eq 1 ]]; then | |
echo " already on local branch: skipped!" | |
continue | |
fi | |
git cherry-pick $SHA1 | |
[[ $? -eq 0 ]] || return -1 | |
done | |
echo | |
echo "Branch status:" | |
git log --oneline $DBASE..$DBRANCH | |
cd - &>/dev/null | |
done | |
echo -e "\n\n" | |
} | |
function repo_reset { | |
PROJECTS=${1:-"projects.list"} | |
CMD='git cherry-pick --abort &>/dev/null; git reset --hard' | |
if [ -f $PROJECTS ]; then | |
# set -x | |
for PRJ in $(cat $PROJECTS); do | |
cd $PRJ | |
HEAD=$(git rev-parse --abbrev-ref HEAD) | |
echo | |
echo "### $(pwd) ($HEAD)" | |
eval $CMD | |
cd - | |
done | |
# set +x | |
else | |
repo forall -c $CMD | |
fi | |
echo -e "\n\n" | |
} | |
function repo_commits { | |
BRANCH=${1:-"HEAD"} | |
PROJECTS=${2:-"projects.list"} | |
if [ -f $PROJECTS ]; then | |
CMD="git log --oneline \$(git describe --all --abbrev=0 $BRANCH~1)..$BRANCH" | |
repo forall `cat $PROJECTS` \ | |
-c "echo ; echo \"### \$(pwd) (\$(git describe))\" ; $CMD" | cat | |
else | |
repo status | |
fi | |
echo -e "\n\n" | |
} | |
function repo_branches { | |
PROJECTS=${1:-"projects.list"} | |
if [ -f $PROJECTS ]; then | |
repo branches `cat $PROJECTS` | |
else | |
repo branches | |
fi | |
echo -e "\n\n" | |
} | |
function repo_log { | |
PROJECTS=${1:-"projects.list"} | |
if [ -f $PROJECTS ]; then | |
repo forall `cat $PROJECTS` \ | |
-c 'echo ; echo "### $(pwd) ($(git describe))" ; git log -n5 --oneline | cat' | |
else | |
repo status | |
fi | |
echo -e "\n\n" | |
} | |
function repo_start { | |
BRANCH=${1:-"devel"} | |
PROJECTS=${2:-"projects.list"} | |
echo | |
echo "################################################################################" | |
echo "Starting new branch [$BRANCH]" | |
if [ -f $PROJECTS ]; then | |
echo "Projects: " | |
cat $PROJECTS | while read PRJ; do echo " $PRJ"; done | |
repo start $BRANCH `cat $PROJECTS` | |
else | |
repo start --all $BRANCH | |
fi | |
echo -e "\n\n" | |
} | |
function repo_build_init { | |
source build/envsetup.sh | |
lunch hikey960-eng | |
} | |
function repo_build_hikey960 { | |
CLOBBER=${1:-0} | |
TARGET_KERNEL_USE=${TARGET_KERNEL_USE:-4.14} | |
[[ $CLOBBER -eq 0 ]] || make clobber | |
repo_build_init | |
echo | |
echo "Rebuild AOSP images using:" | |
echo " TARGET_KERNEL_USE=$TARGET_KERNEL_USE" | |
make TARGET_KERNEL_USE=$TARGET_KERNEL_USE -j | |
} | |
function repo_flash_images { | |
TARGET_PRODUCT=${TARGET_PRODUCT:-hikey960} | |
export ANDROID_BUILD_TOP=${ANDROID_BUILD_TOP:-$(pwd)} | |
export ANDROID_PRODUCT_OUT=${ANDROID_PRODUCT_OUT:-"$ANDROID_BUILD_TOP/out/target/product/$TARGET_PRODUCT"} | |
echo "Flashing new kernel images from:" | |
echo " ANDROID_BUILD_TOP=$ANDROID_BUILD_TOP" | |
echo " ANDROID_PRODUCT_OUT=$ANDROID_PRODUCT_OUT" | |
fastboot flashall | |
} | |
function repo_kernel_build { | |
TARGET_KERNEL_USE=${TARGET_KERNEL_USE:-4.14} | |
export TARGET_KERNEL_USE=$TARGET_KERNEL_USE | |
AOSP_DIR=$(pwd) | |
PREBUILTS_DIR=$AOSP_DIR/prebuilts | |
repo_build_init | |
pushd kernel/current >/dev/null | |
echo | |
echo "Current branch: $(git describe)" | |
source ./build.config.hikey960.clang | |
export CLANG_PREBUILT_BIN=${CLANG_PREBUILT_BIN/prebuilts-master/$PREBUILTS_DIR} | |
if echo $PATH | grep $CLANG_PREBUILT_BIN &>/dev/null; then | |
echo "Cross-compiler already on PATH: $CLANG_PREBUILT_BIN" | |
else | |
export PATH=$CLANG_PREBUILT_BIN:$PATH | |
echo "Add cross-compiler to PATH: $CLANG_PREBUILT_BIN" | |
fi | |
echo "Defconfig: $DEFCONFIG" | |
make ARCH=$ARCH $DEFCONFIG || return -1 | |
echo "Compiling..." | |
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE CLANG_TRIPLE=$CLANG_TRIPLE CC=$CC -j >/dev/null | |
if [[ $? -ne 0 ]]; then | |
echo | |
popd >/dev/null | |
return -1 | |
fi | |
cat arch/arm64/boot/Image.gz \ | |
arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dtb \ | |
> arch/arm64/boot/Image.gz-dtb | |
cp arch/arm64/boot/Image.gz-dtb \ | |
$ANDROID_BUILD_TOP/device/linaro/hikey-kernel/Image.gz-dtb-hikey960-$TARGET_KERNEL_USE | |
cp arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dtb \ | |
$ANDROID_BUILD_TOP/device/linaro/hikey-kernel/hi3660-hikey960.dtb-$TARGET_KERNEL_USE | |
echo | |
popd >/dev/null | |
echo | |
echo "Rebuild boot image using:" | |
echo " TARGET_KERNEL_USE=$TARGET_KERNEL_USE" | |
repo_build_hikey960 | |
pushd $ANDROID_BUILD_TOP/out/target/product/hikey960/ >/dev/null | |
echo | |
echo "AOSP images [$(pwd)]:" | |
ls -lat *.img | |
popd >/dev/null | |
# Alternative solution to update just the boot.img | |
# $ abootimg -u boot.img -k Image.gz-dtb | |
# where boot.img is the boot.img originally generated from a full AOSP | |
# build, and Image.gz-dtb is a custom built kernel+dtb | |
} | |
function repo_flash_bootimage { | |
export ANDROID_BUILD_TOP=${ANDROID_BUILD_TOP:-$(pwd)} | |
export ANDROID_PRODUCT_OUT=${ANDROID_PRODUCT_OUT:-"$ANDROID_BUILD_TOP/out/target/product/hikey960"} | |
echo "Flashing new kernel images from:" | |
echo " ANDROID_BUILD_TOP=$ANDROID_BUILD_TOP" | |
echo " ANDROID_PRODUCT_OUT=$ANDROID_PRODUCT_OUT" | |
# Let's use explitic partitions | |
# NOTE: this is less robust in case the partitions name/layout should change | |
fastboot flash boot $ANDROID_BUILD_TOP/out/target/product/hikey960/boot.img | |
fastboot flash dts $ANDROID_BUILD_TOP/out/target/product/hikey960/dt.img | |
fastboot flash system $ANDROID_BUILD_TOP/out/target/product/hikey960/system.img | |
fastboot reboot | |
} | |
function repo_flash_snapshot_list { | |
pushd $ANDROID_BUILD_TOP/out/target/product/hikey960/ >/dev/null | |
echo | |
echo "Available snapshots are:" | |
for SS in $(find $ANDROID_PRODUCT_OUT -maxdepth 1 -name "snapshot*"); do | |
echo "- $(basename $SS)" | |
done | |
popd >/dev/null | |
} | |
function repo_flash_snapshot_save { | |
TAGNAME=${1:-''} | |
export ANDROID_BUILD_TOP=${ANDROID_BUILD_TOP:-$(pwd)} | |
export ANDROID_PRODUCT_OUT=${ANDROID_PRODUCT_OUT:-"$ANDROID_BUILD_TOP/out/target/product/hikey960"} | |
echo "Flashing new kernel images from:" | |
echo " ANDROID_BUILD_TOP=$ANDROID_BUILD_TOP" | |
echo " ANDROID_PRODUCT_OUT=$ANDROID_PRODUCT_OUT" | |
pushd $ANDROID_BUILD_TOP/out/target/product/hikey960/ >/dev/null | |
echo | |
echo "AOSP images [$(pwd)]:" | |
ls -lat *.img | |
TIMESTAMP=$(date +%Y%m%d_%H%M%S) | |
SNAPDIR="$ANDROID_PRODUCT_OUT/snapshot_$TIMESTAMP" | |
[[ "x$TAGNAME" == "x" ]] || SNAPDIR="${SNAPDIR}_$TAGNAME" | |
echo | |
echo "Saving images into folder [$SNAPDIR]..." | |
mkdir -p $SNAPDIR && cp *.img $SNAPDIR/ || echo "Snapshot FAILED" | |
popd >/dev/null | |
} | |
function repo_flash_snapshot_load { | |
TAGNAME=${1:-default} | |
pushd $ANDROID_BUILD_TOP/out/target/product/hikey960/ >/dev/null | |
SNAPDIR=$(find $ANDROID_PRODUCT_OUT -maxdepth 1 -name "snapshot*${TAGNAME}*") | |
COUNT=$(echo $SNAPDIR | wc -l) | |
if [[ $COUNT -gt 1 ]]; then | |
echo | |
echo "More than one snapshots matching [$TAGNAME] found" | |
echo | |
echo "Matching snapshots are:" | |
ls -la $ANDROID_PRODUCT_OUT/snapshot*${TAGNAME}* | |
popd >/dev/null | |
return -1 | |
fi | |
if [[ ! -d $SNAPDIR ]]; then | |
echo | |
echo "No snapshots matching [$TAGNAME] found" | |
repo_flash_snapshot_list | |
return -1 | |
fi | |
echo | |
echo "Using snapshot [$SNAPDIR]..." | |
cp -R $SNAPDIR/*.img . | |
popd >/dev/null | |
} | |
function repo_flash_snapshot { | |
TAGNAME=${1:-default} | |
repo_flash_load $TAGNAME || return -1 | |
repo_flash_images | |
} | |
function repo_acme_power_cycle { | |
CH=${1:-'0'} | |
IP=${2:-'192.168.0.1'} | |
echo "Toggle device$CH on ACME@$IP..." | |
ssh root@$IP \ | |
"echo 0 > /sys/bus/iio/devices/iio:device$CH/in_active" | |
sleep 2 | |
echo "OFF" | |
echo "ON" | |
ssh root@$IP \ | |
"echo 1 > /sys/bus/iio/devices/iio:device$CH/in_active" | |
sleep 1 | |
} | |
function repo_cscope_reindex { | |
echo | |
echo "Build [.cscope.big.files] DB..." | |
set -x | |
find . -type f \ | |
\( \ | |
-name "*.java" -o \ | |
-name "*.c" -o \ | |
-name "*.cpp" -o \ | |
-name "*.h" \ | |
\) \ | |
-and -not \ | |
\( \ | |
-path "./out/*" -o \ | |
-path "./prebuilts/*" -o \ | |
-path "./external/*" -o \ | |
-path "./dalvik/*" -o \ | |
-path "./ndk/*" -o \ | |
-path "./kernel/*" \ | |
\) \ | |
> .cscope.big.files | |
set +x | |
echo | |
echo "Update CScope DB..." | |
set -x | |
cscope -kqbR -u -i.cscope.big.files -f.cscope.big | |
set +x | |
} | |
cat <<EOF | |
A new set of bash commands are now available to work on this repo tree. | |
All commands starts with "repo_" and they are: | |
EOF | |
grep 'function repo_' init_env | grep -Ev 'grep|#' | cut -d" " -f2 | sort | |
echo -e "\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment