-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_kernel.sh
More file actions
181 lines (143 loc) · 4.84 KB
/
Copy pathbuild_kernel.sh
File metadata and controls
181 lines (143 loc) · 4.84 KB
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
#!bin/bash
clear
LANG=C
###### PREREQUISITES #######
# What you need installed to compile
# gcc, gpp, cpp, c++, g++, lzma, lzop, ia32-libs flex
# If on 64bit Linux, install gcc multilib
### info on how to start this autobuild ###
# Project structure
# --project_root/ #### can have any name
# -----ramdisk_source/ ## defined by RAMDISK_TMP var
# -----ramdisk_tmp/ ## defined by RAMDISK_DIR var
# -----kernel_source/ #### can have any name
# -----RELEASE/
## TOOLCHAIN INFO ##
# Toolchain is already into kernel dir. You just need to have
# correct folder structure and run this script. Everything will be auto-built
## FLASHABLE ZIP ##
# Flashable zip will be located in project_root/RELEASE directory
# and will have name Kernel-slte.zip
# location defines
KERNELDIR=$(readlink -f .);
RAMDISK_TMP=ramdisk_tmp
RAMDISK_DIR=ramdisk_source
DEFCONFIG=exynos5422-k3g_defconfig
CLEANUP()
{
# begin by ensuring the required directory structure is complete, and empty
echo "Initialising................."
echo "Cleaning READY dir......."
rm -rf "$KERNELDIR"/READY/boot
rm -rf "$KERNELDIR"/READY/*.img
rm -rf "$KERNELDIR"/READY/*.zip
rm -rf "$KERNELDIR"/READY/*.sh
rm -f "$KERNELDIR"/.config
#### Cleanup bootimg_tools now #####
echo "Cleaning bootimg_tools from unneeded data..."
echo "Deleting kernel zImage named 'kernel' in bootimg_tools dir....."
rm -f "$KERNELDIR"/bootimg_tools/boot_g900h/kernel
echo "Deleting all files from ramdisk dir in bootimg_tools if it exists"
if [ ! -d "$KERNELDIR"/bootimg_tools/boot_g900h/ramdisk ]; then
mkdir -p "$KERNELDIR"/bootimg_tools/boot_g900h/ramdisk
chmod 777 "$KERNELDIR"/bootimg_tools/boot_g900h/ramdisk
else
rm -rf "$KERNELDIR"/bootimg_tools/boot_g900h/ramdisk/*
fi;
echo "Deleted all files from ramdisk dir in bootimg_tools";
echo "Clean all files from temporary and make ramdisk_tmp if it doesn´t exist"
if [ ! -d ../"$RAMDISK_TMP" ]; then
mkdir ../"$RAMDISK_TMP"
chown root:root ../"$RAMDISK_TMP"
chmod 777 ../"$RAMDISK_TMP"
else
rm -rf ../"$RAMDISK_TMP"/*
fi;
echo "Make RELEASE directory if it doesn't exist and clean it if it exists"
if [ ! -d ../RELEASE ]; then
mkdir ../RELEASE
else
rm -rf ../RELEASE/*
fi;
# force regeneration of .dtb and zImage files for every compile
rm -f arch/arm/boot/*.cmd
rm -f arch/arm/boot/zImage
rm -f arch/arm/boot/Image
}
BUILD_NOW()
{
if [ ! -f "$KERNELDIR"/.config ]; then
echo "Copying arch/arm/configs/$DEFCONFIG to .config"
cp arch/arm/configs/"$DEFCONFIG" .config
else
rm -f "$KERNELDIR"/.config
echo "Copying arch/arm/configs/$DEFCONFIG to .config"
cp arch/arm/configs/"$DEFCONFIG" .config
fi;
# we don't build modules, so no need to delete them
########
### CPU thread usage
# Idea by savoca
NR_CPUS=$(grep -c ^processor /proc/cpuinfo)
if [ "$NR_CPUS" -le "2" ]; then
NR_CPUS=4;
echo "Building kernel with 4 CPU threads";
else
echo "Building kernel with $NR_CPUS CPU threads";
fi;
# build zImage
time make ARCH=arm CROSS_COMPILE=/home/yash92duster/Desktop/yash/toolchain/arm-eabi-4.8/bin/arm-eabi- zImage-dtb -j ${NR_CPUS}
stat "$KERNELDIR"/arch/arm/boot/zImage || exit 1;
# copy all ramdisk files to ramdisk temp dir.
cp -a ../"$RAMDISK_DIR"/* ../"$RAMDISK_TMP"/
# remove empty directory placeholders from tmp-initramfs
for i in $(find ../"$RAMDISK_TMP"/ -name EMPTY_DIRECTORY); do
rm -f "$i";
done;
if [ -e "$KERNELDIR"/arch/arm/boot/zImage ]; then
cp arch/arm/boot/zImage bootimg_tools/boot_g900h/kernel
cp .config READY/view_only_config
# copy all ramdisk files to ramdisk temp dir.
cp -a ../"$RAMDISK_TMP"/* bootimg_tools/boot_g900h/ramdisk/
### Now I have ramdisk and kernel (zImage) and dtb dt.img in bootimg_tools
### Also I have img_info which is kept every recompile for parsing mkbootimg parameters
# Build boot.img and move it to READY dir
echo "Move boot.img to READY/boot.img"
cd bootimg_tools
./mkboot boot_g900h ../READY/boot.img
# Make flashable zip
cd ../READY
zip -r Kernel-g900h.zip * >/dev/null
mv Kernel-g900h.zip ../../RELEASE/
# Add proper timestamps to default.prop in ramdisk
DATE=$(date)
DATEUTC=$(date +%s)
sed -i "s/ro.bootimage.build.date=.*/ro.bootimage.build.date=${DATE}/g" ../../"$RAMDISK_DIR"/default.prop
sed -i "s/ro.bootimage.build.date.utc=.*/ro.bootimage.build.date.utc=${DATEUTC}/g" ../../"$RAMDISK_DIR"/default.prop
echo "Build done"
else
# with red-color
echo -e "\e[1;31mKernel STUCK in BUILD! no zImage exist\e[m"
fi;
}
CLEAN_KERNEL()
{
echo "Mrproper and clean running";
make ARCH=arm mrproper;
make clean;
# clean remaining .o files if needed
shopt -s globstar; # enable globstar in bash
rm **/*.o;
# clean ccache
read -t 10 -p "clean ccache, 10sec timeout (y/n)?";
if [ "$REPLY" == "y" ]; then
ccache -C;
fi;
}
echo "Initializing auto-build script......."
sleep 1;
CLEAN_KERNEL;
CLEANUP;
echo "Build now starting"
BUILD_NOW;
exit;