forked from bmc08gt/local_manifest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-clean-kernel
executable file
·179 lines (152 loc) · 5.87 KB
/
build-clean-kernel
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
#!/bin/bash
# Copyright (C) 2013 BMc08GT
# Build Script. Use bash to run this script, bash build-clean-kernel from root of source tree
# Args:
# $1 = feed device
# requires vendor/<rom>/tools structure with zip/* and mkbootimg inside
# example: bash ./vendor/aokp/tools/build-clean-kernel d2vzw
#############################################################
DEVICE=$1;
# Tools location housing tools for this script
TOOLS_LOC=vendor/*/tools
ZIP_LOC=$TOOLS_LOC/zip
#Find manufacturer based on device
MANF=`find device/*/ -name $DEVICE`;
MANF=${MANF%/*};
MANF=${MANF##*/};
# Defconfig
DEFCONFIG=`grep -rH 'defconfig' device/$MANF/$DEVICE `;
DEFCONFIG=${DEFCONFIG##*:};
DEFCONFIG=`echo $DEFCONFIG | cut -c3- `;
# Kernel path
KERNELPATH=` find kernel/$MANF -name $DEFCONFIG `;
KERNELPATH=${KERNELPATH%/*/*/*/*};
CHECK_FOR_DEVICE_INIT=` find device/$MANF/$DEVICE -name init.* `;
CHECK_INC_SECONDARY=`grep -rH "inherit-product, device/$MANF/" device/$MANF/$DEVICE/device.mk`;
if [ "$CHECK_INC_SECONDARY" != '' ]; then
CHECK_INC_SECONDARY=${CHECK_INC_SECONDARY##*,};
CHECK_INC_SECONDARY=${CHECK_INC_SECONDARY%?};
SECONDARY_INITS=${CHECK_INC_SECONDARY#/*};
SECONDARY_INITS=` find $SECONDARY_INITS -name init.* `;
CHECK_INC_TERTIARY=` grep -rH "inherit-product, device/$MANF" $CHECK_INC_SECONDARY `;
if [ "$CHECK_INC_TERTIARY" != '' ]; then
CHECK_INC_TERTIARY=${CHECK_INC_TERTIARY##*,};
CHECK_INC_TERTIARY=${CHECK_INC_TERTIARY%?};
TERTIARY_INITS=${CHECK_INC_TERTIAARY#/*};
TERTIARY_INITS=` find $TERTIARY_INITS -name init.* `;
CHECK_INC_QUARTENARY=` grep -rH "inherit-product, device/$MANF" $CHECK_INC_TERTIARY `;
if [ "$CHECK_INC_QUARTENARY" != '' ]; then
CHECK_INC_QUARTENARY=${CHECK_INC_QUARTENARY##*,};
CHECK_INC_QUARTENARY=${CHECK_INC_QUARTENARY%?};
QUARTENARY_INITS=${CHECK_INC_QUARTENARY#/*};
QUARTENARY_INITS=` find $QUARTENARY_INITS -name init.* `;
fi
fi
fi
# Grab ramdisk args based on manufacturer and device
RAMDISK_ARGS_FILE=`grep -rH $KERNELSRC device/$MANF `;
RAMDISK_ARGS_FILE=${RAMDISK_ARGS%%:*};
ARGS_DIRECTORY=${RAMDISK_ARGS%/*};
ABOOT_HW=`grep -rH 'androidboot.hardware' $ARGS_DIRECTORY `;
ABOOT_HW=${ABOOT_HW##*:};
ABOOT_HW=`echo $ABOOT_HW | cut -c3- `;
ABOOT_HW=${ABOOT_HW#*=};
BASE=`grep -rH 'BOARD_KERNEL_BASE' $ARGS_DIRECTORY `;
BASE=${BASE##*x};
OFFSET=`grep -rH 'ramdisk_offset' $ARGS_DIRECTORY `;
OFFSET=${OFFSET##*x};
ADDR=` expr $BASE + $OFFSET `
#############################################################
# Export above variables
export $DEVICE;
export $TOOLS_LOC;
export $ZIP_LOC;
export $MANF;
export $DEFCONFIG;
export $KERNELPATH;
export $CHECK_FOR_DEVICE_INIT;
export $CHECK_INC_SECONDARY;
export $SECONDARY_INITS;
export $CHECK_INC_TERTIARY;
export $TERTIARY_INITS;
export $CHECK_INC_QUARTENARY;
export $QUARTENARY_INITS;
export $RAMDISK_ARGS;
export $ARGS_DIRECTORY;
export $ABOOT_HW;
export $BASE;
export $ADDR;
# Source Directory PATH
# Script is executed from vendor/<rom>/tools so cd back to tree root
export DIRSRC="$( cd ../../.. && pwd)";
# Kernel Source PATH
export KERNELSRC=$DIRSRC/$KERNELPATH;
# Clean-kernel output
mkdir -p out && mkdir -p out/clean-kernel;
export CLEAN_DIR=$DIRSRC/out/clean-kernel/;
# Target gcc version
export TARGET_GCC=4.7;
export ARM_EABI_TOOLCHAIN=$DIRSRC/prebuilts/gcc/linux-x86/arm/arm-eabi-$TARGET_GCC;
export PATH=$PATH:$ARM_EABI_TOOLCHAIN/bin:$ARM_EABI_TOOLCHAIN/arm-eabi/bin;
# Cross compile with arm
export ARCH=arm;
export CCOMPILE=$CROSS_COMPILE;
export CROSS_COMPILE=$ARM_EABI_TOOLCHAIN/bin/arm-eabi-;
#############################################################
echo "Cleaning target kernel source";
cd $KERNELSRC && make -C $KERNELSRC -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@" clean;
# Start the build
echo "";
echo "Starting the kernel build";
echo "";
make -C $KERNELSRC -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@" $DEFCONFIG && time make -C $KERNELSRC -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@" zImage && make -C $KERNELSRC -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@" modules;
# Creating spoof pkg directories for zip
if [ ! -e $ZIP_LOC ]; then
echo " No $ZIP_LOC!! Must have prebuilt zip location for spoofing to create package!";
exit;
else
cp -R $ZIP_LOC $KERNELSRC;
fi
mkdir -p $KERNELSRC/ramdisk;
#############################################################
# Find modules and prepare them for packaging
cd $KERNELSRC;
find drivers -name "*.ko" | xargs $CROSS_COMPILE-strip --strip-unneeded;
find drivers -name "*.ko" | xargs -i cp {} zip/system/lib/modules/;
# Dyanmically find ramdisk and prepare for packaging
cd ramdisk;
cp system/core/rootdir/init.rc .;
cp system/core/rootdir/ueventd.rc .;
# Use above inc_paths to find init files and cp them here overriding the system/core counterpart
if [ "$CHECK_FOR_DEVICE_INIT" != "" ]; then
echo $CHECK_FOR_DEVICE_INIT | sed -e 's/\s\+/\n/g' | (while read line; do
cp -f $line .;
done;)
fi
if [ "$SECONDARY_INITS" != "" ]; then
echo $SECONDARY_INITS | sed -e 's/\s\+/\n/g' | (while read line; do
cp -f $line .;
done;)
if [ "$TERTIARY_INITS" != "" ]; then
echo $TERTIARY_INITS | sed -e 's/\s\+/\n/g' | (while read line; do
cp -f $line .;
done;)
if [ "$QUARTENARY_INITS" != "" ]; then
echo $QUARTENARY_INITS | sed -e 's/\s\+/\n/g' | (while read line; do
cp -f $line .;
done;)
fi
fi
fi
# Create ramdisk image
find . | cpio -o -H newc | gzip > /tmp/ramdisk.img;
cd ..;
$TOOLS_LOC/mkbootimg --cmdline 'console=null androidboot.hardware=$ABOOT_HW' --base 0x$BASE --ramdiskaddr 0x${ADDR} --kernel arch/arm/boot/zImage --ramdisk /tmp/ramdisk.img -o zip/boot.img
cd zip;
zip -r clean-kernel-$DEVICE$APPEND.zip *
mv clean-kernel-$DEVICE$APPEND.zip $CLEAN_DIR/;
#############################################################
echo "";
echo " Making kernel directory proper now.";
cd $KERNELSRC && make mrproper && cd $DIRSRC;
echo "";