16d983feaSJan-Benedict Glaw#!/bin/sh 2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 36d983feaSJan-Benedict Glaw 46d983feaSJan-Benedict Glaw# 5af7db99aSMatteo Croce# buildtar 0.0.5 66d983feaSJan-Benedict Glaw# 76073aa64SJan-Benedict Glaw# (C) 2004-2006 by Jan-Benedict Glaw <jbglaw@lug-owl.de> 86d983feaSJan-Benedict Glaw# 96d983feaSJan-Benedict Glaw# This script is used to compile a tarball from the currently 106d983feaSJan-Benedict Glaw# prepared kernel. Based upon the builddeb script from 116d983feaSJan-Benedict Glaw# Wichert Akkerman <wichert@wiggy.net>. 126d983feaSJan-Benedict Glaw# 136d983feaSJan-Benedict Glaw 146d983feaSJan-Benedict Glawset -e 156d983feaSJan-Benedict Glaw 166d983feaSJan-Benedict Glaw# 176d983feaSJan-Benedict Glaw# Some variables and settings used throughout the script 186d983feaSJan-Benedict Glaw# 196d983feaSJan-Benedict Glawtmpdir="${objtree}/tar-install" 206bc6c940SBorislav Petkovtarball="${objtree}/linux-${KERNELRELEASE}-${ARCH}.tar" 216d983feaSJan-Benedict Glaw 226d983feaSJan-Benedict Glaw 236d983feaSJan-Benedict Glaw# 246d983feaSJan-Benedict Glaw# Figure out how to compress, if requested at all 256d983feaSJan-Benedict Glaw# 266d983feaSJan-Benedict Glawcase "${1}" in 27af7db99aSMatteo Croce dir-pkg|tar-pkg) 2877780f79SMasahiro Yamada opts= 296d983feaSJan-Benedict Glaw ;; 306d983feaSJan-Benedict Glaw targz-pkg) 31e4a42c82SDenis Efremov opts="-I ${KGZIP}" 3277780f79SMasahiro Yamada tarball=${tarball}.gz 336d983feaSJan-Benedict Glaw ;; 346d983feaSJan-Benedict Glaw tarbz2-pkg) 35e4a42c82SDenis Efremov opts="-I ${KBZIP2}" 3677780f79SMasahiro Yamada tarball=${tarball}.bz2 376d983feaSJan-Benedict Glaw ;; 389a17f400SZdenek Kaspar tarxz-pkg) 398dfb61dcSDenis Efremov opts="-I ${XZ}" 4077780f79SMasahiro Yamada tarball=${tarball}.xz 419a17f400SZdenek Kaspar ;; 4288f5e1e6SPaweł Jasiak tarzst-pkg) 4388f5e1e6SPaweł Jasiak opts="-I ${ZSTD}" 4488f5e1e6SPaweł Jasiak tarball=${tarball}.zst 4588f5e1e6SPaweł Jasiak ;; 466d983feaSJan-Benedict Glaw *) 476d983feaSJan-Benedict Glaw echo "Unknown tarball target \"${1}\" requested, please add it to ${0}." >&2 486d983feaSJan-Benedict Glaw exit 1 496d983feaSJan-Benedict Glaw ;; 506d983feaSJan-Benedict Glawesac 516d983feaSJan-Benedict Glaw 526d983feaSJan-Benedict Glaw 536d983feaSJan-Benedict Glaw# 546d983feaSJan-Benedict Glaw# Clean-up and re-create the temporary directory 556d983feaSJan-Benedict Glaw# 566d983feaSJan-Benedict Glawrm -rf -- "${tmpdir}" 576d983feaSJan-Benedict Glawmkdir -p -- "${tmpdir}/boot" 58dd965f1fSMasahiro Yamadadirs=boot 596d983feaSJan-Benedict Glaw 6055a87cd8SDomenico Andreoli 6155a87cd8SDomenico Andreoli# 6255a87cd8SDomenico Andreoli# Try to install dtbs 6355a87cd8SDomenico Andreoli# 6455a87cd8SDomenico Andreoliif grep -q '^CONFIG_OF_EARLY_FLATTREE=y' include/config/auto.conf; then 6555a87cd8SDomenico Andreoli # Only some architectures with OF support have this target 6655a87cd8SDomenico Andreoli if [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then 6755a87cd8SDomenico Andreoli $MAKE ARCH="${ARCH}" -f ${srctree}/Makefile INSTALL_DTBS_PATH="${tmpdir}/boot/dtbs/${KERNELRELEASE}" dtbs_install 6855a87cd8SDomenico Andreoli fi 6955a87cd8SDomenico Andreolifi 7055a87cd8SDomenico Andreoli 7155a87cd8SDomenico Andreoli 726d983feaSJan-Benedict Glaw# 736d983feaSJan-Benedict Glaw# Try to install modules 746d983feaSJan-Benedict Glaw# 756fb7ef5aSMasahiro Yamadaif grep -q '^CONFIG_MODULES=y' include/config/auto.conf; then 76175209ccSMasahiro Yamada make ARCH="${ARCH}" -f ${srctree}/Makefile INSTALL_MOD_PATH="${tmpdir}" modules_install 77dd965f1fSMasahiro Yamada dirs="$dirs lib" 786d983feaSJan-Benedict Glawfi 796d983feaSJan-Benedict Glaw 806d983feaSJan-Benedict Glaw 816d983feaSJan-Benedict Glaw# 826d983feaSJan-Benedict Glaw# Install basic kernel files 836d983feaSJan-Benedict Glaw# 846073aa64SJan-Benedict Glawcp -v -- "${objtree}/System.map" "${tmpdir}/boot/System.map-${KERNELRELEASE}" 85cfd63736SNicolas Porcelcp -v -- "${KCONFIG_CONFIG}" "${tmpdir}/boot/config-${KERNELRELEASE}" 866073aa64SJan-Benedict Glawcp -v -- "${objtree}/vmlinux" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 876d983feaSJan-Benedict Glaw 886d983feaSJan-Benedict Glaw 896d983feaSJan-Benedict Glaw# 906d983feaSJan-Benedict Glaw# Install arch-specific kernel image(s) 916d983feaSJan-Benedict Glaw# 926d983feaSJan-Benedict Glawcase "${ARCH}" in 93bc395addSDaniel De Graaf x86|i386|x86_64) 94bc395addSDaniel De Graaf [ -f "${objtree}/arch/x86/boot/bzImage" ] && cp -v -- "${objtree}/arch/x86/boot/bzImage" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 956d983feaSJan-Benedict Glaw ;; 966d983feaSJan-Benedict Glaw alpha) 976073aa64SJan-Benedict Glaw [ -f "${objtree}/arch/alpha/boot/vmlinux.gz" ] && cp -v -- "${objtree}/arch/alpha/boot/vmlinux.gz" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 986d983feaSJan-Benedict Glaw ;; 9991400ac3SHelge Deller parisc*) 10091400ac3SHelge Deller [ -f "${KBUILD_IMAGE}" ] && cp -v -- "${KBUILD_IMAGE}" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 10191400ac3SHelge Deller [ -f "${objtree}/lifimage" ] && cp -v -- "${objtree}/lifimage" "${tmpdir}/boot/lifimage-${KERNELRELEASE}" 10291400ac3SHelge Deller ;; 1037848ea79SStuart Longland mips) 1047848ea79SStuart Longland if [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.bin" ]; then 1057848ea79SStuart Longland cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.bin" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 1067848ea79SStuart Longland elif [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.ecoff" ]; then 1077848ea79SStuart Longland cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.ecoff" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 1087848ea79SStuart Longland elif [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.srec" ]; then 1097848ea79SStuart Longland cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.srec" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 1107848ea79SStuart Longland elif [ -f "${objtree}/vmlinux.32" ]; then 1117848ea79SStuart Longland cp -v -- "${objtree}/vmlinux.32" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1127848ea79SStuart Longland elif [ -f "${objtree}/vmlinux.64" ]; then 1137848ea79SStuart Longland cp -v -- "${objtree}/vmlinux.64" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1147848ea79SStuart Longland elif [ -f "${objtree}/arch/mips/boot/vmlinux.bin" ]; then 1157848ea79SStuart Longland cp -v -- "${objtree}/arch/mips/boot/vmlinux.bin" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1167848ea79SStuart Longland elif [ -f "${objtree}/arch/mips/boot/vmlinux.ecoff" ]; then 1177848ea79SStuart Longland cp -v -- "${objtree}/arch/mips/boot/vmlinux.ecoff" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1187848ea79SStuart Longland elif [ -f "${objtree}/arch/mips/boot/vmlinux.srec" ]; then 1197848ea79SStuart Longland cp -v -- "${objtree}/arch/mips/boot/vmlinux.srec" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1207848ea79SStuart Longland elif [ -f "${objtree}/vmlinux" ]; then 1217848ea79SStuart Longland cp -v -- "${objtree}/vmlinux" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1227848ea79SStuart Longland fi 1237848ea79SStuart Longland ;; 1240df57d90SOlof Johansson arm64) 125*731c4eacSVeronika Kabatova for i in Image.bz2 Image.gz Image.lz4 Image.lzma Image.lzo vmlinuz.efi ; do 1260df57d90SOlof Johansson if [ -f "${objtree}/arch/arm64/boot/${i}" ] ; then 1270df57d90SOlof Johansson cp -v -- "${objtree}/arch/arm64/boot/${i}" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}" 1280df57d90SOlof Johansson break 1290df57d90SOlof Johansson fi 1300df57d90SOlof Johansson done 1310df57d90SOlof Johansson ;; 1327d0bc44bSCarlos de Paula riscv) 1337d0bc44bSCarlos de Paula for i in Image.bz2 Image.gz Image; do 1347d0bc44bSCarlos de Paula if [ -f "${objtree}/arch/riscv/boot/${i}" ] ; then 1357d0bc44bSCarlos de Paula cp -v -- "${objtree}/arch/riscv/boot/${i}" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}" 1367d0bc44bSCarlos de Paula break 1377d0bc44bSCarlos de Paula fi 1387d0bc44bSCarlos de Paula done 1397d0bc44bSCarlos de Paula ;; 1406d983feaSJan-Benedict Glaw *) 1416073aa64SJan-Benedict Glaw [ -f "${KBUILD_IMAGE}" ] && cp -v -- "${KBUILD_IMAGE}" "${tmpdir}/boot/vmlinux-kbuild-${KERNELRELEASE}" 1426d983feaSJan-Benedict Glaw echo "" >&2 1436d983feaSJan-Benedict Glaw echo '** ** ** WARNING ** ** **' >&2 1446d983feaSJan-Benedict Glaw echo "" >&2 14525985edcSLucas De Marchi echo "Your architecture did not define any architecture-dependent files" >&2 1466d983feaSJan-Benedict Glaw echo "to be placed into the tarball. Please add those to ${0} ..." >&2 1476d983feaSJan-Benedict Glaw echo "" >&2 1486d983feaSJan-Benedict Glaw sleep 5 1496d983feaSJan-Benedict Glaw ;; 1506d983feaSJan-Benedict Glawesac 1516d983feaSJan-Benedict Glaw 152af7db99aSMatteo Croceif [ "${1}" = dir-pkg ]; then 153af7db99aSMatteo Croce echo "Kernel tree successfully created in $tmpdir" 154af7db99aSMatteo Croce exit 0 155af7db99aSMatteo Crocefi 1566d983feaSJan-Benedict Glaw 1576d983feaSJan-Benedict Glaw# 1586d983feaSJan-Benedict Glaw# Create the tarball 1596d983feaSJan-Benedict Glaw# 16091d16185SMichal Marekif tar --owner=root --group=root --help >/dev/null 2>&1; then 16177780f79SMasahiro Yamada opts="$opts --owner=root --group=root" 16291d16185SMichal Marekfi 1636d983feaSJan-Benedict Glaw 16477780f79SMasahiro Yamadatar cf $tarball -C $tmpdir $opts $dirs 16577780f79SMasahiro Yamada 16677780f79SMasahiro Yamadaecho "Tarball successfully created in $tarball" 1676d983feaSJan-Benedict Glaw 1686d983feaSJan-Benedict Glawexit 0 169