-
Notifications
You must be signed in to change notification settings - Fork 9
/
build-kernel.sh
executable file
·106 lines (79 loc) · 2.75 KB
/
build-kernel.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
#! /bin/bash -e
export TZ=UTC
# Identity to fill the "Maintainer:" field in dpkg control file
export DEBEMAIL="voldemort@ministry_of_magic"
export DEBFULLNAME="Who Must Not Be Named"
export KDEB_CHANGELOG_DIST="Debian"
if [ -e config ]; then
CONFIG="$PWD/config"
else
CONFIG=
fi
SCRIPTDIR="$PWD"
OUTDIR="$PWD/out"
mkdir -p "$OUTDIR"
cp fingerprint.sh "$OUTDIR"/
. ver.sh
. arch.sh
. concur.sh
. fingerprint.sh
. fixed-dir.sh
TOOLS_PREFIX="$FIXED_DIRECTORY/tools"
LINUX_SRC="https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-${LINUX_VER}.tar.xz"
LINUX_SIGN="https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-${LINUX_VER}.tar.sign"
LINUX_SIGN_FILE="linux-${LINUX_VER}.tar.sign"
LINUX_TBL_CMP="linux-${LINUX_VER}.tar.xz"
LINUX_TBL_DECMP="unxz"
LINUX_TBL="linux-${LINUX_VER}.tar"
LINUX_DIR="linux-${LINUX_VER}"
GRSEC_FILE="grsecurity-${GRSEC_VER}.patch"
if [ ! -e "$LINUX_TBL" ]; then
wget "$LINUX_SRC" -O "$LINUX_TBL_CMP"
wget "$LINUX_SIGN" -O "$LINUX_SIGN_FILE"
"$LINUX_TBL_DECMP" "$LINUX_TBL_CMP"
if [ "$VERIFY_GPG" != "0"]; then
gpg --verify "$LINUX_SIGN_FILE" "$LINUX_TBL"
else
true
fi
fi
if [ ! -e "$GRSEC_FILE" ]; then
cp "$SCRIPTDIR/$GRSEC_FILE" .
fi
# Ensure the build is clean
rm -rf "$LINUX_DIR"
rm -f *.deb
tar xvf "$LINUX_TBL"
cd "$LINUX_DIR"
patch -Np1 -i ../"$GRSEC_FILE"
cp "$SCRIPTDIR"/fingerprint.sh .
# Some variables for deterministic kernel build
export KBUILD_BUILD_TIMESTAMP="${KERNEL_TIMESTAMP}"
export DEB_BUILD_TIMESTAMP="$(date --date="${KERNEL_TIMESTAMP}" +%s)"
export SOURCE_DATE_EPOCH="$DEB_BUILD_TIMESTAMP"
export KBUILD_BUILD_USER=grsec
export KBUILD_BUILD_HOST=grsec
export KCONFIG_NOTIMESTAMP=1
export XZ_OPT="--check=crc64"
export ROOT_DEV=FLOPPY
# trustchain
export SECUREBOOT
export DB_KEY
export DB_CERT
chmod 755 scripts/gcc-plugin.sh # Without this command, the script cannot be executed under Debian.
# Here's some hacks for deterministic build
# The first line makes the randstruct seed deterministic (with the value in fingerprint)
# The second one uses the fingerprint timestamp as the debian changelog timestamp
sed "s/@SEED@/$GRSEC_RANDSTRUCT_SEED/g" < "$SCRIPTDIR"/hacks/gen-random-seed.sh.in > scripts/gcc-plugins/gen-random-seed.sh
sed "s/@TIMESTAMP@/$KERNEL_TIMESTAMP/g" < "$SCRIPTDIR"/hacks/builddeb.in > scripts/package/builddeb
chmod 755 scripts/package/builddeb
if [ "$CONFIG" ]; then
cp $CONFIG .config
else
make ARCH="$LINUX_ARCH" CROSS_COMPILE="$TOOLS_PREFIX"/bin/"$TOOLS_TRIPLET"- defconfig
fi
make ARCH="$LINUX_ARCH" CROSS_COMPILE="$TOOLS_PREFIX"/bin/"$TOOLS_TRIPLET"- "$KERNEL_CONCUR" bindeb-pkg
# Copy anything into $OUTDIR/
cp ../*.deb "$OUTDIR"/
cp arch/x86/boot/bzImage vmlinux "$OUTDIR"/
make ARCH="$LINUX_ARCH" CROSS_COMPILE="$TOOLS_PREFIX"/bin/"$TOOLS_TRIPLET"- INSTALL_MOD_PATH="$OUTDIR" modules_install