Skip to content

Commit c6ed978

Browse files
committed
Successfully build x86 and arm64 kernel headers for new linux versions
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 8cbaedc commit c6ed978

3 files changed

Lines changed: 24 additions & 55 deletions

File tree

tools/docker/Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ LINUX_HEADER_BUILD_DIR := $(BUILD_DIR)/linux_headers
7474
LINUX_HEADER_ASSETS_BUILD_DIR := $(LINUX_HEADER_BUILD_DIR)/assets
7575
LINUX_KERNEL_VERSIONS := 4.18.20 \
7676
5.10.252 \
77-
5.14.21 \
78-
6.1.167 \
79-
6.6.132 \
80-
6.12.80 \
81-
6.18.21 \
82-
6.19.10
77+
5.14.21 \
78+
6.1.167 \
79+
6.6.132 \
80+
6.12.80 \
81+
6.18.21 \
82+
6.19.10
8383

8484

8585
LINUX_HEADER_TEMPLATE := linux-headers-%.tar.gz
@@ -114,7 +114,8 @@ elasticsearch_image_tag := "gcr.io/pixie-oss/pixie-dev-public/elasticsearch:$(EL
114114

115115
## Linux kernel for qemu/BPF tests.
116116
KERNEL_BUILD_DIR := $(BUILD_DIR)/kernel_build
117-
KERNEL_BUILD_VERSIONS := 5.10.252 \
117+
KERNEL_BUILD_VERSIONS := 4.14.309 \
118+
5.10.252 \
118119
5.14.21 \
119120
6.1.167 \
120121
6.6.132 \

tools/docker/linux_headers_image/Dockerfile

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,16 @@ RUN apt-get update
2727
RUN apt-get upgrade -y -q
2828
RUN apt-get install -y -q build-essential \
2929
bc \
30-
libdw-dev \
3130
libelf-dev \
3231
libssl-dev \
3332
flex \
3433
bison \
35-
kmod \
36-
cpio \
3734
rsync \
3835
wget \
3936
binutils-aarch64-linux-gnu \
4037
gcc-aarch64-linux-gnu \
41-
dwarves \
42-
debhelper \
4338
python3
4439

45-
# opensslconf.h lives at the multiarch path (e.g. /usr/include/x86_64-linux-gnu/openssl/).
46-
# During cross-compilation, dpkg-buildpackage alters include paths so host tools
47-
# (like scripts/sign-file) can no longer find it. Symlink it to the standard path.
48-
RUN if [ -f /usr/include/x86_64-linux-gnu/openssl/opensslconf.h ] && \
49-
[ ! -f /usr/include/openssl/opensslconf.h ]; then \
50-
ln -s /usr/include/x86_64-linux-gnu/openssl/opensslconf.h /usr/include/openssl/opensslconf.h; \
51-
fi
52-
5340
WORKDIR /configs
5441
ADD x86_64_config /configs/x86_64
5542
ADD arm64_config /configs/arm64

tools/docker/linux_headers_image/build_linux_headers.sh

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,56 +49,37 @@ mkdir -p "${WORKSPACE}"/src
4949
pushd "${WORKSPACE}"/src || exit
5050

5151
KERN_MAJ=$(echo "${KERN_VERSION}" | cut -d'.' -f1);
52-
KERN_MIN=$(echo "${KERN_VERSION}" | cut -d'.' -f2);
5352
wget -nv http://mirrors.edge.kernel.org/pub/linux/kernel/v"${KERN_MAJ}".x/linux-"${KERN_VERSION}".tar.gz
5453

5554
tar zxf linux-"${KERN_VERSION}".tar.gz
5655

5756
pushd linux-"${KERN_VERSION}" || exit
5857

59-
cp /configs/"${ARCH}" .config
60-
make ARCH="${ARCH}" olddefconfig
61-
make ARCH="${ARCH}" clean
62-
6358
LOCALVERSION="-pl"
6459

65-
DEB_ARCH="${ARCH//x86_64/amd64}"
66-
# binary builds are required for non git trees after linux v6.3 (inclusive).
67-
# The .deb file suffix is also different.
68-
TARGET='bindeb-pkg'
69-
DEB_SUFFIX="-1_${DEB_ARCH}.deb"
70-
if [ "${KERN_MAJ}" -lt 6 ] || { [ "${KERN_MAJ}" -le 6 ] && [ "${KERN_MIN}" -lt 3 ]; }; then
71-
TARGET='deb-pkg'
72-
DEB_SUFFIX="${LOCALVERSION}-1_${DEB_ARCH}.deb"
73-
fi
74-
echo "Building ${TARGET} for ${KERN_VERSION}${LOCALVERSION} (${ARCH})"
60+
cp /configs/"${ARCH}" .config
61+
make ARCH="${ARCH}" olddefconfig
7562

76-
EXTRA_MAKE_ARGS=""
77-
if [ "${ARCH}" != "$(uname -m)" ]; then
78-
# Skip dpkg dependency checks when cross-compiling, since host packages
79-
# (e.g. libssl-dev) won't satisfy target arch requirements.
80-
EXTRA_MAKE_ARGS="DPKG_FLAGS=-d"
81-
fi
82-
make ARCH="${ARCH}" -j "$(nproc)" "${TARGET}" LOCALVERSION="${LOCALVERSION}" ${EXTRA_MAKE_ARGS}
63+
# Only generate headers — no kernel or module compilation needed.
64+
# 'make prepare' generates include/generated/ and arch/*/include/generated/
65+
# which are the only outputs we package.
66+
echo "Generating headers for ${KERN_VERSION}${LOCALVERSION} (${ARCH})"
67+
make ARCH="${ARCH}" prepare LOCALVERSION="${LOCALVERSION}"
8368

8469
popd || exit
8570
popd || exit
8671

87-
# Extract headers into a tarball
88-
dpkg -x src/linux-headers-"${KERN_VERSION}${LOCALVERSION}_${KERN_VERSION}${DEB_SUFFIX}" .
72+
# Package headers into the same directory structure the old deb-pkg approach produced
73+
# (usr/src/linux-headers-<version><localversion>/{include,arch}).
74+
KERNEL_ARCH="${ARCH//x86_64/x86}"
75+
HEADERS_DIR="usr/src/linux-headers-${KERN_VERSION}${LOCALVERSION}"
76+
77+
mkdir -p "${HEADERS_DIR}/arch"
78+
cp -a "src/linux-${KERN_VERSION}/include" "${HEADERS_DIR}/"
79+
cp -a "src/linux-${KERN_VERSION}/arch/${KERNEL_ARCH}" "${HEADERS_DIR}/arch/"
8980

9081
# Remove broken symlinks
91-
find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}" -xtype l -exec rm {} +
92-
93-
# Remove uneeded files to reduce size
94-
# Keep only:
95-
# - usr/src/linux-headers-x.x.x-pl/include
96-
# - usr/src/linux-headers-x.x.x-pl/arch/${ARCH}
97-
# This reduces the size by a little over 2x.
98-
rm -rf usr/share
99-
find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}" -maxdepth 1 -mindepth 1 ! -name include ! -name arch -type d \
100-
-exec rm -rf {} +
101-
find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}"/arch -maxdepth 1 -mindepth 1 ! -name "${ARCH//x86_64/x86}" -type d -exec rm -rf {} +
82+
find "${HEADERS_DIR}" -xtype l -exec rm {} +
10283

10384
tar zcf linux-headers-"${ARCH}"-"${KERN_VERSION}".tar.gz usr
10485

0 commit comments

Comments
 (0)