-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbuild.sh
executable file
·131 lines (109 loc) · 3.2 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# Android kernel for Google ChromeOS devices build script by jcadduono
################### BEFORE STARTING ################
#
# download a working toolchain and extract it somewhere and configure this
# file to point to the toolchain's root directory.
#
# once you've set up the config section how you like it, you can simply run
# ./build.sh [VARIANT]
#
###################### CONFIG ######################
# root directory of android_kernel_google_chromeos git repo (default is this script's location)
RDIR=$(pwd)
[ "$VER" ] ||
# version number
VER=$(cat "$RDIR/VERSION")
# directory containing cross-compile arm64 toolchain
TOOLCHAIN=$HOME/build/toolchain/gcc-linaro-5.3.1-2016.05-x86_64_aarch64-linux-gnu
CPU_THREADS=$(grep -c "processor" /proc/cpuinfo)
# amount of cpu threads to use in kernel make process
THREADS=$((CPU_THREADS + 1))
############## SCARY NO-TOUCHY STUFF ###############
ABORT() {
[ "$1" ] && echo "Error: $*"
exit 1
}
cd "$RDIR" || ABORT "Failed to enter $RDIR!"
CONTINUE=false
export ARCH=arm64
export CROSS_COMPILE=$TOOLCHAIN/bin/aarch64-linux-gnu-
export WIFIVERSION=
[ -x "${CROSS_COMPILE}gcc" ] ||
ABORT "Unable to find gcc cross-compiler at location: ${CROSS_COMPILE}gcc"
while [ $# != 0 ]; do
if [ "$1" = "--continue" ] || [ "$1" = "-c" ]; then
CONTINUE=true
elif [ ! "$DEVICE" ]; then
DEVICE=$1
elif [ ! "$TARGET" ]; then
TARGET=$1
else
echo "Too many arguments!"
echo "Usage: ./build.sh [--continue] [device] [target defconfig]"
ABORT
fi
shift
done
[ "$TARGET" ] || TARGET=google
[ "$DEVICE" ] || DEVICE=dragon
DEFCONFIG=${TARGET}_${DEVICE}_defconfig
[ -f "arch/$ARCH/configs/${DEFCONFIG}" ] ||
ABORT "Config $DEFCONFIG not found in $ARCH configs!"
export LOCALVERSION=$TARGET-$DEVICE-$VER
CLEAN_BUILD() {
echo "Cleaning build..."
rm -rf build
}
SETUP_BUILD() {
echo "Creating kernel config for $LOCALVERSION..."
mkdir -p build
make -C "$RDIR" O=build "$DEFCONFIG" \
|| ABORT "Failed to set up build"
}
BUILD_KERNEL() {
echo "Starting build for $LOCALVERSION..."
while ! make -C "$RDIR" O=build -j"$THREADS"; do
read -rp "Build failed. Retry? " do_retry
case $do_retry in
Y|y) continue ;;
*) return 1 ;;
esac
done
}
INSTALL_MODULES() {
grep -q 'CONFIG_MODULES=y' build/.config || return 0
echo "Installing kernel modules to build/lib/modules..."
while ! make -C "$RDIR" O=build \
INSTALL_MOD_PATH="." \
INSTALL_MOD_STRIP=1 \
modules_install
do
read -rp "Build failed. Retry? " do_retry
case $do_retry in
Y|y) continue ;;
*) return 1 ;;
esac
done
rm build/lib/modules/*/build build/lib/modules/*/source
}
BUILD_CHROMEOS_KERNEL() {
echo "Building ChromeOS kernel image..."
KDIR="$RDIR/build/arch/$ARCH/boot"
chromeos/scripts/generate-its-script.sh -c lz4 -d "" \
"$KDIR/Image" "$KDIR/dts/tegra/"*.dtb > "$KDIR/Image.its" \
|| ABORT "Failed to generate ChromeOS Image.its"
build/scripts/dtc/dtc -I dts -O dtb -p 1024 \
< "$KDIR/Image.its" > "$KDIR/Image.fit" \
|| ABORT "Failed to build ChromeOS Image.fit"
echo "Final image: $KDIR/Image.fit"
}
if ! $CONTINUE; then
CLEAN_BUILD
SETUP_BUILD ||
ABORT "Failed to set up build!"
fi
BUILD_KERNEL &&
INSTALL_MODULES &&
BUILD_CHROMEOS_KERNEL &&
echo "Finished building $LOCALVERSION!"