forked from sgt7/android_kernel_samsung_p1
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_boot.img.sh
166 lines (143 loc) · 3.96 KB
/
build_boot.img.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
#!/bin/bash
#
# Script to build Galaxy Tab Kernel
# 2012 Chirayu Desai
# Common defines
txtrst='\e[0m' # Color off
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
echo -e "${txtblu}##########################################"
echo -e "${txtblu}# #"
echo -e "${txtblu}# GALAXYTAB KERNEL BUILDSCRIPT #"
echo -e "${txtblu}# #"
echo -e "${txtblu}##########################################"
echo -e "\r\n ${txtrst}"
echo ""
# Starting Timer
START=$(date +%s)
DEVICE="$1"
THREADS=`cat /proc/cpuinfo | grep processor | wc -l`
case "$DEVICE" in
clean)
make clean
exit
;;
p1|P1)
DEFCONFIG=p1_cm9_defconfig
;;
p1c|P1C)
DEFCONFIG=p1c_cm9_defconfig
;;
p1l|P1L)
DEFCONFIG=p1l_cm9_defconfig
;;
p1n|P1N)
DEFCONFIG=p1n_cm9_defconfig
;;
*)
echo -e "${txtred}Usage: $0 device"
echo -e "Example: ./build.sh p1"
echo -e "Supported Devices: p1 p1c p1l p1n ${txtrst}"
;;
esac
# Some defines
KERNEL_DIR=`pwd`
KERNEL_PATH="./arch/arm/boot/zImage"
KERNEL_INITRD_DIR="../initramfs"
KERNEL_INITRD_GIT="https://github.com/sgt7/p1000-initramfs-cm9.git"
INITSOURCE=`grep CONFIG_INITRAMFS_SOURCE arch/arm/configs/$DEFCONFIG `
# Check if initramfs is present, if not, then clone it
if [ ! -d $KERNEL_INITRD_DIR ]; then
cd ..
git clone $KERNEL_INITRD_GIT initramfs
cd $KERNEL_DIR
fi
# .git is huge!
echo ""
echo -e "${txtgrn} MOVING .git TO SAFE LOCATION "
echo -e "\r\n ${txtrst}"
mv $KERNEL_INITRD_DIR/.git ~/DONOTLOOKATME
echo -e "${txtblu} Checking if your initramfs path is correct...."
echo -e "${txtblu}The initramfs path was: ""${txtred}$INITSOURCE${txtrst}"
sed -i "s|CONFIG_INITRAMFS_SOURCE=\".*\"|CONFIG_INITRAMFS_SOURCE=\"usr/galaxytab_initramfs.list\"|" arch/arm/configs/$DEFCONFIG
INITSOURCE=`grep CONFIG_INITRAMFS_SOURCE arch/arm/configs/$DEFCONFIG `
echo -e "${txtblu}Now changed to: ""${txtgrn}$INITSOURCE${txtrst}"
if [ ! "$1" = "" ] ; then
echo ""
echo -e "${txtgrn} MAKING DEFCONFIG "
echo -e "\r\n ${txtrst}"
make -j$THREADS ARCH=arm $DEFCONFIG
fi
# Don't forget to build the MODULES
if [ ! "$1" = "" ] ; then
echo ""
echo -e "${txtgrn} BUILDING MODULES AND COPYING THEM TO RAMDISK "
echo -e "\r\n ${txtrst}"
make -j$THREADS modules
echo ""
# Copy the modules into the ramdisk
find . -iname *.ko | xargs cp -frvt ../initramfs/lib/modules/
/opt/toolchains/arm-2009q3/bin/arm-none-eabi-strip --strip-debug ../initramfs/lib/modules/*
sleep 2
fi
# The real build starts now
if [ ! "$1" = "" ] ; then
echo ""
echo -e "${txtgrn} BUILDING KERNEL "
echo -e "\r\n ${txtrst}"
make -j$THREADS
fi
# Make it into a boot.img
# ty nubecoder for this :)
# Function
function PACKAGE_BOOTIMG()
{
if [ "$1" = "" ] || [ "$2" = "" ] ; then
ERROR_MSG="Error: PACKAGE_BOOTIMG - Missing args!"
return 2
fi
if [ ! -f "$1" ] ; then
ERROR_MSG="Error: PACKAGE_BOOTIMG - zImage does not exist!"
return 1
else
echo -e "${txtblu} Creating ramdisk.img"
./tools/mkbootfs $KERNEL_INITRD_DIR | ./tools/minigzip > ramdisk.img
if [ -f boot.img ] ; then
echo "removing old boot.img"
rm -f boot.img
fi
echo -e "${txtblu} Creating boot.img"
./tools/mkshbootimg.py boot.img ./arch/arm/boot/zImage ramdisk.img
echo -e "${txtblu} Cleaning up temp files:"
rm -f ramdisk.img
echo -e "${txtblu} Done!"
return 0
fi
}
# Main
if [ ! "$1" = "" ] ; then
echo ""
echo -e "${txtgrn} MAKING KERNEL INTO A BOOT.IMG FILE "
echo -e "\r\n ${txtrst}"
PACKAGE_BOOTIMG "$KERNEL_PATH" "$KERNEL_INITRD_DIR"
if [ $? != 0 ] ; then
echo -e "${txtred} $ERROR_MSG"
else
echo -e "${txtblu} Boot.img created successfully...${txtrst}"
fi
fi
# move it back just in case
echo ""
echo -e "${txtgrn} MOVING .git BACK "
echo -e "\r\n ${txtrst}"
mv ~/DONOTLOOKATME $KERNEL_INITRD_DIR/.git
# The end!
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