6 # Simple script to generate a deb package for a Linux kernel. All the
7 # complexity of what to do with a kernel after it is installed or removed
8 # is left to other scripts and packages. Scripts can be placed into the
9 # preinst, postinst, prerm and postrm directories in /etc/kernel or
10 # /usr/share/kernel. A different list of search directories can be given
11 # via KDEB_HOOKDIR. Scripts in directories earlier in the list will
12 # override scripts of the same name in later directories. The script will
13 # be called on package installation and removal.
18 grep -q "^$1=y" include/config/auto.conf
22 if is_enabled "$1"; then
24 elif [ $# -ge 3 ]; then
29 install_linux_image () {
33 # Only some architectures with OF support have this target
34 if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then
35 ${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install
38 ${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" INSTALL_MOD_STRIP=1 modules_install
39 rm -f "${pdir}/lib/modules/${KERNELRELEASE}/build"
42 if [ "${ARCH}" = um ] ; then
43 mkdir -p "${pdir}/usr/lib/uml/modules"
44 mv "${pdir}/lib/modules/${KERNELRELEASE}" "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}"
45 mkdir -p "${pdir}/usr/bin" "${pdir}/usr/share/doc/${pname}"
46 cp System.map "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}/System.map"
47 cp ${KCONFIG_CONFIG} "${pdir}/usr/share/doc/${pname}/config"
48 gzip "${pdir}/usr/share/doc/${pname}/config"
50 mkdir -p "${pdir}/boot"
51 cp System.map "${pdir}/boot/System.map-${KERNELRELEASE}"
52 cp ${KCONFIG_CONFIG} "${pdir}/boot/config-${KERNELRELEASE}"
55 # Not all arches have the same installed path in debian
56 # XXX: have each arch Makefile export a variable of the canonical image install
60 installed_image_path="usr/bin/linux-${KERNELRELEASE}";;
62 installed_image_path="boot/vmlinux-${KERNELRELEASE}";;
64 installed_image_path="boot/vmlinuz-${KERNELRELEASE}";;
66 cp "$(${MAKE} -s -f ${srctree}/Makefile image_name)" "${pdir}/${installed_image_path}"
68 if [ "${ARCH}" != um ]; then
69 install_maint_scripts "${pdir}"
73 install_maint_scripts () {
74 # Install the maintainer scripts
75 # Note: hook scripts under /etc/kernel are also executed by official Debian
76 # kernel packages, as well as kernel packages built using make-kpkg.
77 # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
78 # so do we; recent versions of dracut and initramfs-tools will obey this.
79 debhookdir=${KDEB_HOOKDIR:-/etc/kernel /usr/share/kernel}
80 for script in postinst postrm preinst prerm; do
81 mkdir -p "${pdir}/DEBIAN"
82 cat <<-EOF > "${pdir}/DEBIAN/${script}"
87 # Pass maintainer script parameters to hook scripts
88 export DEB_MAINT_PARAMS="\$*"
90 # Tell initramfs builder whether it's wanted
91 export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
93 # run-parts will error out if one of its directory arguments does not
94 # exist, so filter the list of hook directories accordingly.
96 for dir in ${debhookdir}; do
97 test -d "\$dir/${script}.d" || continue
98 hookdirs="\$hookdirs \$dir/${script}.d"
100 hookdirs="\${hookdirs# }"
101 test -n "\$hookdirs" && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" \$hookdirs
104 chmod 755 "${pdir}/DEBIAN/${script}"
108 install_linux_image_dbg () {
111 # Parse modules.order directly because 'make modules_install' may sign,
112 # compress modules, and then run unneeded depmod.
113 if is_enabled CONFIG_MODULES; then
114 while read -r mod; do
116 dbg="${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/kernel/${mod}"
117 buildid=$("${READELF}" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p')
118 link="${pdir}/usr/lib/debug/.build-id/${buildid}.debug"
120 mkdir -p "${dbg%/*}" "${link%/*}"
121 "${OBJCOPY}" --only-keep-debug "${mod}" "${dbg}"
122 ln -sf --relative "${dbg}" "${link}"
126 # Build debug package
127 # Different tools want the image in different locations
129 mkdir -p ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
130 cp vmlinux ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
132 mkdir -p ${pdir}/usr/lib/debug/boot/
133 ln -s ../lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/boot/vmlinux-${KERNELRELEASE}
135 ln -s lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/vmlinux-${KERNELRELEASE}
138 install_kernel_headers () {
140 version=${1#linux-headers-}
142 CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
144 mkdir -p $pdir/lib/modules/$version/
145 ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build
148 install_libc_headers () {
151 $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr
153 # move asm headers to /usr/include/<libc-machine>/asm to match the structure
154 # used by Debian-based distros (to support multi-arch)
155 mkdir "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
156 mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
163 install_linux_image_dbg "${package}";;
164 linux-image-*|user-mode-linux-*)
165 install_linux_image "${package}";;
167 install_libc_headers "${package}";;
169 install_kernel_headers "${package}";;