-
Notifications
You must be signed in to change notification settings - Fork 0
/
what
executable file
·129 lines (121 loc) · 3.85 KB
/
what
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
#!/bin/bash
# Commonly used and long path names/strings
# Edit this as per your local environment/device!
cmdline="androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x37 ehci-hcd.park=3 dwc3.maximum_speed=high dwc3_msm.prop_chg_detect=Y"
dtbflags="-2 -s 2048"
kernelsauce=/home/someone/adev/nougat/kernel
zimagepath=$kernelsauce/arch/arm/boot/zImage-dtb
ramdisk="ramdisk/ramdisk.cpio.gz"
# Reset after a previous run of the script
mkdir out >/dev/null 2>/dev/null
mod=0
signage=0
enforcing=0
permissive=0
# Help message to be shown on -h
halp () {
echo " options:"
echo " -h -- display this help message"
echo " -d -- compile a dt.img from the source kernel dirctory."
echo " Deprecated in favour of zImage-dtb."
echo " -p, -e -- create permissive or enforcing image, respectively."
echo " Deprecated in favour of highly-modular zips. Requires"
echo " '-d' to have been run previously."
echo " -z -- create flashable zip file from the zImage-dtb. The"
echo " created zips allow the user to choose whether they"
echo " want a permissive of enforcing image at the time of"
echo " install, and use the native ROM's ramdisk."
echo " -m -- copy all kernel module .ko files to flash with the zip"
echo " file. Requires the '-z' flag. Requires a full kernel"
echo " source to find the modules in."
echo " -a -- zipalign and sign the created zip file. Requires the"
echo " '-z' flag."
}
# Create a dtb.img from the kernel source path.
dtb () {
echo " Looking for dtb files in $kernelsauce " >&2
./tools/dtbToolCM $dtbflags -o out/dt.img -p $kernelsauce/scripts/dtc/ $kernelsauce/arch/arm/boot/
# Error out if the image is not created.
if [ -f out/dt.img ]; then
echo " DTB successfully generated"
else
exit 1
fi
}
# Setup cmdline as per user choice
cmdlinesetup () {
[ $permissive = 1 ] && cmdlineexec=$cmdline && bootimgout=perm
[ $enforcing = 1 ] && cmdlineexec=$cmdline\ androidboot.selinux=permissive && bootimgout=enf
zimg
}
# Check to see if zImage path is correct
zimg () {
if [ ! -f $zimagepath ]; then
echo "!!! zImage not found, have you set the correct path?"
exit 1
fi
bootimg
}
# Functions that run the mkbootimg tool. Use $source_path defined in bootimg.
# Once the command is sent, check if the images are in place. If not, error out.
bootimg () {
./tools/mkbootimg --base 0x00000000 --kernel $zimagepath --ramdisk_offset 0x02000000 --tags_offset 0x01E00000 --pagesize 2048 --cmdline "$cmdlineexec" --ramdisk $ramdisk -o out/$bootimgout-$(date '+%Y%m%d').img
echo " Boot image created in $(readlink -e out/)"
}
# Zip the boot image into a flashable zip and sign it
zips () {
# Delete temporary "~" files; reduce clutter, make zip files cleaner
find . -name "*~" -type f -delete
cp $zimagepath kerneller/extract/res/
# Include and update the modules if needed
[ $mod=1 ] && find kerneller/extract/modules/ -name '*.ko' -exec rm -rf {} \; && find $kernelsauce -name '*.ko' -exec cp {} kerneller/extract/modules/ \;
cd kerneller
./unsigned_zip
[ $signage=1 ] && ./signed_zip
for (( num=1; num<99; num++ ))
do
if [ ! -f ../out/r-$(date '+%Y%m%d')-$num.zip ]; then
break
fi
done
mv r.zip ../out/r-$(date '+%Y%m%d')-$num.zip
cd ..
echo " Zip file created in $(readlink -e out/)"
}
# Check for flags passed
while getopts "hdepmaz" opt; do
case $opt in
a)
signage=1
;;
d)
dtb
;;
e)
echo " Enforcing image selected"
enforcing=1
cmdlinesetup
;;
h)
# Show a help message and quit
halp
exit 0
;;
m)
mod=1
;;
p)
echo " Permissive image selected"
permissive=1
cmdlinesetup
;;
z)
zips
;;
*)
# Show a help message and quit
halp
exit 0
;;
esac
done