-
Notifications
You must be signed in to change notification settings - Fork 1
/
_in_container_build.sh
executable file
·118 lines (95 loc) · 4.26 KB
/
_in_container_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
#!/bin/bash
set -eu
# We want to build linux for each of our targets and versions using the config files. Linux is in /app/linux/[version]
# while our configs are at configs/[version]/[arch]. We need to set the ARCH and CROSS_COMPILE variables
# and put the binaries in /app/binaries
# Get options from build.sh
CONFIG_ONLY="$1"
VERSIONS="$2"
TARGETS="$3"
echo "Config only: $CONFIG_ONLY"
echo "Versions: $VERSIONS"
echo "Targets: $TARGETS"
# Set this to update defconfigs instead of building kernel
get_cc() {
local arch=$1
local abi=""
# Clear CFLAGS and KCFLAGS if they are set
unset CFLAGS
unset KCFLAGS
if [[ $arch == *"arm64"* ]]; then
abi=""
arch="aarch64"
elif [[ $arch == *"arm"* ]]; then
abi="eabi"
if [[ $arch == *"eb"* ]]; then
export CFLAGS="-mbig-endian"
export KCFLAGS="-mbig-endian"
fi
arch="arm"
fi
echo "/opt/cross/${arch}-linux-musl${abi}/bin/${arch}-linux-musl${abi}-"
}
for VERSION in $VERSIONS; do
for TARGET in $TARGETS; do
BUILD_TARGETS="vmlinux"
if [ $TARGET == "armel" ]; then
BUILD_TARGETS="vmlinux zImage"
elif [ $TARGET == "arm64" ]; then
BUILD_TARGETS="vmlinux Image.gz"
elif [ $TARGET == "x86_64" ]; then
BUILD_TARGETS="vmlinux bzImage"
fi
# Set short_arch based on TARGET
short_arch=$(echo $TARGET | sed -E 's/(.*)(e[lb]|eb64)$/\1/')
if [ "$short_arch" == "mips64" ]; then
short_arch="mips"
fi
echo "Building $BUILD_TARGETS for $TARGET"
if [ ! -f "/app/configs/${VERSION}/${TARGET}" ]; then
echo "No config for $TARGET"
exit 1
fi
mkdir -p "/tmp/build/${VERSION}/${TARGET}"
cpp -P -undef "/app/configs/${VERSION}/${TARGET}" -o "/tmp/build/${VERSION}/${TARGET}/.config"
# If updating configs, lint them with kernel first! This removes default options and duplicates.
if $CONFIG_ONLY; then
echo "Linting config for $TARGET to config_${VERSION}_${TARGET}.linted"
make -C /app/linux/$VERSION ARCH=${short_arch} CROSS_COMPILE=$(get_cc $TARGET) O=/tmp/build/${VERSION}/${TARGET}/ savedefconfig
cp "/tmp/build/${VERSION}/${TARGET}/defconfig" "/app/config_${VERSION}_${TARGET}.linted"
diff -u <(sort /tmp/build/${VERSION}/${TARGET}/.config) <(sort /tmp/build/${VERSION}/${TARGET}/defconfig | sed '/^[ #]/d')
else
echo "Building kernel for $TARGET"
make -C /app/linux/$VERSION ARCH=${short_arch} CROSS_COMPILE=$(get_cc $TARGET) O=/tmp/build/${VERSION}/${TARGET}/ olddefconfig
make -C /app/linux/$VERSION ARCH=${short_arch} CROSS_COMPILE=$(get_cc $TARGET) O=/tmp/build/${VERSION}/${TARGET}/ $BUILD_TARGETS -j$(nproc)
mkdir -p /kernels/$VERSION
# Copy out zImage (if present) and vmlinux (always)
if [ -f "/tmp/build/${VERSION}/${TARGET}/arch/${short_arch}/boot/zImage" ]; then
cp "/tmp/build/${VERSION}/${TARGET}/arch/${short_arch}/boot/zImage" /kernels/$VERSION/zImage.${TARGET}
fi
if [ -f "/tmp/build/${VERSION}/${TARGET}/arch/${short_arch}/boot/bzImage" ]; then
cp "/tmp/build/${VERSION}/${TARGET}/arch/${short_arch}/boot/bzImage" /kernels/$VERSION/bzImage.${TARGET}
fi
# Copy out Image.gz (if present)
if [ -f "/tmp/build/${VERSION}/${TARGET}/arch/${short_arch}/boot/Image.gz" ]; then
cp "/tmp/build/${VERSION}/${TARGET}/arch/${short_arch}/boot/Image.gz" /kernels/$VERSION/zImage.${TARGET}
fi
cp "/tmp/build/${VERSION}/${TARGET}/vmlinux" /kernels/$VERSION/vmlinux.${TARGET}
# Generate OSI profile
echo "[${TARGET}]" >> /kernels/$VERSION/osi.config
/panda/panda/plugins/osi_linux/utils/kernelinfo_gdb/run.sh \
/kernels/$VERSION/vmlinux.${TARGET} /tmp/panda_profile.${TARGET}
cat /tmp/panda_profile.${TARGET} >> /kernels/$VERSION/osi.config
dwarf2json linux --elf /kernels/$VERSION/vmlinux.${TARGET} | xz -c > /kernels/$VERSION/cosi.${TARGET}.json.xz
# strip vmlinux
$(get_cc $TARGET)strip /kernels/$VERSION/vmlinux.${TARGET}
fi
done
done
if ! $CONFIG_ONLY; then
echo "Built by linux_builder on $(date)" > /kernels/README.txt
tar cvfz /app/kernels-latest.tar.gz /kernels
chmod o+rw /app/kernels-latest.tar.gz
fi
# Ensure cache can be read/written by host
chmod -R o+rw /tmp/build