mirror of
https://github.com/hardkernel/kernel_common_drivers.git
synced 2026-06-25 12:03:48 +09:00
patch: auto patch fail [1/1]
PD#SWPL-214570 Problem: failure occurred when calling autopatch.sh in the kernel directory Solution: 1. Before applying the patch, confirm that the directory is a Git repository 2. The kernel path and kernel version can be obtained through calculation, so there is no need to add additional parameters 3. Optimize the maximum number of patches to improve performance 4. Optimize lunch patch 5. Optimize debug logs 6. Refactor into functions Verify: local Change-Id: Ied02c8ed30816ac65bb53691aab92fd23d4146e7 Signed-off-by: Wanwei Jiang <wanwei.jiang@amlogic.com>
This commit is contained in:
committed by
gerrit autosubmit
parent
1547ea4405
commit
eb4e1a61ee
+104
-89
@@ -1,59 +1,80 @@
|
||||
#!/bin/bash
|
||||
|
||||
enter_path=$(pwd)
|
||||
common_path=$(pwd)
|
||||
if [[ -z "${KERNEL_DIR}" ]]; then
|
||||
KERNEL_DIR=common
|
||||
fi
|
||||
if [[ ! -f ${KERNEL_DIR}/init/main.c ]]; then
|
||||
echo "The directory of kernel does not exist";
|
||||
exit
|
||||
fi
|
||||
if [[ -z "${COMMON_DRIVERS_DIR}" ]]; then
|
||||
if [[ -d ${KERNEL_DIR}/../common_drivers ]]; then
|
||||
COMMON_DRIVERS_DIR=../common_drivers
|
||||
elif [[ -d "${KERNEL_DIR}/common_drivers" ]]; then
|
||||
COMMON_DRIVERS_DIR=common_drivers
|
||||
function get_paths_and_enter_common_path()
|
||||
{
|
||||
ENTER_PATH=$(pwd)
|
||||
AUTO_PATCH_PATH=$(dirname $(realpath -s "$0"))
|
||||
common_driver_path=$(dirname ${AUTO_PATCH_PATH})
|
||||
temp_path=$(dirname ${common_driver_path})
|
||||
if [[ -f ${temp_path}/init/main.c ]]; then
|
||||
common_kernel_path=${temp_path}
|
||||
COMMON_PATH=$(dirname ${temp_path})
|
||||
elif [[ -f ${temp_path}/common/init/main.c ]]; then
|
||||
common_kernel_path=${temp_path}/common
|
||||
COMMON_PATH=${temp_path}
|
||||
elif [[ -f ${KERNEL_DIR}/init/main.c ]]; then
|
||||
common_kernel_path=$(realpath -s ${KERNEL_DIR})
|
||||
COMMON_PATH=$(realpath -s ${common_kernel_path}/..)
|
||||
else
|
||||
echo "The directory of kernel does not exist";
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
COMMON_DRIVERS_DIR=$(realpath --relative-to=${common_kernel_path} ${common_driver_path})
|
||||
KERNEL_DIR=${common_kernel_path##*/}
|
||||
cd ${COMMON_PATH}
|
||||
|
||||
if [[ ! -f ${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/amlogic_utils.sh ]]; then
|
||||
echo "The directory of common_drivers does not exist";
|
||||
exit
|
||||
fi
|
||||
auto_patch_path=`realpath $0`
|
||||
auto_patch_path=`dirname ${auto_patch_path}`
|
||||
if [[ $# == 1 && -d ${auto_patch_path}/$1 ]]; then
|
||||
FULL_KERNEL_VERSION=$1
|
||||
elif [[ -f ${KERNEL_DIR}/build.config.constants ]]; then
|
||||
version_message=$(grep -rn BRANCH= ${KERNEL_DIR}/build.config.constants)
|
||||
version_message="common${version_message##*android}"
|
||||
FULL_KERNEL_VERSION=${version_message}
|
||||
else
|
||||
version=`grep "^VERSION = " common/Makefile | cut -d ' ' -f 3`
|
||||
patchlevel=`grep "^PATCHLEVEL = " common/Makefile | cut -d ' ' -f 3`
|
||||
matching_paths=$(find ${auto_patch_path} -type d -name "common*-${version}\.${patchlevel}")
|
||||
path_array=($(echo "${matching_paths}"))
|
||||
path_count=${#path_array[@]}
|
||||
if [[ $path_count == 1 ]]; then
|
||||
FULL_KERNEL_VERSION=${matching_paths##*/}
|
||||
if [[ ${DEBUG} == 1 ]]; then
|
||||
echo ENTER_PATH=${ENTER_PATH}
|
||||
echo COMMON_PATH=${COMMON_PATH}
|
||||
echo KERNEL_DIR=${KERNEL_DIR}
|
||||
echo COMMON_DRIVERS_DIR=${COMMON_DRIVERS_DIR}
|
||||
echo AUTO_PATCH_PATH=${AUTO_PATCH_PATH}
|
||||
fi
|
||||
}
|
||||
|
||||
function get_full_kernel_version()
|
||||
{
|
||||
if [[ $# == 1 && -d ${AUTO_PATCH_PATH}/$1 ]]; then
|
||||
FULL_KERNEL_VERSION=$1
|
||||
elif [[ -f ${KERNEL_DIR}/build.config.constants || -f ${KERNEL_DIR}/build.config.common ]]; then
|
||||
version_message=$(grep -rn BRANCH= ${KERNEL_DIR}/build.config.constants)
|
||||
if [[ -z ${version_message} ]]; then
|
||||
version_message=$(grep -rn BRANCH= ${KERNEL_DIR}/build.config.common)
|
||||
fi
|
||||
if [[ -z ${version_message} ]]; then
|
||||
cd ${ENTER_PATH}
|
||||
echo "Can't find BRANCH in build.config.constants and build.config.common"
|
||||
exit
|
||||
fi
|
||||
version_message="common${version_message##*android}"
|
||||
FULL_KERNEL_VERSION=${version_message}
|
||||
else
|
||||
echo "Can't find FULL_KERNEL_VERSION"
|
||||
version=`grep "^VERSION = " common/Makefile | cut -d ' ' -f 3`
|
||||
patchlevel=`grep "^PATCHLEVEL = " common/Makefile | cut -d ' ' -f 3`
|
||||
matching_paths=$(find ${AUTO_PATCH_PATH} -type d -name "common*-${version}\.${patchlevel}")
|
||||
path_array=($(echo "${matching_paths}"))
|
||||
path_count=${#path_array[@]}
|
||||
if [[ $path_count == 1 ]]; then
|
||||
FULL_KERNEL_VERSION=${matching_paths##*/}
|
||||
else
|
||||
cd ${ENTER_PATH}
|
||||
echo "Can't find FULL_KERNEL_VERSION"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
if [[ ${DEBUG} == 1 ]]; then
|
||||
echo FULL_KERNEL_VERSION=${FULL_KERNEL_VERSION}
|
||||
fi
|
||||
PATCHES_PATH=${AUTO_PATCH_PATH}/${FULL_KERNEL_VERSION}
|
||||
if [[ ! -d ${PATCHES_PATH} ]]; then
|
||||
cd ${ENTER_PATH}
|
||||
echo "None patch to am, ${PATCHES_PATH}/${FULL_KERNEL_VERSION}/patches does not exist!!!"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
PATCHES_PATH=${auto_patch_path}/${FULL_KERNEL_VERSION}
|
||||
|
||||
if [[ ! -d ${PATCHES_PATH} ]]; then
|
||||
echo "None patch to am, ${PATCHES_PATH}/${FULL_KERNEL_VERSION}/patches does not exist!!!"
|
||||
cd ${enter_path}
|
||||
exit
|
||||
fi
|
||||
|
||||
# echo KERNEL_DIR=$KERNEL_DIR COMMON_DRIVERS_DIR=$COMMON_DRIVERS_DIR enter_path=$enter_path PATCHES_PATH=$PATCHES_PATH
|
||||
if [[ ${DEBUG} == 1 ]]; then
|
||||
echo PATCHES_PATH=${PATCHES_PATH}
|
||||
fi
|
||||
}
|
||||
|
||||
function am_patch()
|
||||
{
|
||||
@@ -62,37 +83,43 @@ function am_patch()
|
||||
local compare_id=$3
|
||||
local change_id=`grep 'Change-Id' $patch | head -n1 | awk '{print $2}'`
|
||||
|
||||
# echo ${patch} ${dir}
|
||||
if [ -d "${dir}" ]; then
|
||||
cd ${dir};
|
||||
cd ${dir}
|
||||
if [[ ! "${compare_id[@]}" =~ "${change_id}" ]]; then
|
||||
# echo "###patch ${patch##*/}### "
|
||||
if [[ ${DEBUG} == 1 ]]; then
|
||||
echo patch ${dir}/${patch}
|
||||
fi
|
||||
git am -q ${patch} 1>/dev/null 2>&1;
|
||||
if [ $? != 0 ]; then
|
||||
git am --abort
|
||||
cd ${enter_path}
|
||||
cd ${ENTER_PATH}
|
||||
if [[ ${DEBUG} != 1 ]]; then
|
||||
echo
|
||||
fi
|
||||
echo "Patch Error : Failed to patch [$patch], Need check it. exit!!!"
|
||||
exit -1
|
||||
fi
|
||||
echo -n .
|
||||
if [[ ${DEBUG} != 1 ]]; then
|
||||
echo -n .
|
||||
fi
|
||||
fi
|
||||
cd ${common_path}
|
||||
cd ${COMMON_PATH}
|
||||
fi
|
||||
}
|
||||
|
||||
function auto_patch()
|
||||
{
|
||||
local patch_dir=$1
|
||||
# echo patch_dir=$patch_dir
|
||||
|
||||
for file in `find ${patch_dir} -name "*.patch" | sort`; do
|
||||
local file_name=${file%.*}; #echo file_name $file_name
|
||||
local resFile=`basename $file_name`; #echo resFile $resFile
|
||||
local dir_name1=${resFile//#/\/}; #echo dir_name $dir_name
|
||||
local dir_name=${dir_name1%/*}; #echo dir_name $dir_name
|
||||
local dir=${common_path}/$dir_name; #echo $dir
|
||||
local dir=${COMMON_PATH}/$dir_name; #echo $dir
|
||||
|
||||
local compare_change_id=$([[ -d ${dir} ]] && cd ${dir} && git log -n 400 |grep "Change-Id:" | awk '{print $2}')
|
||||
[[ ! -d ${dir}/.git ]] && continue
|
||||
local compare_change_id=$(cd ${dir} && git log -n 50 | grep "Change-Id:" | awk '{print $2}')
|
||||
am_patch ${file} ${dir} "${compare_change_id[@]}"
|
||||
done
|
||||
}
|
||||
@@ -103,9 +130,8 @@ function traverse_patch_dir()
|
||||
echo "Auto Patch Start"
|
||||
{
|
||||
if [[ "${PATCH_PARM}" != "non_common" ]]; then
|
||||
local common_change_id=$(cd ${KERNEL_DIR} && git log -n 400 |grep "Change-Id:" | awk '{print $2}')
|
||||
local common_change_id=$(cd ${KERNEL_DIR} && git log -n 200 | grep "Change-Id:" | awk '{print $2}')
|
||||
for file in `ls ${PATCHES_PATH}/common`; do
|
||||
# echo file=$file
|
||||
if [ -d ${PATCHES_PATH}/common/${file} ]; then
|
||||
for patch in `find ${PATCHES_PATH}/common/${file} -name "*.patch" | sort`; do
|
||||
am_patch ${patch} ${KERNEL_DIR} "${common_change_id[@]}"
|
||||
@@ -116,54 +142,43 @@ function traverse_patch_dir()
|
||||
} &
|
||||
|
||||
{
|
||||
local common_drivers_change_id=$(cd ${KERNEL_DIR}/${COMMON_DRIVERS_DIR} && git log -n 400 |grep "Change-Id:" | awk '{print $2}')
|
||||
if [[ -d ${PATCHES_PATH}/common_drivers ]]; then
|
||||
local common_drivers_change_id=$(cd ${KERNEL_DIR}/${COMMON_DRIVERS_DIR} && git log -n 100 | grep "Change-Id:" | awk '{print $2}')
|
||||
for patch in `find ${PATCHES_PATH}/common_drivers -name "*.patch" | sort`; do
|
||||
am_patch ${patch} ${KERNEL_DIR}/${COMMON_DRIVERS_DIR} "${common_drivers_change_id[@]}"
|
||||
done
|
||||
fi
|
||||
} &
|
||||
|
||||
for file in `ls ${PATCHES_PATH}`; do
|
||||
[[ "${file}" == "common" || "${file}" == "common_drivers" ]] && continue
|
||||
if [ -d ${PATCHES_PATH}/${file} ]; then
|
||||
local dest_dir=${PATCHES_PATH}/${file}
|
||||
|
||||
auto_patch ${dest_dir}
|
||||
fi
|
||||
done
|
||||
[[ -d ${PATCHES_PATH}/tools ]] && auto_patch ${PATCHES_PATH}/tools
|
||||
|
||||
wait
|
||||
echo
|
||||
echo "Patch Finish: ${common_path}"
|
||||
if [[ ${DEBUG} != 1 ]]; then
|
||||
echo
|
||||
fi
|
||||
echo "Patch Finish: ${COMMON_PATH}"
|
||||
}
|
||||
|
||||
function handle_lunch_patch()
|
||||
{
|
||||
echo "Auto Patch lunch's patch Start"
|
||||
|
||||
while read line_patch; do
|
||||
local patch_dir=${line_patch%/*}
|
||||
local patch_file=${line_patch##*/}
|
||||
local file=${PATCHES_PATH}/${patch_dir}/${patch_file}
|
||||
|
||||
local file_name=${file%.*}
|
||||
local resFile=`basename $file_name`
|
||||
local dir_name1=${resFile//#/\/}
|
||||
local dir_name=${dir_name1%/*}
|
||||
local dir=${common_path}/$dir_name
|
||||
|
||||
local compare_change_id=$(cd ${dir} && git log -n 400 |grep "Change-Id:" | awk '{print $2}')
|
||||
am_patch ${file} ${dir} ${compare_change_id}
|
||||
done < ${PATCHES_PATH}/lunch_patches.txt
|
||||
auto_patch ${PATCHES_PATH}/tools
|
||||
|
||||
echo
|
||||
echo "Patch Finish: ${common_path}"
|
||||
echo "Patch Finish: ${COMMON_PATH}"
|
||||
}
|
||||
|
||||
if [[ "${PATCH_PARM}" == "lunch" ]]; then
|
||||
handle_lunch_patch
|
||||
else
|
||||
traverse_patch_dir
|
||||
fi
|
||||
cd ${enter_path}
|
||||
function main()
|
||||
{
|
||||
get_paths_and_enter_common_path
|
||||
get_full_kernel_version $@
|
||||
if [[ "${PATCH_PARM}" == "lunch" ]]; then
|
||||
handle_lunch_patch
|
||||
else
|
||||
traverse_patch_dir
|
||||
fi
|
||||
cd ${ENTER_PATH}
|
||||
}
|
||||
|
||||
main $@
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
tools/external#lz4#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
tools/external#python#absl-py#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
tools/external#toybox#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
tools/external#zlib#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
tools/external#zopfli#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
tools/prebuilts#build-tools#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
tools/prebuilts#clang#host#linux-x86#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
tools/prebuilts#clang-tools#0001-clang-tools-modify-android.bp-to-android_bp-1-1.patch
|
||||
tools/prebuilts#gcc#linux-x86#host#x86_64-linux-glibc2.17-4.8#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
tools/prebuilts#ndk-r26#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
tools/prebuilts#rust#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
tools/prebuilts#tradefed#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
tools/tools#mkbootimg#0001-tool-bring-up-androidu-with-common16-6.12-1-1.patch
|
||||
Reference in New Issue
Block a user