18c2ecf20Sopenharmony_ci#!/bin/sh 28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci# 58c2ecf20Sopenharmony_ci# buildtar 0.0.5 68c2ecf20Sopenharmony_ci# 78c2ecf20Sopenharmony_ci# (C) 2004-2006 by Jan-Benedict Glaw <jbglaw@lug-owl.de> 88c2ecf20Sopenharmony_ci# 98c2ecf20Sopenharmony_ci# This script is used to compile a tarball from the currently 108c2ecf20Sopenharmony_ci# prepared kernel. Based upon the builddeb script from 118c2ecf20Sopenharmony_ci# Wichert Akkerman <wichert@wiggy.net>. 128c2ecf20Sopenharmony_ci# 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciset -e 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci# 178c2ecf20Sopenharmony_ci# Some variables and settings used throughout the script 188c2ecf20Sopenharmony_ci# 198c2ecf20Sopenharmony_citmpdir="${objtree}/tar-install" 208c2ecf20Sopenharmony_citarball="${objtree}/linux-${KERNELRELEASE}-${ARCH}.tar" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci# 248c2ecf20Sopenharmony_ci# Figure out how to compress, if requested at all 258c2ecf20Sopenharmony_ci# 268c2ecf20Sopenharmony_cicase "${1}" in 278c2ecf20Sopenharmony_ci dir-pkg|tar-pkg) 288c2ecf20Sopenharmony_ci opts= 298c2ecf20Sopenharmony_ci ;; 308c2ecf20Sopenharmony_ci targz-pkg) 318c2ecf20Sopenharmony_ci opts="-I ${KGZIP}" 328c2ecf20Sopenharmony_ci tarball=${tarball}.gz 338c2ecf20Sopenharmony_ci ;; 348c2ecf20Sopenharmony_ci tarbz2-pkg) 358c2ecf20Sopenharmony_ci opts="-I ${KBZIP2}" 368c2ecf20Sopenharmony_ci tarball=${tarball}.bz2 378c2ecf20Sopenharmony_ci ;; 388c2ecf20Sopenharmony_ci tarxz-pkg) 398c2ecf20Sopenharmony_ci opts="-I ${XZ}" 408c2ecf20Sopenharmony_ci tarball=${tarball}.xz 418c2ecf20Sopenharmony_ci ;; 428c2ecf20Sopenharmony_ci *) 438c2ecf20Sopenharmony_ci echo "Unknown tarball target \"${1}\" requested, please add it to ${0}." >&2 448c2ecf20Sopenharmony_ci exit 1 458c2ecf20Sopenharmony_ci ;; 468c2ecf20Sopenharmony_ciesac 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci# 508c2ecf20Sopenharmony_ci# Clean-up and re-create the temporary directory 518c2ecf20Sopenharmony_ci# 528c2ecf20Sopenharmony_cirm -rf -- "${tmpdir}" 538c2ecf20Sopenharmony_cimkdir -p -- "${tmpdir}/boot" 548c2ecf20Sopenharmony_cidirs=boot 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci# 588c2ecf20Sopenharmony_ci# Try to install dtbs 598c2ecf20Sopenharmony_ci# 608c2ecf20Sopenharmony_ciif grep -q '^CONFIG_OF_EARLY_FLATTREE=y' include/config/auto.conf; then 618c2ecf20Sopenharmony_ci # Only some architectures with OF support have this target 628c2ecf20Sopenharmony_ci if [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then 638c2ecf20Sopenharmony_ci $MAKE ARCH="${ARCH}" -f ${srctree}/Makefile INSTALL_DTBS_PATH="${tmpdir}/boot/dtbs/${KERNELRELEASE}" dtbs_install 648c2ecf20Sopenharmony_ci fi 658c2ecf20Sopenharmony_cifi 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci# 698c2ecf20Sopenharmony_ci# Try to install modules 708c2ecf20Sopenharmony_ci# 718c2ecf20Sopenharmony_ciif grep -q '^CONFIG_MODULES=y' include/config/auto.conf; then 728c2ecf20Sopenharmony_ci make ARCH="${ARCH}" -f ${srctree}/Makefile INSTALL_MOD_PATH="${tmpdir}" modules_install 738c2ecf20Sopenharmony_ci dirs="$dirs lib" 748c2ecf20Sopenharmony_cifi 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci# 788c2ecf20Sopenharmony_ci# Install basic kernel files 798c2ecf20Sopenharmony_ci# 808c2ecf20Sopenharmony_cicp -v -- "${objtree}/System.map" "${tmpdir}/boot/System.map-${KERNELRELEASE}" 818c2ecf20Sopenharmony_cicp -v -- "${KCONFIG_CONFIG}" "${tmpdir}/boot/config-${KERNELRELEASE}" 828c2ecf20Sopenharmony_cicp -v -- "${objtree}/vmlinux" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci# 868c2ecf20Sopenharmony_ci# Install arch-specific kernel image(s) 878c2ecf20Sopenharmony_ci# 888c2ecf20Sopenharmony_cicase "${ARCH}" in 898c2ecf20Sopenharmony_ci x86|i386|x86_64) 908c2ecf20Sopenharmony_ci [ -f "${objtree}/arch/x86/boot/bzImage" ] && cp -v -- "${objtree}/arch/x86/boot/bzImage" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 918c2ecf20Sopenharmony_ci ;; 928c2ecf20Sopenharmony_ci alpha) 938c2ecf20Sopenharmony_ci [ -f "${objtree}/arch/alpha/boot/vmlinux.gz" ] && cp -v -- "${objtree}/arch/alpha/boot/vmlinux.gz" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 948c2ecf20Sopenharmony_ci ;; 958c2ecf20Sopenharmony_ci parisc*) 968c2ecf20Sopenharmony_ci [ -f "${KBUILD_IMAGE}" ] && cp -v -- "${KBUILD_IMAGE}" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 978c2ecf20Sopenharmony_ci [ -f "${objtree}/lifimage" ] && cp -v -- "${objtree}/lifimage" "${tmpdir}/boot/lifimage-${KERNELRELEASE}" 988c2ecf20Sopenharmony_ci ;; 998c2ecf20Sopenharmony_ci mips) 1008c2ecf20Sopenharmony_ci if [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.bin" ]; then 1018c2ecf20Sopenharmony_ci cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.bin" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 1028c2ecf20Sopenharmony_ci elif [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.ecoff" ]; then 1038c2ecf20Sopenharmony_ci cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.ecoff" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 1048c2ecf20Sopenharmony_ci elif [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.srec" ]; then 1058c2ecf20Sopenharmony_ci cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.srec" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 1068c2ecf20Sopenharmony_ci elif [ -f "${objtree}/vmlinux.32" ]; then 1078c2ecf20Sopenharmony_ci cp -v -- "${objtree}/vmlinux.32" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1088c2ecf20Sopenharmony_ci elif [ -f "${objtree}/vmlinux.64" ]; then 1098c2ecf20Sopenharmony_ci cp -v -- "${objtree}/vmlinux.64" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1108c2ecf20Sopenharmony_ci elif [ -f "${objtree}/arch/mips/boot/vmlinux.bin" ]; then 1118c2ecf20Sopenharmony_ci cp -v -- "${objtree}/arch/mips/boot/vmlinux.bin" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1128c2ecf20Sopenharmony_ci elif [ -f "${objtree}/arch/mips/boot/vmlinux.ecoff" ]; then 1138c2ecf20Sopenharmony_ci cp -v -- "${objtree}/arch/mips/boot/vmlinux.ecoff" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1148c2ecf20Sopenharmony_ci elif [ -f "${objtree}/arch/mips/boot/vmlinux.srec" ]; then 1158c2ecf20Sopenharmony_ci cp -v -- "${objtree}/arch/mips/boot/vmlinux.srec" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1168c2ecf20Sopenharmony_ci elif [ -f "${objtree}/vmlinux" ]; then 1178c2ecf20Sopenharmony_ci cp -v -- "${objtree}/vmlinux" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1188c2ecf20Sopenharmony_ci fi 1198c2ecf20Sopenharmony_ci ;; 1208c2ecf20Sopenharmony_ci arm64) 1218c2ecf20Sopenharmony_ci for i in Image.bz2 Image.gz Image.lz4 Image.lzma Image.lzo ; do 1228c2ecf20Sopenharmony_ci if [ -f "${objtree}/arch/arm64/boot/${i}" ] ; then 1238c2ecf20Sopenharmony_ci cp -v -- "${objtree}/arch/arm64/boot/${i}" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 1248c2ecf20Sopenharmony_ci break 1258c2ecf20Sopenharmony_ci fi 1268c2ecf20Sopenharmony_ci done 1278c2ecf20Sopenharmony_ci ;; 1288c2ecf20Sopenharmony_ci *) 1298c2ecf20Sopenharmony_ci [ -f "${KBUILD_IMAGE}" ] && cp -v -- "${KBUILD_IMAGE}" "${tmpdir}/boot/vmlinux-kbuild-${KERNELRELEASE}" 1308c2ecf20Sopenharmony_ci echo "" >&2 1318c2ecf20Sopenharmony_ci echo '** ** ** WARNING ** ** **' >&2 1328c2ecf20Sopenharmony_ci echo "" >&2 1338c2ecf20Sopenharmony_ci echo "Your architecture did not define any architecture-dependent files" >&2 1348c2ecf20Sopenharmony_ci echo "to be placed into the tarball. Please add those to ${0} ..." >&2 1358c2ecf20Sopenharmony_ci echo "" >&2 1368c2ecf20Sopenharmony_ci sleep 5 1378c2ecf20Sopenharmony_ci ;; 1388c2ecf20Sopenharmony_ciesac 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ciif [ "${1}" = dir-pkg ]; then 1418c2ecf20Sopenharmony_ci echo "Kernel tree successfully created in $tmpdir" 1428c2ecf20Sopenharmony_ci exit 0 1438c2ecf20Sopenharmony_cifi 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci# 1468c2ecf20Sopenharmony_ci# Create the tarball 1478c2ecf20Sopenharmony_ci# 1488c2ecf20Sopenharmony_ciif tar --owner=root --group=root --help >/dev/null 2>&1; then 1498c2ecf20Sopenharmony_ci opts="$opts --owner=root --group=root" 1508c2ecf20Sopenharmony_cifi 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_citar cf $tarball -C $tmpdir $opts $dirs 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ciecho "Tarball successfully created in $tarball" 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ciexit 0 157