Skip to content

Commit b611daa

Browse files
committed
kbuild: deb-pkg: split image and debug objects staging out into functions
Prepare for the refactoring in the next commit. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent f50aa51 commit b611daa

File tree

1 file changed

+116
-106
lines changed

1 file changed

+116
-106
lines changed

scripts/package/builddeb

Lines changed: 116 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,115 @@ create_package() {
5151
dpkg-deb $dpkg_deb_opts ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" ..
5252
}
5353

54+
install_linux_image () {
55+
pdir=$1
56+
pname=$2
57+
58+
rm -rf ${pdir}
59+
60+
# Only some architectures with OF support have this target
61+
if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then
62+
${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install
63+
fi
64+
65+
if is_enabled CONFIG_MODULES; then
66+
${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" modules_install
67+
rm -f "${pdir}/lib/modules/${KERNELRELEASE}/build"
68+
rm -f "${pdir}/lib/modules/${KERNELRELEASE}/source"
69+
if [ "${SRCARCH}" = um ] ; then
70+
mkdir -p "${pdir}/usr/lib/uml/modules"
71+
mv "${pdir}/lib/modules/${KERNELRELEASE}" "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}"
72+
fi
73+
fi
74+
75+
# Install the kernel
76+
if [ "${ARCH}" = um ] ; then
77+
mkdir -p "${pdir}/usr/bin" "${pdir}/usr/share/doc/${pname}"
78+
cp System.map "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}/System.map"
79+
cp ${KCONFIG_CONFIG} "${pdir}/usr/share/doc/${pname}/config"
80+
gzip "${pdir}/usr/share/doc/${pname}/config"
81+
else
82+
mkdir -p "${pdir}/boot"
83+
cp System.map "${pdir}/boot/System.map-${KERNELRELEASE}"
84+
cp ${KCONFIG_CONFIG} "${pdir}/boot/config-${KERNELRELEASE}"
85+
fi
86+
87+
# Not all arches have the same installed path in debian
88+
# XXX: have each arch Makefile export a variable of the canonical image install
89+
# path instead
90+
case "${SRCARCH}" in
91+
um)
92+
installed_image_path="usr/bin/linux-${KERNELRELEASE}";;
93+
parisc|mips|powerpc)
94+
installed_image_path="boot/vmlinux-${KERNELRELEASE}";;
95+
*)
96+
installed_image_path="boot/vmlinuz-${KERNELRELEASE}";;
97+
esac
98+
cp "$(${MAKE} -s -f ${srctree}/Makefile image_name)" "${pdir}/${installed_image_path}"
99+
100+
# Install the maintainer scripts
101+
# Note: hook scripts under /etc/kernel are also executed by official Debian
102+
# kernel packages, as well as kernel packages built using make-kpkg.
103+
# make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
104+
# so do we; recent versions of dracut and initramfs-tools will obey this.
105+
debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
106+
for script in postinst postrm preinst prerm; do
107+
mkdir -p "${pdir}${debhookdir}/${script}.d"
108+
109+
mkdir -p "${pdir}/DEBIAN"
110+
cat <<-EOF > "${pdir}/DEBIAN/${script}"
111+
112+
#!/bin/sh
113+
114+
set -e
115+
116+
# Pass maintainer script parameters to hook scripts
117+
export DEB_MAINT_PARAMS="\$*"
118+
119+
# Tell initramfs builder whether it's wanted
120+
export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
121+
122+
test -d ${debhookdir}/${script}.d && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" ${debhookdir}/${script}.d
123+
exit 0
124+
EOF
125+
chmod 755 "${pdir}/DEBIAN/${script}"
126+
done
127+
}
128+
129+
install_linux_image_dbg () {
130+
pdir=$1
131+
image_pdir=$2
132+
133+
rm -rf ${pdir}
134+
135+
for module in $(find ${image_pdir}/lib/modules/ -name *.ko -printf '%P\n'); do
136+
module=lib/modules/${module}
137+
mkdir -p $(dirname ${pdir}/usr/lib/debug/${module})
138+
# only keep debug symbols in the debug file
139+
${OBJCOPY} --only-keep-debug ${image_pdir}/${module} ${pdir}/usr/lib/debug/${module}
140+
# strip original module from debug symbols
141+
${OBJCOPY} --strip-debug ${image_pdir}/${module}
142+
# then add a link to those
143+
${OBJCOPY} --add-gnu-debuglink=${pdir}/usr/lib/debug/${module} ${image_pdir}/${module}
144+
done
145+
146+
# re-sign stripped modules
147+
if is_enabled CONFIG_MODULE_SIG_ALL; then
148+
${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${image_pdir}" modules_sign
149+
fi
150+
151+
# Build debug package
152+
# Different tools want the image in different locations
153+
# perf
154+
mkdir -p ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
155+
cp vmlinux ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
156+
# systemtap
157+
mkdir -p ${pdir}/usr/lib/debug/boot/
158+
ln -s ../lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/boot/vmlinux-${KERNELRELEASE}
159+
# kdump-tools
160+
ln -s lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/vmlinux-${KERNELRELEASE}
161+
}
162+
54163
deploy_kernel_headers () {
55164
pdir=$1
56165

@@ -105,106 +214,14 @@ deploy_libc_headers () {
105214
}
106215

107216
version=$KERNELRELEASE
108-
tmpdir=debian/linux-image
109-
dbg_dir=debian/linux-image-dbg
110217
packagename=linux-image-$version
111218
dbg_packagename=$packagename-dbg
112219

113220
if [ "$ARCH" = "um" ] ; then
114221
packagename=user-mode-linux-$version
115222
fi
116223

117-
# Not all arches have the same installed path in debian
118-
# XXX: have each arch Makefile export a variable of the canonical image install
119-
# path instead
120-
case $ARCH in
121-
um)
122-
installed_image_path="usr/bin/linux-$version"
123-
;;
124-
parisc|mips|powerpc)
125-
installed_image_path="boot/vmlinux-$version"
126-
;;
127-
*)
128-
installed_image_path="boot/vmlinuz-$version"
129-
esac
130-
131-
BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes)
132-
133-
# Setup the directory structure
134-
rm -rf "$tmpdir" "$dbg_dir" debian/files
135-
mkdir -m 755 -p "$tmpdir/DEBIAN"
136-
mkdir -p "$tmpdir/lib" "$tmpdir/boot"
137-
138-
# Install the kernel
139-
if [ "$ARCH" = "um" ] ; then
140-
mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename"
141-
cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
142-
cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config"
143-
gzip "$tmpdir/usr/share/doc/$packagename/config"
144-
else
145-
cp System.map "$tmpdir/boot/System.map-$version"
146-
cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version"
147-
fi
148-
cp "$($MAKE -s -f $srctree/Makefile image_name)" "$tmpdir/$installed_image_path"
149-
150-
if is_enabled CONFIG_OF_EARLY_FLATTREE; then
151-
# Only some architectures with OF support have this target
152-
if [ -d "${srctree}/arch/$SRCARCH/boot/dts" ]; then
153-
$MAKE -f $srctree/Makefile INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install
154-
fi
155-
fi
156-
157-
if is_enabled CONFIG_MODULES; then
158-
INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_install
159-
rm -f "$tmpdir/lib/modules/$version/build"
160-
rm -f "$tmpdir/lib/modules/$version/source"
161-
if [ "$ARCH" = "um" ] ; then
162-
mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
163-
rmdir "$tmpdir/lib/modules/$version"
164-
fi
165-
if [ -n "$BUILD_DEBUG" ] ; then
166-
for module in $(find $tmpdir/lib/modules/ -name *.ko -printf '%P\n'); do
167-
module=lib/modules/$module
168-
mkdir -p $(dirname $dbg_dir/usr/lib/debug/$module)
169-
# only keep debug symbols in the debug file
170-
$OBJCOPY --only-keep-debug $tmpdir/$module $dbg_dir/usr/lib/debug/$module
171-
# strip original module from debug symbols
172-
$OBJCOPY --strip-debug $tmpdir/$module
173-
# then add a link to those
174-
$OBJCOPY --add-gnu-debuglink=$dbg_dir/usr/lib/debug/$module $tmpdir/$module
175-
done
176-
177-
# resign stripped modules
178-
if is_enabled CONFIG_MODULE_SIG_ALL; then
179-
INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_sign
180-
fi
181-
fi
182-
fi
183-
184-
# Install the maintainer scripts
185-
# Note: hook scripts under /etc/kernel are also executed by official Debian
186-
# kernel packages, as well as kernel packages built using make-kpkg.
187-
# make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
188-
# so do we; recent versions of dracut and initramfs-tools will obey this.
189-
debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
190-
for script in postinst postrm preinst prerm ; do
191-
mkdir -p "$tmpdir$debhookdir/$script.d"
192-
cat <<EOF > "$tmpdir/DEBIAN/$script"
193-
#!/bin/sh
194-
195-
set -e
196-
197-
# Pass maintainer script parameters to hook scripts
198-
export DEB_MAINT_PARAMS="\$*"
199-
200-
# Tell initramfs builder whether it's wanted
201-
export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
202-
203-
test -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d
204-
exit 0
205-
EOF
206-
chmod 755 "$tmpdir/DEBIAN/$script"
207-
done
224+
rm -f debian/files
208225

209226
if [ "$ARCH" != "um" ]; then
210227
if is_enabled CONFIG_MODULES; then
@@ -216,20 +233,13 @@ if [ "$ARCH" != "um" ]; then
216233
create_package linux-libc-dev debian/linux-libc-dev
217234
fi
218235

219-
create_package "$packagename" "$tmpdir"
236+
install_linux_image debian/linux-image "$packagename"
220237

221-
if [ -n "$BUILD_DEBUG" ] ; then
222-
# Build debug package
223-
# Different tools want the image in different locations
224-
# perf
225-
mkdir -p $dbg_dir/usr/lib/debug/lib/modules/$version/
226-
cp vmlinux $dbg_dir/usr/lib/debug/lib/modules/$version/
227-
# systemtap
228-
mkdir -p $dbg_dir/usr/lib/debug/boot/
229-
ln -s ../lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/boot/vmlinux-$version
230-
# kdump-tools
231-
ln -s lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/vmlinux-$version
232-
create_package "$dbg_packagename" "$dbg_dir"
238+
if is_enabled CONFIG_DEBUG_INFO; then
239+
install_linux_image_dbg debian/linux-image-dbg debian/linux-image
240+
create_package "$dbg_packagename" debian/linux-image-dbg
233241
fi
234242

243+
create_package "$packagename" debian/linux-image
244+
235245
exit 0

0 commit comments

Comments
 (0)