-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpacksrc.sh
executable file
·409 lines (354 loc) · 10.2 KB
/
packsrc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#!/bin/bash
# file : packsrc.sh
# usage : packsrc.sh -p [rk2928,rk3066,rk3168,rk3188] [-r]
# -r - for recover files
# author : Cody Xie
# modify : 2013-03-29 created.
# 2013-04-01 tested on rk2928 android 4.2 sdk
# TODO : test for 4.1 and other platform, add support bin
# tar all source code exclude prebuilt libraries
which git > /dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "git does not exist"
exit 1
fi
which sed > /dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "sed does not exist"
exit 1
fi
which tar > /dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "tar does not exist"
exit 1
fi
RECOVER_ONLY=0
# check all parameters
if [ $# -lt 1 ] ; then
echo "usage : $0 -p [rk2928,rk3066,rk3026,rk3168,rk3188] [-r]"
echo " -r - for recover files"
exit 1
else
while getopts "p:rv:" arg
do
case $arg in
p)
TARGET_PLATFORM=$OPTARG
;;
# v)
# TARGET_VERSION=$OPTARG
# ;;
r)
RECOVER_ONLY=1
;;
\?)
echo "usage : $0 -p [rk2928,rk3066,rk3026,rk3168,rk3188] [-r]"
echo " -r - for recover files"
exit 1
;;
esac
done
case $TARGET_PLATFORM in
"rk3188")
TARGET_PRODUCT=rk30sdk
TARGET_BOARD=rk30board
;;
"rk3066")
TARGET_PRODUCT=rk30sdk
TARGET_BOARD=rk30board
;;
"rk3026")
TARGET_PRODUCT=rk30sdk
TARGET_BOARD=rk30board
;;
"rk3168")
TARGET_PRODUCT=rk30sdk
TARGET_BOARD=rk30board
;;
"rk2928")
TARGET_PRODUCT=rk2928sdk
TARGET_BOARD=rk2928board
;;
*)
echo "usage : $0 -p [rk2928,rk3066,rk3026,rk3168,rk3188] [-r]"
echo " -r - for recover files"
exit 1
;;
esac
fi
echo "======================================================"
echo "patching $TARGET_PRODUCT $TARGET_BOARD $TARGET_VERSION"
echo "======================================================"
TOPDIR=$PWD
TARGET_OUT=out/target/product/$TARGET_PRODUCT
COMMON_PATH=device/rockchip/common
source $TOPDIR/build/envsetup.sh > /dev/null 2>&1
LIBSRCDIRS=(
hardware/rk29/hwcomposer_rga
hardware/rk29/libgralloc_ump
hardware/rk29/libyuvtorgb
frameworks/base/libs/hwui
frameworks/native/libs/gui
frameworks/av/libvideoeditor
frameworks/base/media/jni/mediaeditor
)
OUTLIBPATHS=(
system/lib
)
AUTOMKDIRS=(
$COMMON_PATH/proprietary/lib
$COMMON_PATH/proprietary/bin
)
EXCLUDEDIRS=(.git .repo)
function get_soarray () {
if [ ${#LIBSRCDIRS[*]} -eq 0 ] ; then
return 1
fi
[ ! -e _tmp ] || rm -f _tmp
for d in ${LIBSRCDIRS[*]}
do
pushd $d > /dev/null 2>&1
grep BUILD_SHARED_LIBRARY * -rl | xargs grep LOCAL_MODULE[^_] -r >> $TOPDIR/_tmp
popd > /dev/null 2>&1
done
sed -i "s/\$(TARGET_BOARD_HARDWARE)/"$TARGET_BOARD"/g" $TOPDIR/_tmp
sed -i 's/.*=//g' $TOPDIR/_tmp
sed -i 's/^[ ]*//g' $TOPDIR/_tmp
sed -i 's/*[ ]$//g' $TOPDIR/_tmp
sed -i 's/$/.so/g' $TOPDIR/_tmp
echo `cat $TOPDIR/_tmp`
rm -f _tmp
}
function get_binarray () {
if [ ${#LIBSRCDIRS[*]} -eq 0 ] ; then
return 1
fi
[ ! -e _tmp ] || rm -f _tmp
for d in ${LIBSRCDIRS[*]}
do
pushd $d > /dev/null 2>&1
grep BUILD_SHARED_LIBRARY * -rl | xargs grep LOCAL_MODULE[^_] -r >> $TOPDIR/_tmp
popd > /dev/null 2>&1
done
sed -i "s/\$(TARGET_BOARD_HARDWARE)/"$TARGET_BOARD"/g" $TOPDIR/_tmp
sed -i 's/.*=//g' $TOPDIR/_tmp
sed -i 's/^[ ]*//g' $TOPDIR/_tmp
sed -i 's/*[ ]$//g' $TOPDIR/_tmp
sed -i 's/$/.so/g' $TOPDIR/_tmp
echo `cat $TOPDIR/_tmp`
rm -f _tmp
}
function checkout_file () {
echo "checking out files..."
for d in ${LIBSRCDIRS[*]}
do
pushd $d > /dev/null
git checkout -f
popd > /dev/null
done
}
function rebuild_files () {
local dedicated=$1
if [ "$dedicated" == "dedicated" ] ; then
sed -i '/BOARD_USE_LCDC_COMPOSER/c BOARD_USE_LCDC_COMPOSER ?= true' device/rockchip/$TARGET_PRODUCT/BoardConfig.mk
for d in ${LIBSRCDIRS[*]}
do
pushd $d
mm -B
popd
done
else
sed -i '/BOARD_USE_LCDC_COMPOSER/c BOARD_USE_LCDC_COMPOSER ?= false' device/rockchip/$TARGET_PRODUCT/BoardConfig.mk
for d in ${LIBSRCDIRS[*]}
do
pushd $d
mm -B
popd
done
fi
}
function get_so_outpath () {
local libs=(`echo $@`)
cd $TARGET_OUT > /dev/null 2>&1
for lib in ${libs[*]}
do
for d in $OUTLIBPATHS
do
pushd $TOPDIR/$TARGET_OUT/$d > /dev/null 2>&1
echo $d`find -name $lib | sed -e 's/^\.//g'` | grep $lib
popd > /dev/null 2>&1
done
done
cd - > /dev/null 2>&1
}
function make_dir () {
[ -d $COMMON_PATH/proprietary/lib/osmem ] || mkdir -p $COMMON_PATH/proprietary/lib/osmem
[ -d $COMMON_PATH/proprietary/lib/dedicated ] || mkdir -p $COMMON_PATH/proprietary/lib/dedicated
[ -d $COMMON_PATH/proprietary/bin ] || mkdir -p $COMMON_PATH/proprietary/bin
}
function copy_libs () {
local dedicated=$1
shift
local so_libs=(`echo $@`)
make_dir
for so in ${so_libs[*]}
do
if [ "$dedicated" != "dedicated" ] ; then
cp -f $TARGET_OUT/$so $COMMON_PATH/proprietary/lib/osmem
else
cp -f $TARGET_OUT/$so $COMMON_PATH/proprietary/lib/dedicated
fi
done
}
function generate_mk () {
local dedicated1=$1
shift
local so_paths=(`echo $@`)
echo "# File : AUTO GENERATED MAKE FILE"
echo "# Date : `date`"
echo "# Author : `whoami`"
echo "# ==============================================="
echo "LOCAL_PATH := \$(call my-dir)"
if [ "$dedicated1" == "dedicated" ] ; then
echo "ifeq (\$(strip \$(BOARD_USE_LCDC_COMPOSER)), true)"
else
echo "ifeq (\$(strip \$(BOARD_USE_LCDC_COMPOSER)), false)"
fi
local i=0
for so in ${so_paths[*]}
do
echo ""
echo "include \$(CLEAR_VARS)"
echo "LOCAL_PREBUILT_LIBS := `basename ${so_paths[$i]}`"
echo "LOCAL_MODULE_PATH := \$(PRODUCT_OUT)/`dirname ${so_paths[$i]}`"
echo "LOCAL_MODULE_TAGS := optional"
echo "include \$(BUILD_MULTI_PREBUILT)"
echo ""
i=$(($i+1))
done
echo "endif"
echo ""
}
function generate_copy_mk () {
local so_libs2=(`echo $@ | sed -e 's/system.*\.so//g'`)
for arg in $@
do
echo $arg | grep "system"
done > tmp
local so_paths=(`cat tmp`)
rm -f tmp
echo "# File : AUTO GENERATED MAKE FILE"
echo "# Date : `date`"
echo "# Author : `whoami`"
echo "# ==============================================="
echo "ifeq (\$(strip \$(BOARD_USE_LCDC_COMPOSER)), true)"
echo "PRODUCT_COPY_FILES += \\"
i=0
for so in ${so_libs2[*]}
do
echo "${so_paths[$i]}" | grep -q "$so"
if [ $? -eq 0 ] ; then
if [ $i -lt $((${#so_libs2[*]} - 1)) ] ; then
echo " $COMMON_PATH/proprietary/lib/dedicated/$so:${so_paths[$i]} \\"
else
echo " $COMMON_PATH/proprietary/lib/dedicated/$so:${so_paths[$i]}"
fi
else
echo "$COMMON_PATH/proprietary/lib/dedicated/$so does not exist!!!"
fi
i=$(($i + 1))
done
echo ""
echo "else"
echo "PRODUCT_COPY_FILES += \\"
i=0
for so in ${so_libs2[*]}
do
echo "${so_paths[$i]}" | grep -q "$so"
if [ $? -eq 0 ] ; then
if [ $i -lt $((${#so_libs2[*]} - 1)) ] ; then
echo " $COMMON_PATH/proprietary/lib/osmem/$so:${so_paths[$i]} \\"
else
echo " $COMMON_PATH/proprietary/lib/osmem/$so:${so_paths[$i]}"
fi
else
echo "$COMMON_PATH/proprietary/lib/osmem/$so does not exist!!!"
fi
i=$(($i + 1))
done
echo "endif"
echo ""
}
function modify_device_mk () {
local mk=$1
sed -i '/rk_proprietary/d' $mk
sed -i '$a\include '$COMMON_PATH'\/proprietary\/rk_proprietary\.mk' $mk
}
function recover_files () {
rm -f _tmp
rm -rf $COMMON_PATH/proprietary/
sed -i '/rk_proprietary/d' $TOPDIR/device/rockchip/$TARGET_PRODUCT/device.mk
[ -d out ] || mv ../rkTmpOut out
checkout_file
}
function tar_all () {
set -x
cd $TOPDIR/kernel
./pack-kernel.sh $TARGET_PLATFORM
cd $TOPDIR
.repo/repo/repo manifest -r -o version-tag.xml
mv out ../rkTmpOut
mv kernel ../rkTmpKernel
tar zxvf kernel.tar.gz kernel/
mv kernel.tar* ../
for d in ${LIBSRCDIRS[*]}
do
pushd $d
find -regex '.*\.\(c\|cpp\|cxx\|mk\)' | xargs rm -f
popd
done
rm -f ../_tmp
for d in ${EXCLUDEDIRS[*]}
do
echo "--exclude=$d " >> ../_tmp
done
local excludes=(`cat ../_tmp`)
tar -zcf ../"$TARGET_PLATFORM"_release.tar ${excludes[*]} --exclude=device/rockchip/rk29sdk/asound-for-rt5625.conf.bak ../`basename $TOPDIR`
rm -f ../_tmp
rm -r kernel
mv ../rkTmpOut out
mv ../rkTmpKernel kernel
set +x
}
function my_main () {
recover_files
if [ $RECOVER_ONLY -eq 1 ] ; then
exit;
fi
so_array=(`get_soarray`)
if [ $? -eq 1 ] ; then
echo "no file"
exit 1
fi
so_paths=(`get_so_outpath ${so_array[*]}`)
local original=`sed -n "/BOARD_USE_LCDC_COMPOSER/p" device/rockchip/$TARGET_PRODUCT/BoardConfig.mk`
echo "ORIGNAL is $original"
# TODO : add support bin
if [ "$TARGET_PLATFORM" == "rk3188" ] ; then
rebuild_files "dedicated"
copy_libs "dedicated" ${so_paths[*]}
fi
rebuild_files "osmem"
copy_libs "osmem" ${so_paths[*]}
sed -i "/BOARD_USE_LCDC_COMPOSER/c $original" device/rockchip/$TARGET_PRODUCT/BoardConfig.mk
generate_copy_mk ${so_array[*]} ${so_paths[*]} > $COMMON_PATH/proprietary/rk_proprietary.mk
if [ "$TARGET_PLATFORM" == "rk3188" ] ; then
#generate_mk "dedicated" ${so_array[*]} > $COMMON_PATH/proprietary/lib/dedicated/Android.mk
generate_mk "dedicated" ${so_paths[*]} > $COMMON_PATH/proprietary/lib/dedicated/Android.mk
fi
#generate_mk "osmem" ${so_array[*]} > $COMMON_PATH/proprietary/lib/osmem/Android.mk
generate_mk "osmem" ${so_paths[*]} > $COMMON_PATH/proprietary/lib/osmem/Android.mk
modify_device_mk $TOPDIR/device/rockchip/$TARGET_PRODUCT/device.mk
tar_all
}
my_main