blob: 9e0f7e1c90510eb0051c0a9a7442e689d4f62362 [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3
4green='\e[0;32m'
5red='\e[0;31m'
6eol='\e[0m'
7
8BASE_DIR=$PWD
9ABI_DIR=$BASE_DIR/scripts/abi
10ABIGAIL_DIR=$BASE_DIR/../kernel/build/abi
11ABIGAIL_BUILD_SCRIPT=$ABIGAIL_DIR/bootstrap_src_build
12ABI_XML_DIR=$BASE_DIR/scripts/abi/abi_xml
13#target_kernel must create outside current kernel's repo
14TARGET_KERNEL_DIR=$BASE_DIR/../../target_kernel
15TARGET_DEFCONFIG=mtk_gki_defconfig
16TARGET_DEFCONFIG_PATCH=$ABI_DIR/mtk_gki_defconfig_patch
17TARGET_ABI_XML=abi_$src_defconfig.xml
18TARGET_VMLINUX_DIR=$TARGET_KERNEL_DIR/common/out_vmlinux
19
20echo "Get ABIGAIL_VERSION from $ABIGAIL_BUILD_SCRIPT"
21ABIGAIL_VERSION=`grep "ABIGAIL_VERSION=" $ABIGAIL_BUILD_SCRIPT | cut -f2- -d=`
22ABIGAIL_DIR_RELEASE=$ABIGAIL_DIR/abigail-inst/$ABIGAIL_VERSION
23echo "ABIGAIL_DIR_RELEASE=$ABIGAIL_DIR_RELEASE"
24
25
26cd $TARGET_KERNEL_DIR
27TARGET_KERNEL_DIR_RELATED_PATH=`pwd`
28TARGET_KERNEL_OUT_DIR_RELATED_PATH=$TARGET_KERNEL_DIR_RELATED_PATH/common/out/..
29echo "TARGET_KERNEL_DIR_RELATED_PATH=$TARGET_KERNEL_DIR_RELATED_PATH"
30echo "TARGET_KERNEL_OUT_DIR_RELATED_PATH=$TARGET_KERNEL_OUT_DIR_RELATED_PATH"
31cd $BASE_DIR
32
33function print_usage(){
34 echo -e "${green}Script for auto generate target_branch's ABI xml \
35based 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] \
39mode=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 \
48src_defconfig=k79v1_64_gki_debug_defconfig \
49target_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 \
53for 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=\
64k79v1_64_gki_debug_defconfig \
65target_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
75function 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
84if [[ "$1" == "h" ]] || [[ "$1" == "help" ]] || [ -z "mode" ]
85then
86 print_usage
87fi
88
89if [ "$mode" == "d" ]
90then
91 del_temp_files
92fi
93
94if [ "$mode" == "p" ]
95then
96target_commit=d8a623c #ACK4.19.80
97echo src_commit=$src_commit
98echo target_commit=$target_commit
99fi
100
101if [ "$mode" == "m" ] || [ "$mode" == "p" ]
102then
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 \
108commit 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 \
120with 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 \
158in $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
177fi