forked from RobertCNelson/stable-kernel
/
build_kernel.sh
executable file
·189 lines (164 loc) · 4.37 KB
/
build_kernel.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
#!/bin/bash -e
unset KERNEL_REL
unset KERNEL_PATCH
unset BUILD
unset CC
unset GIT_MODE
unset IS_LUCID
unset PACKAGE
unset APT
if [ ! $(which mkimage) ];then
echo "Missing uboot-mkimage"
PACKAGE="uboot-mkimage "
APT=1
fi
if [ ! $(which ccache) ];then
echo "Missing ccache"
PACKAGE+="ccache "
APT=1
fi
if [ ! $(which git) ];then
echo "Missing git"
PACKAGE+="git-core "
APT=1
fi
if [ ! $(file /usr/lib/libncurses.so | grep -v ERROR | awk '{print $1}') ];then
echo "Missing ncurses"
PACKAGE+="libncurses5-dev "
APT=1
fi
if [ "${APT}" ];then
echo "Installing Dependicies"
sudo aptitude install $PACKAGE
fi
ARCH=$(uname -m)
CCACHE=ccache
DIR=$PWD
CORES=1
if test "-$ARCH-" = "-x86_64-" || test "-$ARCH-" = "-i686-"
then
CORES=$(cat /proc/cpuinfo | grep processor | wc -l)
let CORES=$CORES+1
fi
mkdir -p ${DIR}/deploy/
DL_DIR=${DIR}/dl
mkdir -p ${DL_DIR}
function dl_kernel {
wget -c --directory-prefix=${DL_DIR} http://www.kernel.org/pub/linux/kernel/v2.6/linux-${KERNEL_REL}.tar.bz2
if [ "${KERNEL_PATCH}" ] ; then
wget -c --directory-prefix=${DL_DIR} http://www.kernel.org/pub/linux/kernel/v2.6/${DL_PATCH}.bz2
fi
}
function extract_kernel {
echo "Cleaning Up"
rm -rfd ${DIR}/KERNEL || true
echo "Extracting: ${KERNEL_REL} Kernel"
tar xjf ${DL_DIR}/linux-${KERNEL_REL}.tar.bz2
mv linux-${KERNEL_REL} KERNEL
cd ${DIR}/KERNEL
if [ "${GIT_MODE}" ] ; then
git init
git add .
git commit -a -m ''$KERNEL_REL' Kernel'
git tag -a $KERNEL_REL -m $KERNEL_REL
fi
if [ "${KERNEL_PATCH}" ] ; then
echo "Applying: ${KERNEL_PATCH} Patch"
bzcat ${DL_DIR}/patch-${KERNEL_PATCH}.bz2 | patch -s -p1
if [ "${GIT_MODE}" ] ; then
git add .
git commit -a -m ''$KERNEL_PATCH' Kernel'
git tag -a $KERNEL_PATCH -m $KERNEL_PATCH
fi
fi
cd ${DIR}/
}
function patch_kernel {
cd ${DIR}/KERNEL
export DIR GIT_MODE
/bin/bash -e ${DIR}/patch.sh
if [ "${KERNEL_PATCH}" ] ; then
sed -i 's/EXTRAVERSION = .'$STABLE_PATCH'/EXTRAVERSION = .'$STABLE_PATCH'-'$BUILD'/g' ${DIR}/KERNEL/Makefile
else
sed -i 's/EXTRAVERSION =/EXTRAVERSION = -'$BUILD'/g' ${DIR}/KERNEL/Makefile
fi
if [ "${GIT_MODE}" ] ; then
if [ "${KERNEL_PATCH}" ] ; then
git add .
git commit -a -m ''$KERNEL_PATCH'-'$BUILD' patchset'
git tag -a $KERNEL_PATCH-$BUILD -m $KERNEL_PATCH-$BUILD
else
git add .
git commit -a -m ''$KERNEL_REL'-'$BUILD' patchset'
git tag -a $KERNEL_REL-$BUILD -m $KERNEL_REL-$BUILD
fi
fi
#Test Patches:
cd ${DIR}/
}
function copy_defconfig {
cd ${DIR}/KERNEL/
make ARCH=arm CROSS_COMPILE=${CC} distclean
if [ "${IS_LUCID}" ] ; then
cp ${DIR}/patches/lucid-defconfig .config
else
cp ${DIR}/patches/defconfig .config
fi
cd ${DIR}/
}
function make_menuconfig {
cd ${DIR}/KERNEL/
make ARCH=arm CROSS_COMPILE=${CC} menuconfig
if [ "${IS_LUCID}" ] ; then
cp .config ${DIR}/patches/lucid-defconfig
else
cp .config ${DIR}/patches/defconfig
fi
cd ${DIR}/
}
function make_uImage {
cd ${DIR}/KERNEL/
echo "make -j${CORES} ARCH=arm CROSS_COMPILE=\"${CCACHE} ${CC}\" CONFIG_DEBUG_SECTION_MISMATCH=y uImage"
time make -j${CORES} ARCH=arm CROSS_COMPILE="${CCACHE} ${CC}" CONFIG_DEBUG_SECTION_MISMATCH=y uImage
#2.6.35+
# time make -j${CORES} ARCH=arm LOCALVERSION=-${BUILD} CROSS_COMPILE="${CCACHE} ${CC}" CONFIG_DEBUG_SECTION_MISMATCH=y uImage
KERNEL_UTS=$(cat ${DIR}/KERNEL/include/generated/utsrelease.h | awk '{print $3}' | sed 's/\"//g' )
cp arch/arm/boot/uImage ${DIR}/deploy/${KERNEL_UTS}.uImage
cd ${DIR}
}
function make_modules {
cd ${DIR}/KERNEL/
time make -j${CORES} ARCH=arm CROSS_COMPILE="${CCACHE} ${CC}" modules
#2.6.35+
# time make -j${CORES} ARCH=arm LOCALVERSION=-${BUILD} CROSS_COMPILE="${CCACHE} ${CC}" modules
rm -rfd ${DIR}/deploy/mod &> /dev/null || true
mkdir -p ${DIR}/deploy/mod
make ARCH=arm CROSS_COMPILE=${CC} modules_install INSTALL_MOD_PATH=${DIR}/deploy/mod
cd ${DIR}/deploy/mod
tar czf ../${KERNEL_UTS}-modules.tar.gz *
cd ${DIR}
}
if [ -e ${DIR}/system.sh ]; then
. system.sh
. version.sh
if [ "${IS_LUCID}" ] ; then
echo ""
echo "Building for Lucid (10.04) & Maverick (10.10)"
echo ""
else
echo ""
echo "Building for Debian Lenny/Squeeze/Sid & Ubuntu 9.04/9.10"
echo ""
fi
dl_kernel
extract_kernel
patch_kernel
copy_defconfig
make_menuconfig
make_uImage
make_modules
else
echo "Missing system.sh, please copy system.sh.sample to system.sh and edit as needed"
echo "cp system.sh.sample system.sh"
echo "gedit system.sh"
fi