aboutsummaryrefslogtreecommitdiffstats
path: root/build.sh
blob: b0cc4790f6ed8102c43f8eff37bc309f1b264c98 (plain)
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
#!/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"
    # add modules which should be copied after build below
    MODULES=("drivers/net/wireless/bcm4329/bcm4329.ko")

    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
    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"
                    adb reboot
                fi
            done
        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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}

build ()
{
    local target=$1
    echo "Building for $target"
    local target_dir="$BUILD_DIR/$target"
    local module
    [ x = "x$NO_RM" ] && rm -fr "$target_dir"
    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 $DEVICE_CM_DIR/kernel
                cp "$target_dir"/arch/arm/boot/zImage bin/kernel/zImage
                for module in "${MODULES[@]}" ; do
                    cp "$target_dir/$module" $DEVICE_CM_DIR
                    cp "$target_dir/$module" bin/system/modules
                done
                CheckVersion
                CreateKernelZip
                UpgradeMinor
            else
                CompileError
            fi
        else
            CompileError
        fi
    fi
}

setup

if [ "$1" = clean ] ; then
    rm -fr "$BUILD_DIR"/*
    exit 0
fi

targets=("$@")
if [ 0 = "${#targets[@]}" ] ; then
    targets=(crespo)
fi

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