| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0 |
| 3 | |
| 4 | green='\e[0;32m' |
| 5 | red='\e[0;31m' |
| 6 | eol='\e[0m' |
| 7 | |
| 8 | BASE_DIR=$PWD |
| 9 | ABI_DIR=$BASE_DIR/scripts/abi |
| 10 | ABIGAIL_DIR=$BASE_DIR/../kernel/build/abi |
| 11 | ABIGAIL_BUILD_SCRIPT=$ABIGAIL_DIR/bootstrap_src_build |
| 12 | ABI_XML_DIR=$BASE_DIR/scripts/abi/abi_xml |
| 13 | #target_kernel must create outside current kernel's repo |
| 14 | TARGET_KERNEL_DIR=$BASE_DIR/../../target_kernel |
| 15 | TARGET_DEFCONFIG=mtk_gki_defconfig |
| 16 | TARGET_DEFCONFIG_PATCH=$ABI_DIR/mtk_gki_defconfig_patch |
| 17 | TARGET_ABI_XML=abi_$src_defconfig.xml |
| 18 | TARGET_VMLINUX_DIR=$TARGET_KERNEL_DIR/common/out_vmlinux |
| 19 | |
| 20 | echo "Get ABIGAIL_VERSION from $ABIGAIL_BUILD_SCRIPT" |
| 21 | ABIGAIL_VERSION=`grep "ABIGAIL_VERSION=" $ABIGAIL_BUILD_SCRIPT | cut -f2- -d=` |
| 22 | ABIGAIL_DIR_RELEASE=$ABIGAIL_DIR/abigail-inst/$ABIGAIL_VERSION |
| 23 | echo "ABIGAIL_DIR_RELEASE=$ABIGAIL_DIR_RELEASE" |
| 24 | |
| 25 | |
| 26 | cd $TARGET_KERNEL_DIR |
| 27 | TARGET_KERNEL_DIR_RELATED_PATH=`pwd` |
| 28 | TARGET_KERNEL_OUT_DIR_RELATED_PATH=$TARGET_KERNEL_DIR_RELATED_PATH/common/out/.. |
| 29 | echo "TARGET_KERNEL_DIR_RELATED_PATH=$TARGET_KERNEL_DIR_RELATED_PATH" |
| 30 | echo "TARGET_KERNEL_OUT_DIR_RELATED_PATH=$TARGET_KERNEL_OUT_DIR_RELATED_PATH" |
| 31 | cd $BASE_DIR |
| 32 | |
| 33 | function print_usage(){ |
| 34 | echo -e "${green}Script for auto generate target_branch's ABI xml \ |
| 35 | based on src_defconfig ${eol}" |
| 36 | echo "" |
| 37 | echo -e "${red}Command for local test:${eol}" |
| 38 | echo "[src_commit] [src_defconfig] [target_branch] [target_commit] \ |
| 39 | mode=m ./scripts/abi/genOriABIxml.sh" |
| 40 | echo "" |
| 41 | echo -e "${green}Description:${eol}" |
| 42 | echo "[src_commit]: source kernel commit id" |
| 43 | echo "[src_defconfig]: source project defconfig" |
| 44 | echo "[target_branch]: target branch" |
| 45 | echo "[target_commit]: target kernel commit id" |
| 46 | echo "" |
| 47 | echo -e "${green}Example:${eol} ${red}src_commit=491f0e3 \ |
| 48 | src_defconfig=k79v1_64_gki_debug_defconfig \ |
| 49 | target_branch=common-android-4.19 target_commit=f232ce6 mode=m \ |
| 50 | ./scripts/abi/genOriABIxml.sh 2>&1 | tee buildOriABI.log${eol}" |
| 51 | echo "" |
| 52 | echo -e "${green}Script for auto generate target_branch's ABI xml \ |
| 53 | for preflight based on src_defconfig ${eol}" |
| 54 | echo "" |
| 55 | echo -e "${red}Command for local test:${eol}" |
| 56 | echo "[src_defconfig] [target_branch] mode=p \ |
| 57 | ./scripts/abi/genOriABIxml.sh" |
| 58 | echo "" |
| 59 | echo -e "${green}Description:${eol}" |
| 60 | echo "[src_defconfig]: source project defconfig" |
| 61 | echo "[target_branch]: target branch" |
| 62 | echo "" |
| 63 | echo -e "${green}Example:${eol} ${red}src_defconfig=\ |
| 64 | k79v1_64_gki_debug_defconfig \ |
| 65 | target_branch=common-android-4.19 mode=p \ |
| 66 | ./scripts/abi/genOriABIxml.sh 2>&1 | tee buildOriABI.log${eol}" |
| 67 | echo "" |
| 68 | echo -e "${red}Command for delete temp files:${eol}" |
| 69 | echo "mode=d ./scripts/abi/genOriABIxml.sh" |
| 70 | echo "" |
| 71 | echo -e "${green}Example:${eol} ${red}mode=d \ |
| 72 | ./scripts/abi/genOriABIxml.sh${eol}" |
| 73 | } |
| 74 | |
| 75 | function del_temp_files(){ |
| 76 | echo "Start delete temp files..." |
| 77 | echo "Delete temp files $BASE_DIR/out" |
| 78 | rm -rf $BASE_DIR/out |
| 79 | echo "Delete temp files $TARGET_KERNEL_DIR" |
| 80 | rm -rf $TARGET_KERNEL_DIR |
| 81 | #rm -rf $ABI_XML_DIR/$TARGET_ABI_XML |
| 82 | } |
| 83 | |
| 84 | if [[ "$1" == "h" ]] || [[ "$1" == "help" ]] || [ -z "mode" ] |
| 85 | then |
| 86 | print_usage |
| 87 | fi |
| 88 | |
| 89 | if [ "$mode" == "d" ] |
| 90 | then |
| 91 | del_temp_files |
| 92 | fi |
| 93 | |
| 94 | if [ "$mode" == "p" ] |
| 95 | then |
| 96 | target_commit=d8a623c #ACK4.19.80 |
| 97 | echo src_commit=$src_commit |
| 98 | echo target_commit=$target_commit |
| 99 | fi |
| 100 | |
| 101 | if [ "$mode" == "m" ] || [ "$mode" == "p" ] |
| 102 | then |
| 103 | #Build libabigail first |
| 104 | $ABIGAIL_BUILD_SCRIPT |
| 105 | #remove temp files first |
| 106 | del_temp_files |
| 107 | echo "Generate .config from src_defconfig:$src_defconfig with kernel \ |
| 108 | commit id:$src_commit" |
| 109 | cd .. |
| 110 | export PATH=\ |
| 111 | $PWD/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/:\ |
| 112 | $PWD/prebuilts/clang/host/linux-x86/clang-r353983c/bin/:$PATH |
| 113 | cd $BASE_DIR |
| 114 | git checkout $src_commit |
| 115 | make ARCH=arm64 CLANG_TRIPLE=aarch64-linux-gnu- \ |
| 116 | CROSS_COMPILE=aarch64-linux-android- \ |
| 117 | CC=clang $src_defconfig O=out |
| 118 | |
| 119 | echo "Generate ABI xml:$TARGET_ABI_XML of target_branch:$target_branch \ |
| 120 | with commit id:$target_commit" |
| 121 | mkdir $TARGET_KERNEL_DIR |
| 122 | cd $TARGET_KERNEL_DIR |
| 123 | repo init -u http://gerrit.mediatek.inc:8080/kernel/manifest -b $target_branch |
| 124 | mosesq mtk_repo sync -f -j8 --no-clone-bundle -c --no-tags |
| 125 | |
| 126 | export PATH=\ |
| 127 | $PWD/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/:\ |
| 128 | $PWD/prebuilts-master/clang/host/linux-x86/clang-r353983c/bin/:$PATH |
| 129 | cd common |
| 130 | git checkout $target_commit |
| 131 | echo "Move .config from $BASE_DIR/out to \ |
| 132 | $PWD/arch/arm64/configs/$TARGET_DEFCONFIG" |
| 133 | cp $BASE_DIR/out/.config arch/arm64/configs/$TARGET_DEFCONFIG |
| 134 | #Modify $TARGET_DEFCONFIG configs according to $TARGET_DEFCONFIG_PATCH |
| 135 | exec < $TARGET_DEFCONFIG_PATCH |
| 136 | while read line |
| 137 | do |
| 138 | #get string before "=" |
| 139 | config_=${line%%=*} |
| 140 | #replace matched string |
| 141 | sed -i "/$config_/c\\$line" \ |
| 142 | $PWD/arch/arm64/configs/$TARGET_DEFCONFIG |
| 143 | done |
| 144 | |
| 145 | make ARCH=arm64 CLANG_TRIPLE=aarch64-linux-gnu- \ |
| 146 | CROSS_COMPILE=aarch64-linux-android- CC=clang $TARGET_DEFCONFIG O=out |
| 147 | mosesq make ARCH=arm64 CLANG_TRIPLE=aarch64-linux-gnu- \ |
| 148 | CROSS_COMPILE=aarch64-linux-android- CC=clang O=out -j24 -k |
| 149 | |
| 150 | #Only use vmlinux to generate ABI xml |
| 151 | echo "Copy vmlinux from $PWD/out to $PWD/out_vmlinux" |
| 152 | mkdir out_vmlinux |
| 153 | cp out/vmlinux out_vmlinux |
| 154 | |
| 155 | #Use abi_dump to generate $TARGET_ABI_XML |
| 156 | #export $ABIGAIL_DIR bin and lib |
| 157 | echo "Generate $ABI_XML_DIR/$TARGET_ABI_XML from vmlinux \ |
| 158 | in $TARGET_VMLINUX_DIR" |
| 159 | export PATH=${ABIGAIL_DIR_RELEASE}/bin:${PATH} |
| 160 | export LD_LIBRARY_PATH=${ABIGAIL_DIR_RELEASE}/lib:\ |
| 161 | ${ABIGAIL_DIR_RELEASE}/lib/elfutils:${LD_LIBRARY_PATH} |
| 162 | cd $ABIGAIL_DIR |
| 163 | python dump_abi --linux-tree $TARGET_VMLINUX_DIR \ |
| 164 | --out-file $ABI_XML_DIR/$TARGET_ABI_XML |
| 165 | |
| 166 | # sanitize the abi.xml by removing any occurences of the kernel path |
| 167 | cd $TARGET_KERNEL_DIR |
| 168 | sed -i "s#$TARGET_KERNEL_OUT_DIR_RELATED_PATH/##g" \ |
| 169 | $ABI_XML_DIR/$TARGET_ABI_XML |
| 170 | # now also do that with any left over paths sneaking in |
| 171 | # (e.g. from the prebuilts) |
| 172 | sed -i "s#$TARGET_KERNEL_DIR_RELATED_PATH/##g" \ |
| 173 | $ABI_XML_DIR/$TARGET_ABI_XML |
| 174 | |
| 175 | #remove temp files |
| 176 | del_temp_files |
| 177 | fi |