buildtar 4.09 KB
Newer Older
1
#!/bin/sh
2
# SPDX-License-Identifier: GPL-2.0
3 4

#
5
# buildtar 0.0.4
6
#
7
# (C) 2004-2006 by Jan-Benedict Glaw <jbglaw@lug-owl.de>
8 9 10 11 12 13 14 15 16 17 18 19
#
# This script is used to compile a tarball from the currently
# prepared kernel. Based upon the builddeb script from
# Wichert Akkerman <wichert@wiggy.net>.
#

set -e

#
# Some variables and settings used throughout the script
#
tmpdir="${objtree}/tar-install"
20
tarball="${objtree}/linux-${KERNELRELEASE}-${ARCH}.tar"
21 22 23 24 25 26 27


#
# Figure out how to compress, if requested at all
#
case "${1}" in
	tar-pkg)
28
		opts=
29 30
		;;
	targz-pkg)
31 32
		opts=--gzip
		tarball=${tarball}.gz
33 34
		;;
	tarbz2-pkg)
35 36
		opts=--bzip2
		tarball=${tarball}.bz2
37
		;;
38
	tarxz-pkg)
39 40
		opts=--xz
		tarball=${tarball}.xz
41
		;;
42 43 44 45 46 47 48 49 50 51 52 53
	*)
		echo "Unknown tarball target \"${1}\" requested, please add it to ${0}." >&2
		exit 1
		;;
esac


#
# Clean-up and re-create the temporary directory
#
rm -rf -- "${tmpdir}"
mkdir -p -- "${tmpdir}/boot"
54
dirs=boot
55 56 57 58

#
# Try to install modules
#
59
if grep -q '^CONFIG_MODULES=y' "${KCONFIG_CONFIG}"; then
60
	make ARCH="${ARCH}" -f ${srctree}/Makefile INSTALL_MOD_PATH="${tmpdir}" modules_install
61
	dirs="$dirs lib"
62 63 64 65 66 67
fi


#
# Install basic kernel files
#
68
cp -v -- "${objtree}/System.map" "${tmpdir}/boot/System.map-${KERNELRELEASE}"
69
cp -v -- "${KCONFIG_CONFIG}" "${tmpdir}/boot/config-${KERNELRELEASE}"
70
cp -v -- "${objtree}/vmlinux" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
71 72 73 74 75 76


#
# Install arch-specific kernel image(s)
#
case "${ARCH}" in
77 78
	x86|i386|x86_64)
		[ -f "${objtree}/arch/x86/boot/bzImage" ] && cp -v -- "${objtree}/arch/x86/boot/bzImage" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
79 80
		;;
	alpha)
81
		[ -f "${objtree}/arch/alpha/boot/vmlinux.gz" ] && cp -v -- "${objtree}/arch/alpha/boot/vmlinux.gz" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
82
		;;
Helge Deller's avatar
Helge Deller committed
83 84 85 86
	parisc*)
		[ -f "${KBUILD_IMAGE}" ] && cp -v -- "${KBUILD_IMAGE}" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
		[ -f "${objtree}/lifimage" ] && cp -v -- "${objtree}/lifimage" "${tmpdir}/boot/lifimage-${KERNELRELEASE}"
		;;
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
	mips)
		if [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.bin" ]; then
			cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.bin" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
		elif [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.ecoff" ]; then
			cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.ecoff" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
		elif [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.srec" ]; then
			cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.srec" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
		elif [ -f "${objtree}/vmlinux.32" ]; then
			cp -v -- "${objtree}/vmlinux.32" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
		elif [ -f "${objtree}/vmlinux.64" ]; then
			cp -v -- "${objtree}/vmlinux.64" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
		elif [ -f "${objtree}/arch/mips/boot/vmlinux.bin" ]; then
			cp -v -- "${objtree}/arch/mips/boot/vmlinux.bin" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
		elif [ -f "${objtree}/arch/mips/boot/vmlinux.ecoff" ]; then
			cp -v -- "${objtree}/arch/mips/boot/vmlinux.ecoff" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
		elif [ -f "${objtree}/arch/mips/boot/vmlinux.srec" ]; then
			cp -v -- "${objtree}/arch/mips/boot/vmlinux.srec" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
		elif [ -f "${objtree}/vmlinux" ]; then
			cp -v -- "${objtree}/vmlinux" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
		fi
		;;
108 109 110 111 112 113 114 115
	arm64)
		for i in Image.bz2 Image.gz Image.lz4 Image.lzma Image.lzo ; do
			if [ -f "${objtree}/arch/arm64/boot/${i}" ] ; then
				cp -v -- "${objtree}/arch/arm64/boot/${i}" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
				break
			fi
		done
		;;
116
	*)
117
		[ -f "${KBUILD_IMAGE}" ] && cp -v -- "${KBUILD_IMAGE}" "${tmpdir}/boot/vmlinux-kbuild-${KERNELRELEASE}"
118 119 120
		echo "" >&2
		echo '** ** **  WARNING  ** ** **' >&2
		echo "" >&2
Lucas De Marchi's avatar
Lucas De Marchi committed
121
		echo "Your architecture did not define any architecture-dependent files" >&2
122 123 124 125 126 127 128 129 130 131
		echo "to be placed into the tarball. Please add those to ${0} ..." >&2
		echo "" >&2
		sleep 5
		;;
esac


#
# Create the tarball
#
132 133 134 135 136
if tar --owner=root --group=root --help >/dev/null 2>&1; then
	opts="$opts --owner=root --group=root"
fi

tar cf $tarball -C $tmpdir $opts $dirs
137

138
echo "Tarball successfully created in $tarball"
139 140

exit 0