Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) #!/bin/sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) # builddeb 1.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) # Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) # Simple script to generate a deb package for a Linux kernel. All the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) # complexity of what to do with a kernel after it is installed or removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) # is left to other scripts and packages: they can install scripts in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) # /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) # specified in KDEB_HOOKDIR) that will be called on package install and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) # removal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) set -e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) is_enabled() {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	grep -q "^$1=y" include/config/auto.conf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) if_enabled_echo() {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	if is_enabled "$1"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		echo -n "$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	elif [ $# -ge 3 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		echo -n "$3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) create_package() {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	local pname="$1" pdir="$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	mkdir -m 755 -p "$pdir/DEBIAN"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	mkdir -p "$pdir/usr/share/doc/$pname"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	cp debian/copyright "$pdir/usr/share/doc/$pname/"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	gzip -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		| xargs -r0 md5sum > DEBIAN/md5sums"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	# Fix ownership and permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	chown -R root:root "$pdir"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	chmod -R go-w "$pdir"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	# in case we are in a restrictive umask environment like 0077
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	chmod -R a+rX "$pdir"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	# Create preinstall and post install script to remove dtb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if [ "$3" = "dtb" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	cat >> $pdir/DEBIAN/preinst <<EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) rm -rf /boot/dtb-$version; rm -rf /boot/dtb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	cat >> $pdir/DEBIAN/postinst <<EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) cd /boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) ln -sfT dtb-$version dtb 2> /dev/null || mv dtb-$version dtb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	chmod 775 $pdir/DEBIAN/preinst ; chmod 775 $pdir/DEBIAN/postinst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	# Create postinst prerm scripts for headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if [ "$3" = "headers" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) cat >> $pdir/DEBIAN/postinst << EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) cd /usr/src/linux-headers-$version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) echo "Compiling headers - please wait ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) find -type f -exec touch {} +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) yes "" | make oldconfig >/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) make -j\$(grep -c 'processor' /proc/cpuinfo) -s scripts >/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) make -j\$(grep -c 'processor' /proc/cpuinfo) -s M=scripts/mod/ >/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) cat >> $pdir/DEBIAN/prerm << EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) cd /usr/src/linux-headers-$version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) rm -rf scripts .config.old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	chmod 775 $pdir/DEBIAN/postinst ; chmod 775 $pdir/DEBIAN/prerm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	# Create the package
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	dpkg-gencontrol -p$pname -P"$pdir"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	dpkg-deb ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" ..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) deploy_kernel_headers () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	pdir=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	rm -rf $pdir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		cd $srctree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		find . arch/$SRCARCH -maxdepth 1 -name Makefile\*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		find include scripts -type f -o -type l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	) > debian/hdrsrcfiles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if is_enabled CONFIG_STACK_VALIDATION; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			echo tools/objtool/objtool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		find arch/$SRCARCH/include Module.symvers include scripts -type f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		if is_enabled CONFIG_GCC_PLUGINS; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			find scripts/gcc-plugins -name \*.so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	} > debian/hdrobjfiles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	destdir=$pdir/usr/src/linux-headers-$version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	mkdir -p $destdir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	tar -c -f - -C $srctree -T debian/hdrsrcfiles | tar -xf - -C $destdir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	tar -c -f - -T debian/hdrobjfiles | tar -xf - -C $destdir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	rm -f debian/hdrsrcfiles debian/hdrobjfiles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	# copy .config manually to be where it's expected to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	cp $KCONFIG_CONFIG $destdir/.config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	mkdir -p $pdir/lib/modules/$version/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) deploy_libc_headers () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	pdir=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	rm -rf $pdir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	$MAKE -f $srctree/Makefile headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	$MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	# move asm headers to /usr/include/<libc-machine>/asm to match the structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	# used by Debian-based distros (to support multi-arch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	host_arch=$(dpkg-architecture -a$(cat debian/arch) -qDEB_HOST_MULTIARCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	mkdir $pdir/usr/include/$host_arch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	mv $pdir/usr/include/asm $pdir/usr/include/$host_arch/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) version=$KERNELRELEASE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) tmpdir="$objtree/debian/tmp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) kernel_headers_dir="$objtree/debian/hdrtmp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) libc_headers_dir="$objtree/debian/headertmp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) dbg_dir="$objtree/debian/dbgtmp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) dtb_dir="$objtree/debian/dtbtmp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) packagename=linux-image-"$BRANCH$LOCALVERSION"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) kernel_headers_packagename=linux-headers-"$BRANCH$LOCALVERSION"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) dtb_packagename=linux-dtb-"$BRANCH$LOCALVERSION"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) libc_headers_packagename=linux-libc-dev-"$BRANCH$LOCALVERSION"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) dbg_packagename=$packagename-dbg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if [ "$ARCH" = "um" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	packagename=user-mode-linux-$version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) # Not all arches have the same installed path in debian
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) # XXX: have each arch Makefile export a variable of the canonical image install
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) # path instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) case $ARCH in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) aarch64|arm64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	image_name=Image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	installed_image_path="boot/vmlinuz-$version"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) arm*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	image_name=zImage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	installed_image_path="boot/vmlinuz-$version"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) um)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	installed_image_path="usr/bin/linux-$version"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) parisc|mips|powerpc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	installed_image_path="boot/vmlinux-$version"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	installed_image_path="boot/vmlinuz-$version"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) # Setup the directory structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) rm -rf "$tmpdir" "$kernel_headers_dir" "$libc_headers_dir" "$dbg_dir" "$dtb_dir" $objtree/debian/files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) mkdir -m 755 -p "$dtb_dir/DEBIAN"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) mkdir -p "$dtb_dir/boot/dtb-$version" "$dtb_dir/usr/share/doc/$dtb_packagename"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) mkdir -m 755 -p "$tmpdir/DEBIAN"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) mkdir -p "$tmpdir/lib" "$tmpdir/boot"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) mkdir -p "$kernel_headers_dir/lib/modules/$version/"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) # Build and install the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if [ "$ARCH" = "um" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	$MAKE linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	gzip "$tmpdir/usr/share/doc/$packagename/config"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	cp System.map "$tmpdir/boot/System.map-$version"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) cp "$($MAKE -s -f $srctree/Makefile image_name)" "$tmpdir/$installed_image_path"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if is_enabled CONFIG_OF_EARLY_FLATTREE; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	# Only some architectures with OF support have this target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if [ -d "${srctree}/arch/$SRCARCH/boot/dts" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		$MAKE -f $srctree/Makefile INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if is_enabled CONFIG_MODULES; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_install
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	rm -f "$tmpdir/lib/modules/$version/build"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	rm -f "$tmpdir/lib/modules/$version/source"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if [ "$ARCH" = "um" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		rmdir "$tmpdir/lib/modules/$version"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if [ -n "$BUILD_DEBUG" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		for module in $(find $tmpdir/lib/modules/ -name *.ko -printf '%P\n'); do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			module=lib/modules/$module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			mkdir -p $(dirname $dbg_dir/usr/lib/debug/$module)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			# only keep debug symbols in the debug file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			$OBJCOPY --only-keep-debug $tmpdir/$module $dbg_dir/usr/lib/debug/$module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			# strip original module from debug symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			$OBJCOPY --strip-debug $tmpdir/$module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			# then add a link to those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			$OBJCOPY --add-gnu-debuglink=$dbg_dir/usr/lib/debug/$module $tmpdir/$module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		# resign stripped modules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		if is_enabled CONFIG_MODULE_SIG_ALL; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_sign
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if grep -q '^CONFIG_OF=y' $KCONFIG_CONFIG ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	#mkdir -p "$tmpdir/boot/dtb"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	INSTALL_DTBS_PATH="$dtb_dir/boot/dtb-$version" $MAKE KBUILD_SRC= dtbs_install
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if [ "$ARCH" != "um" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	$MAKE -f $srctree/Makefile headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	$MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH="$libc_headers_dir/usr"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	# move asm headers to /usr/include/<libc-machine>/asm to match the structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	# used by Debian-based distros (to support multi-arch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	host_arch=$(dpkg-architecture -a$(cat debian/arch) -qDEB_HOST_MULTIARCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	mkdir $libc_headers_dir/usr/include/$host_arch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	mv $libc_headers_dir/usr/include/asm $libc_headers_dir/usr/include/$host_arch/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) # Install the maintainer scripts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) # Note: hook scripts under /etc/kernel are also executed by official Debian
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) # kernel packages, as well as kernel packages built using make-kpkg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) # so do we; recent versions of dracut and initramfs-tools will obey this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) for script in postinst postrm preinst prerm ; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	mkdir -p "$tmpdir$debhookdir/$script.d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	cat <<EOF > "$tmpdir/DEBIAN/$script"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #!/bin/bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) set -e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) # Pass maintainer script parameters to hook scripts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) export DEB_MAINT_PARAMS="\$*"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) # Tell initramfs builder whether it's wanted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) test -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) EOF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	chmod 755 "$tmpdir/DEBIAN/$script"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) ##
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) ## Create sym link to kernel image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ##
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) sed -e "s/exit 0//g" -i $tmpdir/DEBIAN/postinst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) cat >> $tmpdir/DEBIAN/postinst <<EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ln -sf $(basename $installed_image_path) /boot/$image_name 2> /dev/null || cp /$installed_image_path /boot/$image_name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) touch /boot/.next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ##
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ## FAT install workaround
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ##
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) sed -e "s/exit 0//g" -i $tmpdir/DEBIAN/preinst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) cat >> $tmpdir/DEBIAN/preinst <<EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) # exit if we are running chroot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if [ "\$(stat -c %d:%i /)" != "\$(stat -c %d:%i /proc/1/root/.)" ]; then exit 0; fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) check_and_unmount (){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	boot_device=\$(mountpoint -d /boot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	for file in /dev/* ; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		CURRENT_DEVICE=\$(printf "%d:%d" \$(stat --printf="0x%t 0x%T" \$file))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		if [[ "\$CURRENT_DEVICE" = "\$boot_device" ]]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			boot_partition=\$file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	bootfstype=\$(blkid -s TYPE -o value \$boot_partition)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if [ "\$bootfstype" = "vfat" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		# we have to keep it mounted! umount /boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		rm -f /boot/System.map* /boot/config* /boot/vmlinuz* /boot/$image_name /boot/uImage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) mountpoint -q /boot && check_and_unmount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) echo "exit 0" >> $tmpdir/DEBIAN/preinst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) # Build kernel header package
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl) > "$objtree/debian/hdrsrcfiles"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) (cd $srctree; find arch/*/include include scripts -type f -o -type l) >> "$objtree/debian/hdrsrcfiles"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) (cd $srctree; find security/*/include -type f) >> "$objtree/debian/hdrsrcfiles"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) ldstemp=$(mktemp);cp scripts/module.lds $ldstemp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) (cd $objtree; make M=scripts clean;)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if is_enabled CONFIG_STACK_VALIDATION; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	(cd $objtree; find tools/objtool -type f -executable) >> "$objtree/debian/hdrobjfiles"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if is_enabled CONFIG_GCC_PLUGINS; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	(cd $objtree; find scripts/gcc-plugins -name \*.so -o -name gcc-common.h) >> "$objtree/debian/hdrobjfiles"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) destdir=$kernel_headers_dir/usr/src/linux-headers-$version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) mkdir -p "$destdir"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) (cd $destdir; patch -p1 < /tmp/headers-debian-byteshift.patch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) (cd $objtree; tar -c -f - -T -) < "$objtree/debian/hdrobjfiles" | (cd $destdir; tar -xf -)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) (cd $objtree; cp $KCONFIG_CONFIG $destdir/.config) # copy .config manually to be where it's expected to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) mv ${ldstemp} $destdir/scripts/module.lds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) ln -sf "/usr/src/linux-headers-$version" "$kernel_headers_dir/lib/modules/$version/build"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) rm -f "$objtree/debian/hdrsrcfiles" "$objtree/debian/hdrobjfiles"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if [ "$ARCH" != "um" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	create_package "$kernel_headers_packagename" "$kernel_headers_dir" "headers"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	create_package "$dtb_packagename" "$dtb_dir" "dtb"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) create_package "$packagename" "$tmpdir"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if [ -n "$BUILD_DEBUG" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	# Build debug package
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	# Different tools want the image in different locations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	# perf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	mkdir -p $dbg_dir/usr/lib/debug/lib/modules/$version/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	cp vmlinux $dbg_dir/usr/lib/debug/lib/modules/$version/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	# systemtap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	mkdir -p $dbg_dir/usr/lib/debug/boot/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	ln -s ../lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/boot/vmlinux-$version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	# kdump-tools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	ln -s lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/vmlinux-$version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	create_package "$dbg_packagename" "$dbg_dir"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) exit 0