2005-04-16 15:20:36 -07:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2009-04-22 16:09:25 -07:00
|
|
|
# builddeb 1.3
|
2005-04-16 15:20:36 -07:00
|
|
|
# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
|
|
|
|
#
|
|
|
|
# Simple script to generate a deb package for a Linux kernel. All the
|
2009-04-22 16:08:31 -07:00
|
|
|
# complexity of what to do with a kernel after it is installed or removed
|
2005-04-16 15:20:36 -07:00
|
|
|
# is left to other scripts and packages: they can install scripts in the
|
2009-04-22 16:10:10 -07:00
|
|
|
# /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
|
|
|
|
# specified in KDEB_HOOKDIR) that will be called on package install and
|
|
|
|
# removal.
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2024-07-02 11:02:42 -07:00
|
|
|
set -eu
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2019-03-08 02:56:24 -07:00
|
|
|
is_enabled() {
|
2019-03-08 02:56:25 -07:00
|
|
|
grep -q "^$1=y" include/config/auto.conf
|
2019-03-08 02:56:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if_enabled_echo() {
|
|
|
|
if is_enabled "$1"; then
|
|
|
|
echo -n "$2"
|
|
|
|
elif [ $# -ge 3 ]; then
|
|
|
|
echo -n "$3"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-03-12 13:07:29 -07:00
|
|
|
install_linux_image () {
|
2023-12-30 06:51:58 -07:00
|
|
|
pname=$1
|
|
|
|
pdir=debian/$1
|
2023-03-12 13:07:29 -07:00
|
|
|
|
|
|
|
# Only some architectures with OF support have this target
|
|
|
|
if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then
|
|
|
|
${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install
|
|
|
|
fi
|
|
|
|
|
2023-12-26 07:33:59 -07:00
|
|
|
${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" INSTALL_MOD_STRIP=1 modules_install
|
2023-06-25 11:16:23 -07:00
|
|
|
rm -f "${pdir}/lib/modules/${KERNELRELEASE}/build"
|
2023-03-12 13:07:29 -07:00
|
|
|
|
|
|
|
# Install the kernel
|
|
|
|
if [ "${ARCH}" = um ] ; then
|
2023-06-25 11:16:23 -07:00
|
|
|
mkdir -p "${pdir}/usr/lib/uml/modules"
|
|
|
|
mv "${pdir}/lib/modules/${KERNELRELEASE}" "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}"
|
2023-03-12 13:07:29 -07:00
|
|
|
mkdir -p "${pdir}/usr/bin" "${pdir}/usr/share/doc/${pname}"
|
|
|
|
cp System.map "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}/System.map"
|
|
|
|
cp ${KCONFIG_CONFIG} "${pdir}/usr/share/doc/${pname}/config"
|
|
|
|
gzip "${pdir}/usr/share/doc/${pname}/config"
|
|
|
|
else
|
|
|
|
mkdir -p "${pdir}/boot"
|
|
|
|
cp System.map "${pdir}/boot/System.map-${KERNELRELEASE}"
|
|
|
|
cp ${KCONFIG_CONFIG} "${pdir}/boot/config-${KERNELRELEASE}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Not all arches have the same installed path in debian
|
|
|
|
# XXX: have each arch Makefile export a variable of the canonical image install
|
|
|
|
# path instead
|
|
|
|
case "${SRCARCH}" in
|
|
|
|
um)
|
|
|
|
installed_image_path="usr/bin/linux-${KERNELRELEASE}";;
|
|
|
|
parisc|mips|powerpc)
|
|
|
|
installed_image_path="boot/vmlinux-${KERNELRELEASE}";;
|
|
|
|
*)
|
|
|
|
installed_image_path="boot/vmlinuz-${KERNELRELEASE}";;
|
|
|
|
esac
|
|
|
|
cp "$(${MAKE} -s -f ${srctree}/Makefile image_name)" "${pdir}/${installed_image_path}"
|
|
|
|
|
|
|
|
# Install the maintainer scripts
|
|
|
|
# Note: hook scripts under /etc/kernel are also executed by official Debian
|
|
|
|
# kernel packages, as well as kernel packages built using make-kpkg.
|
|
|
|
# make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
|
|
|
|
# so do we; recent versions of dracut and initramfs-tools will obey this.
|
|
|
|
debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
|
|
|
|
for script in postinst postrm preinst prerm; do
|
|
|
|
mkdir -p "${pdir}${debhookdir}/${script}.d"
|
|
|
|
|
|
|
|
mkdir -p "${pdir}/DEBIAN"
|
|
|
|
cat <<-EOF > "${pdir}/DEBIAN/${script}"
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Pass maintainer script parameters to hook scripts
|
|
|
|
export DEB_MAINT_PARAMS="\$*"
|
|
|
|
|
|
|
|
# Tell initramfs builder whether it's wanted
|
|
|
|
export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
|
|
|
|
|
|
|
|
test -d ${debhookdir}/${script}.d && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" ${debhookdir}/${script}.d
|
|
|
|
exit 0
|
|
|
|
EOF
|
|
|
|
chmod 755 "${pdir}/DEBIAN/${script}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
install_linux_image_dbg () {
|
2023-12-30 06:51:58 -07:00
|
|
|
pdir=debian/$1
|
2023-03-12 13:07:29 -07:00
|
|
|
|
2023-12-26 07:33:59 -07:00
|
|
|
# Parse modules.order directly because 'make modules_install' may sign,
|
|
|
|
# compress modules, and then run unneeded depmod.
|
|
|
|
while read -r mod; do
|
|
|
|
mod="${mod%.o}.ko"
|
|
|
|
dbg="${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/kernel/${mod}"
|
|
|
|
buildid=$("${READELF}" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p')
|
|
|
|
link="${pdir}/usr/lib/debug/.build-id/${buildid}.debug"
|
2023-03-12 13:07:29 -07:00
|
|
|
|
2023-12-26 07:33:59 -07:00
|
|
|
mkdir -p "${dbg%/*}" "${link%/*}"
|
|
|
|
"${OBJCOPY}" --only-keep-debug "${mod}" "${dbg}"
|
|
|
|
ln -sf --relative "${dbg}" "${link}"
|
|
|
|
done < modules.order
|
2023-03-12 13:07:29 -07:00
|
|
|
|
|
|
|
# Build debug package
|
|
|
|
# Different tools want the image in different locations
|
|
|
|
# perf
|
|
|
|
mkdir -p ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
|
|
|
|
cp vmlinux ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
|
|
|
|
# systemtap
|
|
|
|
mkdir -p ${pdir}/usr/lib/debug/boot/
|
|
|
|
ln -s ../lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/boot/vmlinux-${KERNELRELEASE}
|
|
|
|
# kdump-tools
|
|
|
|
ln -s lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/vmlinux-${KERNELRELEASE}
|
|
|
|
}
|
|
|
|
|
2023-03-12 13:07:30 -07:00
|
|
|
install_kernel_headers () {
|
2023-12-30 06:51:58 -07:00
|
|
|
pdir=debian/$1
|
|
|
|
version=${1#linux-headers-}
|
2020-01-24 21:12:34 -07:00
|
|
|
|
kbuild: deb-pkg: add pkg.linux-upstream.nokernelheaders build profile
Since commit f1d87664b82a ("kbuild: cross-compile linux-headers package
when possible"), 'make bindeb-pkg' may attempt to cross-compile the
linux-headers package, but it fails under certain circumstances.
For example, when CONFIG_MODULE_SIG_FORMAT is enabled on Debian, the
following command fails:
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bindeb-pkg
[ snip ]
Rebuilding host programs with aarch64-linux-gnu-gcc...
HOSTCC debian/linux-headers-6.12.0-rc4/usr/src/linux-headers-6.12.0-rc4/scripts/kallsyms
HOSTCC debian/linux-headers-6.12.0-rc4/usr/src/linux-headers-6.12.0-rc4/scripts/sorttable
HOSTCC debian/linux-headers-6.12.0-rc4/usr/src/linux-headers-6.12.0-rc4/scripts/asn1_compiler
HOSTCC debian/linux-headers-6.12.0-rc4/usr/src/linux-headers-6.12.0-rc4/scripts/sign-file
In file included from /usr/include/openssl/opensslv.h:109,
from debian/linux-headers-6.12.0-rc4/usr/src/linux-headers-6.12.0-rc4/scripts/sign-file.c:25:
/usr/include/openssl/macros.h:14:10: fatal error: openssl/opensslconf.h: No such file or directory
14 | #include <openssl/opensslconf.h>
| ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
This commit adds a new profile, pkg.linux-upstream.nokernelheaders, to
guard the linux-headers package.
There are two options to fix the above issue.
Option 1: Set the pkg.linux-upstream.nokernelheaders build profile
$ DEB_BUILD_PROFILES=pkg.linux-upstream.nokernelheaders \
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bindeb-pkg
This skips the building of the linux-headers package.
Option 2: Install the necessary build dependencies
If you want to cross-compile the linux-headers package, you need to
install additional packages.
For example, on Debian, the packages necessary for cross-compiling it
to arm64 can be installed with the following commands:
# dpkg --add-architecture arm64
# apt update
# apt install gcc-aarch64-linux-gnu libssl-dev:arm64
Fixes: f1d87664b82a ("kbuild: cross-compile linux-headers package when possible")
Reported-by: Ron Economos <re@w6rz.net>
Closes: https://lore.kernel.org/all/b3d4f49e-7ddb-29ba-0967-689232329b53@w6rz.net/
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Tested-by: Ron Economos <re@w6rz.net>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
2024-10-22 11:16:58 -07:00
|
|
|
CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
|
2020-01-24 21:12:34 -07:00
|
|
|
|
|
|
|
mkdir -p $pdir/lib/modules/$version/
|
|
|
|
ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build
|
|
|
|
}
|
|
|
|
|
2023-03-12 13:07:30 -07:00
|
|
|
install_libc_headers () {
|
2023-12-30 06:51:58 -07:00
|
|
|
pdir=debian/$1
|
2020-01-24 21:12:35 -07:00
|
|
|
|
|
|
|
$MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr
|
|
|
|
|
|
|
|
# move asm headers to /usr/include/<libc-machine>/asm to match the structure
|
|
|
|
# used by Debian-based distros (to support multi-arch)
|
kbuild: deb-pkg: set DEB_* variables if debian/rules is directly executed
Since commit 491b146d4c13 ("kbuild: builddeb: Eliminate debian/arch
use"), direct execution of debian/rules results in the following error:
dpkg-architecture: error: unknown option 'DEB_HOST_MULTIARCH'
The current code:
dpkg-architecture -a$DEB_HOST_ARCH -qDEB_HOST_MULTIARCH
... does not look sensible because:
- For this code to work correctly, DEB_HOST_ARCH must be pre-defined,
which is true when the packages are built via dpkg-buildpackage.
In this case, DEB_HOST_MULTIARCH is also likely defined, hence there
is no need to query DEB_HOST_MULTIARCH in the first place.
- If DEB_HOST_MULTIARCH is undefined, DEB_HOST_ARCH is likely undefined
too. So, you cannot query DEB_HOST_MULTIARCH in this way. This is
mostly the case where debian/rules is directly executed.
When debian/rules is directly executed, querying DEB_HOST_MUCHARCH is
not enough because we need to know DEB_{BUILD,HOST}_GNU_TYPE as well.
All DEB_* variables are defined when the package build is initiated by
dpkg-buildpackage, but otherwise, let's call dpkg-architecture to set
all DEB_* environment variables.
This requires dpkg 1.20.6 or newer because --print-format option
was added in dpkg commit 7c54fa2b232e ("dpkg-architecture: Add a
--print-format option").
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <n.schier@avm.de>
2023-12-26 06:52:40 -07:00
|
|
|
mkdir "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
|
|
|
|
mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
|
2020-01-24 21:12:35 -07:00
|
|
|
}
|
|
|
|
|
2024-01-13 03:43:38 -07:00
|
|
|
package=$1
|
|
|
|
|
|
|
|
case "${package}" in
|
|
|
|
*-dbg)
|
|
|
|
install_linux_image_dbg "${package}";;
|
|
|
|
linux-image-*|user-mode-linux-*)
|
|
|
|
install_linux_image "${package}";;
|
|
|
|
linux-libc-dev)
|
|
|
|
install_libc_headers "${package}";;
|
|
|
|
linux-headers-*)
|
|
|
|
install_kernel_headers "${package}";;
|
|
|
|
esac
|