-
Notifications
You must be signed in to change notification settings - Fork 81
/
build.sh
executable file
·203 lines (183 loc) · 5.46 KB
/
build.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
#!/bin/bash
BOARD=crespo
DEVICEDIR=/sdcard/AROM
KNAME=kernel.cyano.RELEASE
DEVICE_CM_DIR=$ANDROID_BUILD_TOP/device/samsung/${BOARD}
WaitForDevice()
{
adb start-server
if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
echo "No device is online. Waiting for one..."
echo "Please connect USB and/or enable USB debugging"
until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
sleep 1
done
echo "Device Found.."
fi
}
setup ()
{
if [ x = "x$ANDROID_BUILD_TOP" ] ; then
echo "Android build environment must be configured"
exit 1
fi
. "$ANDROID_BUILD_TOP"/build/envsetup.sh
KERNEL_DIR="$(dirname "$(readlink -f "$0")")"
BUILD_DIR="$KERNEL_DIR/build"
if [ x = "x$NO_CCACHE" ] && ccache -V &>/dev/null ; then
CCACHE=ccache
CCACHE_BASEDIR="$KERNEL_DIR"
CCACHE_COMPRESS=1
CCACHE_DIR="$BUILD_DIR/.ccache"
export CCACHE_DIR CCACHE_COMPRESS CCACHE_BASEDIR
else
CCACHE=""
fi
CROSS_PREFIX="$ANDROID_BUILD_TOP/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-"
}
CheckVersion ()
{
if [ ! -f .Mayor ]
then
echo 1 > .Mayor
fi
if [ ! -f .Minor ]
then
echo 0 > .Minor
fi
sVersion=$(cat build/${BOARD}/include/config/kernel.release)
echo $sVersion
sVersionMerge=${sVersion:(-8)}
echo sVersionMerge
iMayor=$(cat .Mayor)
iMinor=$(cat .Minor)
}
CreateKernelZip ()
{
cd bin
rm *.zip
KZIPNAME=$KNAME.v$iMayor.$iMinor.$sVersionMerge.zip
zip $KZIPNAME * -r
if [ "$responseSend" == "y" ] ; then
WaitForDevice
echo Going into fastboot
if adb reboot-bootloader ; then
sleep 4
echo Pushing kernel file
if fastboot flash zimage kernel/zImage ; then
sleep 1
fastboot reboot
WaitForDevice
sleep 2
adb root
sleep 4
adb remount
sleep 2
echo Sending modules
for filename in system/modules/* ; do
echo Sending $filename to /system/modules
if adb push $filename /system/modules ; then
echo "Rebooting again"
fi
done
adb reboot
fi
fi
fi
cd ..
echo $KZIPNAME
}
UpgradeMinor ()
{
iMinor=$(($iMinor+1))
echo $iMinor > .Minor
}
CompileError ()
{
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo ! COMPILACION FAILED
echo !
echo !
echo ! ---------------------- COMPILACION ERROR CODE: $RET
echo !
echo !
echo !
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
SenModulesToCMDevice()
{
CURDIR=`pwd`;
cd bin/system/modules
rm $DEVICE_CM_DIR/KernelModules.mk
echo "# Kernel Modules TO BE COPIED" > $DEVICE_CM_DIR/KernelModules.mk
echo 'PRODUCT_COPY_FILES += \' >> $DEVICE_CM_DIR/KernelModules.mk
MODULEF=( $(find * -type f) )
# get length of an array
tLen=${#MODULEF[@]}
# use for loop read all modules but not the last
for (( i=0; i<${tLen}-1; i++ ));
do
echo ' device/samsung/'${BOARD}'/'${MODULEF[$i]}':system/modules/'${MODULEF[$i]}' \' >>$DEVICE_CM_DIR/KernelModules.mk
echo ${MODULEF[$i]}
done
echo ' device/samsung/'${BOARD}'/'${MODULEF[$i]}':system/modules/'${MODULEF[$i]} >>$DEVICE_CM_DIR/KernelModules.mk
cd $CURDIR
}
build ()
{
local target=$1
echo "Building for $target"
local target_dir="$BUILD_DIR/$target"
local module
[ x = "x$NO_RM" ]
mkdir -p "$target_dir"
[ x = "x$NO_DEFCONFIG" ] && mka -C "$KERNEL_DIR" O="$target_dir" ARCH=arm ${BOARD}_defconfig HOSTCC="$CCACHE gcc"
if [ x = "x$NO_BUILD" ] ; then
mka -C "$KERNEL_DIR" O="$target_dir" ARCH=arm HOSTCC="$CCACHE gcc" CROSS_COMPILE="$CCACHE $CROSS_PREFIX" modules
RET=$?
if [[ $RET == 0 ]] ; then
mka -C "$KERNEL_DIR" O="$target_dir" ARCH=arm HOSTCC="$CCACHE gcc" CROSS_COMPILE="$CCACHE $CROSS_PREFIX" zImage
RET=$?
if [[ $RET == 0 ]] ; then
cp "$target_dir"/arch/arm/boot/zImage bin/kernel/zImage
MODULES=( $(find $target_dir/* -type f -name *.ko) )
for module in "${MODULES[@]}" ; do
echo $module
cp "$module" bin/system/lib/modules
done
# SenModulesToCMDevice
CheckVersion
CreateKernelZip
UpgradeMinor
else
CompileError
fi
else
CompileError
fi
fi
}
setup
echo Type y + \"intro\" to send kernel to your mobile:
read -t 10 responseSend;
if [ "$responseSend" == "y" ] ; then
echo Sending to device after build .. $responseSend
else
echo Only compile .. $responseSend
fi
if [ "$1" = clean ] ; then
rm -fr "$BUILD_DIR"/*
exit 0
fi
targets=(crespo)
START=$(date +%s)
for target in "${targets[@]}" ; do
build $target
done
END=$(date +%s)
ELAPSED=$((END - START))
E_MIN=$((ELAPSED / 60))
E_SEC=$((ELAPSED - E_MIN * 60))
printf "Elapsed: "
[ $E_MIN != 0 ] && printf "%d min(s) " $E_MIN
printf "%d sec(s)\n" $E_SEC