-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·116 lines (104 loc) · 3.78 KB
/
build.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
#!/bin/sh
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
end=$(tput sgr0)
VERSION="$(git describe --tags)"
build_dir="../../../out/target/product/d10f/obj/BOOTLOADER_EMMC_OBJ"
print_usage() {
echo "Usage: $0 [-h|-?|--help] [-b|--boot] [-f|--flash] [-c|--clean] [-z|--zip]"
echo "--help: show this text"
echo "--boot: create bootable image and boot it to device using fastboot boot without flashing"
echo "--flash: flash built binary to device using fastboot flash aboot and reboot device to fastboot"
echo "--clean: run make clean before building"
echo "--zip: build flashable Recovery zip after building"
echo "--install: build flashable Recovery zip and install it via TWRP"
}
# Transform long options to short ones
for arg in "$@"; do
shift
case "$arg" in
"--help") set -- "$@" "-h" ;;
"--boot") set -- "$@" "-b" ;;
"--clean") set -- "$@" "-c" ;;
"--flash") set -- "$@" "-f" ;;
"--zip") set -- "$@" "-z" ;;
"--install") set -- "$@" "-i" ;;
*) set -- "$@" "$arg"
esac
done
OPTIND=1
while getopts "hfcbzi" opt
do
case "$opt" in
"b") boot=true ;;
"c") clean=true ;;
"f") flash=true ;;
"z") zip=true ;;
"i") zip=true; install=true ;;
"h") print_usage; exit 0 ;;
*) print_usage >&2; exit 1 ;;
esac
done
shift "$((OPTIND - 1))" # remove options from positional parameters
if [ "$clean" = "true" ]; then
rm -rf "$build_dir"
fi
mkdir -p "$build_dir"
touch dev/fbcon/fbcon.c # Force rebuilding it to make sure that version string is updated
if ! make DEBUG=2 PROJECT=msm8226 BOOTLOADER_OUT="$build_dir" EMMC_BOOT=1 VERSION="$VERSION" -j"$(nproc)"; then
echo ""
echo "${red}Build FAILED!${end}"
exit 1
fi
echo ""
echo "${green}Successfully built${end}"
if [ "$zip" = "true" ]; then
path=$(readlink -f $build_dir/../../)
zipname="$path/IBL_$VERSION.zip"
rm -rf /tmp/zip_template/ "$zipname"
cp -r zip_template /tmp/
cp "$build_dir/../../emmc_appsboot.mbn" "/tmp/zip_template/firmware-update/IBL_$VERSION.mbn"
cat > /tmp/zip_template/META-INF/com/google/android/updater-script <<EOF
# ---- radio update tasks ----
ui_print("Installing IBL $VERSION...");
ifelse(msm.boot_update("main"), (
package_extract_file("firmware-update/tz.mbn", "/dev/block/platform/msm_sdcc.1/by-name/tz");
package_extract_file("firmware-update/sbl1.mbn", "/dev/block/platform/msm_sdcc.1/by-name/sbl1");
package_extract_file("firmware-update/rpm.mbn", "/dev/block/platform/msm_sdcc.1/by-name/rpm");
package_extract_file("firmware-update/IBL_$VERSION.mbn", "/dev/block/platform/msm_sdcc.1/by-name/aboot");
), "");
msm.boot_update("backup");
msm.boot_update("finalize");
ui_print("Done...");
EOF
(
cd "/tmp/zip_template/" || exit 1
zip "$zipname-unsigned" ./* -r
) || exit 1
java -Xmx2048m -jar zip_sign/signapk.jar -w zip_sign/testkey.x509.pem zip_sign/testkey.pk8 "$zipname-unsigned" "$zipname"
echo "${yellow}$zipname ${green}built${end}"
rm -rf "/tmp/zip_template/" "$zipname-unsigned"
fi
if [ "$install" = "true" ]; then
if ! adb devices|grep recovery; then
adb reboot recovery
fi
until adb devices|grep recovery; do sleep 1; done
until adb shell mount|grep /external_sd; do sleep 1; done
adb push "$zipname" "/external_sd/"
adb shell twrp install "/external_sd/$(basename "$zipname")"
adb reboot bootloader
exit 0
fi
if [ "$boot" = "true" ]; then
rm -f "$build_dir/../../IBL.img" # Throw error on boot attempt if mkbootimg fails
mkbootimg --kernel "$build_dir/../../emmc_appsboot.raw" --dt "dt.img" --ramdisk /dev/null -o "$build_dir/../../IBL.img"
fastboot boot "$build_dir/../../IBL.img"
exit 0
fi
if [ "$flash" = "true" ]; then
fastboot flash aboot "$build_dir"/../../emmc_appsboot.mbn
fastboot reboot-bootloader
exit 0
fi