Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
debian-image-builder/packaging/builddeb
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
388 lines (346 sloc)
11.8 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -e | |
| is_enabled() { | |
| grep -q "^$1=y" include/config/auto.conf | |
| } | |
| if_enabled_echo() { | |
| if is_enabled "$1"; then | |
| echo -n "$2" | |
| elif [ $# -ge 3 ]; then | |
| echo -n "$3" | |
| fi | |
| } | |
| create_package() { | |
| local pname="$1" pdir="$2" | |
| mkdir -m 755 -p "$pdir/DEBIAN" | |
| mkdir -p "$pdir/usr/share/doc/$pname" | |
| cp debian/copyright "$pdir/usr/share/doc/$pname/" | |
| cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian" | |
| gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian" | |
| sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \ | |
| | xargs -r0 md5sum > DEBIAN/md5sums" | |
| # Fix ownership and permissions | |
| chown -R root:root "$pdir" | |
| chmod -R go-w "$pdir" | |
| # in case we are in a restrictive umask environment like 0077 | |
| chmod -R a+rX "$pdir" | |
| # Create the package | |
| dpkg-gencontrol -p$pname -P"$pdir" | |
| dpkg-deb -Z$compression --build "$pdir" .. | |
| } | |
| if [ -f scripts/package/pkgvars ]; then | |
| . scripts/package/pkgvars | |
| else | |
| echo "Missing: pkgvars" | |
| exit 0 | |
| fi | |
| version=$KERNELRELEASE | |
| tmpdir="$objtree/debian/tmp" | |
| kernel_headers_dir="$objtree/debian/hdrtmp" | |
| libc_headers_dir="$objtree/debian/headertmp" | |
| dbg_dir="$objtree/debian/dbgtmp" | |
| libc_headers_packagename=linux-libc-dev | |
| dbg_packagename=$packagename-dbg | |
| # variables set by pkgvars | |
| packagename=$linux_name | |
| kernel_headers_packagename=$headers_name | |
| # end of pkgvars | |
| if [ "$ARCH" = "um" ] ; then | |
| packagename=user-mode-linux-$version | |
| 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 $ARCH in | |
| um) | |
| installed_image_path="usr/bin/linux-$version" | |
| ;; | |
| parisc|mips|powerpc) | |
| installed_image_path="boot/vmlinux-$version" | |
| ;; | |
| *) | |
| installed_image_path="boot/vmlinuz-$version" | |
| esac | |
| BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes) | |
| # Setup the directory structure | |
| rm -rf "$tmpdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" $objtree/debian/files | |
| mkdir -m 755 -p "$tmpdir/DEBIAN" | |
| mkdir -p "$tmpdir/lib" "$tmpdir/boot" | |
| mkdir -p "$kernel_headers_dir/lib/modules/$version/" | |
| # Build and install the kernel | |
| if [ "$ARCH" = "um" ] ; then | |
| mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename" | |
| $MAKE linux | |
| cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map" | |
| cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config" | |
| gzip "$tmpdir/usr/share/doc/$packagename/config" | |
| else | |
| cp System.map "$tmpdir/boot/System.map-$version" | |
| cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version" | |
| if [ -f arch/arm/boot/zImage ]; then | |
| cp arch/arm/boot/zImage "$tmpdir/boot/Image" | |
| fi | |
| if [ -f arch/arm64/boot/Image ]; then | |
| cp arch/arm64/boot/Image "$tmpdir/boot/Image" | |
| fi | |
| if [ "$platform" = "broadcom" ]; then | |
| mkdir -p "$tmpdir/boot/$platform" | |
| if [ -f arch/arm/boot/zImage ]; then | |
| cp arch/arm/boot/zImage "$tmpdir/boot/$platform/Image" | |
| fi | |
| if [ -f arch/arm64/boot/Image ]; then | |
| cp arch/arm64/boot/Image "$tmpdir/boot/$platform/Image" | |
| fi | |
| if [ -f firmware/bootcode.bin ]; then | |
| install -m 0644 firmware/bootcode.bin "$tmpdir/boot/$platform" | |
| fi | |
| if [ -f firmware/fixup.dat ]; then | |
| install -m 0644 firmware/fixup*.dat "$tmpdir/boot/$platform" | |
| fi | |
| if [ -f firmware/start.elf ]; then | |
| install -m 0644 firmware/start*.elf "$tmpdir/boot/$platform" | |
| fi | |
| if [ -f firmware/fixup4.dat ]; then | |
| install -m 0644 firmware/fixup4*.dat "$tmpdir/boot/$platform" | |
| fi | |
| if [ -f firmware/start4.elf ]; then | |
| install -m 0644 firmware/start4*.elf "$tmpdir/boot/$platform" | |
| fi | |
| if [ -f firmware/LICENCE.broadcom ]; then | |
| install -m 0644 firmware/LICENCE.broadcom "$tmpdir/boot/$platform" | |
| fi | |
| if [ -f firmware/COPYING.linux ]; then | |
| install -m 0644 firmware/COPYING.linux "$tmpdir/boot/$platform" | |
| fi | |
| fi | |
| fi | |
| cp "$($MAKE -s -f $srctree/Makefile image_name)" "$tmpdir/$installed_image_path" | |
| if is_enabled CONFIG_OF_EARLY_FLATTREE; then | |
| # Only some architectures with OF support have this target | |
| if [ -d "${srctree}/arch/$SRCARCH/boot/dts" ]; then | |
| $MAKE -f $srctree/Makefile INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install | |
| fi | |
| fi | |
| if is_enabled CONFIG_MODULES; then | |
| INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_install | |
| rm -f "$tmpdir/lib/modules/$version/build" | |
| rm -f "$tmpdir/lib/modules/$version/source" | |
| if [ "$ARCH" = "um" ] ; then | |
| mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/" | |
| rmdir "$tmpdir/lib/modules/$version" | |
| fi | |
| if [ -n "$BUILD_DEBUG" ] ; then | |
| for module in $(find $tmpdir/lib/modules/ -name *.ko -printf '%P\n'); do | |
| module=lib/modules/$module | |
| mkdir -p $(dirname $dbg_dir/usr/lib/debug/$module) | |
| # only keep debug symbols in the debug file | |
| $OBJCOPY --only-keep-debug $tmpdir/$module $dbg_dir/usr/lib/debug/$module | |
| # strip original module from debug symbols | |
| $OBJCOPY --strip-debug $tmpdir/$module | |
| # then add a link to those | |
| $OBJCOPY --add-gnu-debuglink=$dbg_dir/usr/lib/debug/$module $tmpdir/$module | |
| done | |
| # resign stripped modules | |
| if is_enabled CONFIG_MODULE_SIG_ALL; then | |
| INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_sign | |
| fi | |
| fi | |
| fi | |
| if [ "$ARCH" != "um" ]; then | |
| $MAKE -f $srctree/Makefile headers | |
| $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH="$libc_headers_dir/usr" | |
| # move asm headers to /usr/include/<libc-machine>/asm to match the structure | |
| # used by Debian-based distros (to support multi-arch) | |
| host_arch=$(dpkg-architecture -a$(cat debian/arch) -qDEB_HOST_MULTIARCH) | |
| mkdir $libc_headers_dir/usr/include/$host_arch | |
| mv $libc_headers_dir/usr/include/asm $libc_headers_dir/usr/include/$host_arch/ | |
| fi | |
| # variables set by pkgvars | |
| if [ -d $tmpdir/$linux_path ]; then | |
| # devicetree | |
| if [ -f $tmpdir/$dtb_path ]; then | |
| mkdir -p "$tmpdir/$boot_path" | |
| cp -r "$tmpdir/$dtb_path" "$tmpdir/$install_devicetree" | |
| fi | |
| if [ -z $device_tree_2 ]; then | |
| :; | |
| else | |
| if [ -f "$tmpdir/$linux_path/$device_tree_2" ]; then | |
| cp -r "$tmpdir/$linux_path/$device_tree_2" "$tmpdir/$boot_path" | |
| fi | |
| fi | |
| if [ -z $device_tree_3 ]; then | |
| :; | |
| else | |
| if [ -f "$tmpdir/$linux_path/$device_tree_3" ]; then | |
| cp -r "$tmpdir/$linux_path/$device_tree_3" "$tmpdir/$boot_path" | |
| fi | |
| fi | |
| if [ -z $device_tree_4 ]; then | |
| :; | |
| else | |
| if [ -f "$tmpdir/$linux_path/$device_tree_4" ]; then | |
| cp -r "$tmpdir/$linux_path/$device_tree_4" "$tmpdir/$boot_path" | |
| fi | |
| fi | |
| # overlays | |
| if [ -d $tmpdir/$overlays_path ]; then | |
| mkdir -p "$tmpdir/$boot_path/overlays" | |
| cp -r "$tmpdir/$overlays_path/" "$tmpdir/$install_overlays/" | |
| fi | |
| fi | |
| # end of pkgvars | |
| # Install the maintainer scripts | |
| debhookdir=${KDEB_HOOKDIR:-/etc/kernel} | |
| for script in postinst postrm preinst prerm ; do | |
| mkdir -p "$tmpdir$debhookdir/$script.d" | |
| cat <<EOF > "$tmpdir/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="$version" --arg="/$installed_image_path" $debhookdir/$script.d | |
| exit 0 | |
| EOF | |
| chmod 755 "$tmpdir/DEBIAN/$script" | |
| done | |
| if [ "$platform" = "broadcom" ]; then | |
| cat <<EOF > "$tmpdir/DEBIAN/preinst" | |
| #!/bin/bash | |
| set -e | |
| # clean boot directory | |
| if [ -f /boot/Image ]; then | |
| rm -fr /boot/{Image,vmlinuz-*,System.map-*,config-*}; | |
| fi | |
| if [ -f /boot/initrd.gz ]; then | |
| rm -fr /boot/{initrd.gz,uInitrd,initrd.img-*}; | |
| fi | |
| if [ -f /boot/$platform/Image ]; then | |
| rm -fr /boot/$platform/Image; | |
| fi | |
| if [ -f /boot/$platform/initrd.gz ]; then | |
| rm -fr /boot/$platform/initrd.gz; | |
| fi | |
| if [ -f /boot/$platform/$device_tree ]; then | |
| rm -fr /boot/$platform/{*.dtb,bootcode.bin,fixup*.dat,start*.elf,fixup4*.dat,start4*.elf,LICENCE.broadcom,COPYING.linux}; | |
| if [ -d /boot/$platform/overlays ]; then | |
| rm -fdr /boot/$platform/overlays; | |
| fi | |
| fi | |
| exit 0 | |
| EOF | |
| chmod 755 "$tmpdir/DEBIAN/preinst" | |
| else | |
| cat <<EOF > "$tmpdir/DEBIAN/preinst" | |
| #!/bin/bash | |
| set -e | |
| # clean boot directory | |
| if [ -f /boot/Image ]; then | |
| rm -fr /boot/{Image,vmlinuz-*,System.map-*,config-*}; | |
| fi | |
| if [ -f /boot/uInitrd ]; then | |
| rm -fr /boot/{uInitrd,initrd.img-*}; | |
| fi | |
| if [ -f /boot/initrd.gz ]; then | |
| rm -fr /boot/{initrd.gz,initrd.img-*}; | |
| fi | |
| if [ -f /boot/$device_tree ]; then | |
| rm -fr /boot/*.dtb; | |
| if [ -d /boot/overlays ]; then | |
| rm -fdr /boot/overlays; | |
| fi | |
| fi | |
| if [ -f /boot/$platform/$device_tree ]; then | |
| rm -fr /boot/$platform/*.dtb; | |
| if [ -d /boot/$platform/overlays ]; then | |
| rm -fdr /boot/$platform/overlays; | |
| fi | |
| fi | |
| exit 0 | |
| EOF | |
| chmod 755 "$tmpdir/DEBIAN/preinst" | |
| fi | |
| # Build kernel header package | |
| (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl) > "$objtree/debian/hdrsrcfiles" | |
| (cd $srctree; find arch/*/include include scripts -type f -o -type l) >> "$objtree/debian/hdrsrcfiles" | |
| (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles" | |
| (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles" | |
| if is_enabled CONFIG_STACK_VALIDATION; then | |
| (cd $objtree; find tools/objtool -type f -executable) >> "$objtree/debian/hdrobjfiles" | |
| fi | |
| (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles" | |
| if is_enabled CONFIG_GCC_PLUGINS; then | |
| (cd $objtree; find scripts/gcc-plugins -name \*.so -o -name gcc-common.h) >> "$objtree/debian/hdrobjfiles" | |
| fi | |
| destdir=$kernel_headers_dir/usr/src/linux-headers-$version | |
| mkdir -p "$destdir" | |
| (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -) | |
| (cd $objtree; tar -c -f - -T -) < "$objtree/debian/hdrobjfiles" | (cd $destdir; tar -xf -) | |
| (cd $objtree; cp $KCONFIG_CONFIG $destdir/.config) # copy .config manually to be where it's expected to be | |
| ln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build" | |
| rm -f "$objtree/debian/hdrsrcfiles" "$objtree/debian/hdrobjfiles" | |
| # kernel headers postinst and preinst script | |
| if [ -f headers-byteshift.patch ]; then | |
| cp -f "headers-byteshift.patch" "$destdir/" | |
| cp -f "$srctree/scripts/module.lds" "$destdir/" | |
| mkdir -p "$kernel_headers_dir/DEBIAN" | |
| cat <<EOF > "$kernel_headers_dir/DEBIAN/postinst" | |
| #!/bin/bash | |
| set -e | |
| clean_headers(){ | |
| find -type f -exec touch {} + | |
| if grep -w "Linux/arm" ".config"; then | |
| echo 'y' | make ARCH=arm M=scripts clean; | |
| else | |
| echo 'y' | make M=scripts clean; | |
| fi | |
| patch -p1 < headers-byteshift.patch | |
| if [ -f scripts/module.lds ]; then :; else install -m 0644 module.lds scripts/; fi | |
| rm -f {headers-byteshift.patch,module.lds} | |
| if grep -w "Linux/arm" ".config"; then | |
| echo 'y' | make ARCH=arm -j\$(grep -c 'processor' /proc/cpuinfo) -s scripts; | |
| echo 'y' | make ARCH=arm -j\$(grep -c 'processor' /proc/cpuinfo) -s M=scripts/mod/; | |
| else | |
| echo 'y' | make -j\$(grep -c 'processor' /proc/cpuinfo) -s scripts; | |
| echo 'y' | make -j\$(grep -c 'processor' /proc/cpuinfo) -s M=scripts/mod/; | |
| fi | |
| if [ -f .config.old ]; then rm -f .config.old; fi | |
| } | |
| # compile headers | |
| cd /usr/src/linux-headers-$version | |
| echo -e "Compiling headers ..." | |
| clean_headers > /dev/null 2>&1; | |
| exit 0 | |
| EOF | |
| chmod 755 "$kernel_headers_dir/DEBIAN/postinst" | |
| fi | |
| mkdir -p $kernel_headers_dir/DEBIAN | |
| cat <<EOF > "$kernel_headers_dir/DEBIAN/preinst" | |
| #!/bin/sh | |
| set -e | |
| # remove old linux headers | |
| rm -fdr /usr/src/linux-headers-* > /dev/null 2>&1 | |
| exit 0 | |
| EOF | |
| chmod 755 "$kernel_headers_dir/DEBIAN/preinst" | |
| if [ "$ARCH" != "um" ]; then | |
| create_package "$kernel_headers_packagename" "$kernel_headers_dir" | |
| create_package "$libc_headers_packagename" "$libc_headers_dir" | |
| fi | |
| create_package "$packagename" "$tmpdir" | |
| if [ -n "$BUILD_DEBUG" ] ; then | |
| # Build debug package | |
| # Different tools want the image in different locations | |
| # perf | |
| mkdir -p $dbg_dir/usr/lib/debug/lib/modules/$version/ | |
| cp vmlinux $dbg_dir/usr/lib/debug/lib/modules/$version/ | |
| # systemtap | |
| mkdir -p $dbg_dir/usr/lib/debug/boot/ | |
| ln -s ../lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/boot/vmlinux-$version | |
| # kdump-tools | |
| ln -s lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/vmlinux-$version | |
| create_package "$dbg_packagename" "$dbg_dir" | |
| fi | |
| exit 0 |