buildtar 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # buildtar 0.0.5
  5. #
  6. # (C) 2004-2006 by Jan-Benedict Glaw <[email protected]>
  7. #
  8. # This script is used to compile a tarball from the currently
  9. # prepared kernel. Based upon the builddeb script from
  10. # Wichert Akkerman <[email protected]>.
  11. #
  12. set -e
  13. #
  14. # Some variables and settings used throughout the script
  15. #
  16. tmpdir="${objtree}/tar-install"
  17. tarball="${objtree}/linux-${KERNELRELEASE}-${ARCH}.tar"
  18. #
  19. # Figure out how to compress, if requested at all
  20. #
  21. case "${1}" in
  22. dir-pkg|tar-pkg)
  23. opts=
  24. ;;
  25. targz-pkg)
  26. opts="-I ${KGZIP}"
  27. tarball=${tarball}.gz
  28. ;;
  29. tarbz2-pkg)
  30. opts="-I ${KBZIP2}"
  31. tarball=${tarball}.bz2
  32. ;;
  33. tarxz-pkg)
  34. opts="-I ${XZ}"
  35. tarball=${tarball}.xz
  36. ;;
  37. tarzst-pkg)
  38. opts="-I ${ZSTD}"
  39. tarball=${tarball}.zst
  40. ;;
  41. *)
  42. echo "Unknown tarball target \"${1}\" requested, please add it to ${0}." >&2
  43. exit 1
  44. ;;
  45. esac
  46. #
  47. # Clean-up and re-create the temporary directory
  48. #
  49. rm -rf -- "${tmpdir}"
  50. mkdir -p -- "${tmpdir}/boot"
  51. dirs=boot
  52. #
  53. # Try to install dtbs
  54. #
  55. if grep -q '^CONFIG_OF_EARLY_FLATTREE=y' include/config/auto.conf; then
  56. # Only some architectures with OF support have this target
  57. if [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then
  58. $MAKE ARCH="${ARCH}" -f ${srctree}/Makefile INSTALL_DTBS_PATH="${tmpdir}/boot/dtbs/${KERNELRELEASE}" dtbs_install
  59. fi
  60. fi
  61. #
  62. # Try to install modules
  63. #
  64. if grep -q '^CONFIG_MODULES=y' include/config/auto.conf; then
  65. make ARCH="${ARCH}" -f ${srctree}/Makefile INSTALL_MOD_PATH="${tmpdir}" modules_install
  66. dirs="$dirs lib"
  67. fi
  68. #
  69. # Install basic kernel files
  70. #
  71. cp -v -- "${objtree}/System.map" "${tmpdir}/boot/System.map-${KERNELRELEASE}"
  72. cp -v -- "${KCONFIG_CONFIG}" "${tmpdir}/boot/config-${KERNELRELEASE}"
  73. cp -v -- "${objtree}/vmlinux" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
  74. #
  75. # Install arch-specific kernel image(s)
  76. #
  77. case "${ARCH}" in
  78. x86|i386|x86_64)
  79. [ -f "${objtree}/arch/x86/boot/bzImage" ] && cp -v -- "${objtree}/arch/x86/boot/bzImage" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
  80. ;;
  81. alpha)
  82. [ -f "${objtree}/arch/alpha/boot/vmlinux.gz" ] && cp -v -- "${objtree}/arch/alpha/boot/vmlinux.gz" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
  83. ;;
  84. parisc*)
  85. [ -f "${KBUILD_IMAGE}" ] && cp -v -- "${KBUILD_IMAGE}" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
  86. [ -f "${objtree}/lifimage" ] && cp -v -- "${objtree}/lifimage" "${tmpdir}/boot/lifimage-${KERNELRELEASE}"
  87. ;;
  88. mips)
  89. if [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.bin" ]; then
  90. cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.bin" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
  91. elif [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.ecoff" ]; then
  92. cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.ecoff" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
  93. elif [ -f "${objtree}/arch/mips/boot/compressed/vmlinux.srec" ]; then
  94. cp -v -- "${objtree}/arch/mips/boot/compressed/vmlinux.srec" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
  95. elif [ -f "${objtree}/vmlinux.32" ]; then
  96. cp -v -- "${objtree}/vmlinux.32" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
  97. elif [ -f "${objtree}/vmlinux.64" ]; then
  98. cp -v -- "${objtree}/vmlinux.64" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
  99. elif [ -f "${objtree}/arch/mips/boot/vmlinux.bin" ]; then
  100. cp -v -- "${objtree}/arch/mips/boot/vmlinux.bin" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
  101. elif [ -f "${objtree}/arch/mips/boot/vmlinux.ecoff" ]; then
  102. cp -v -- "${objtree}/arch/mips/boot/vmlinux.ecoff" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
  103. elif [ -f "${objtree}/arch/mips/boot/vmlinux.srec" ]; then
  104. cp -v -- "${objtree}/arch/mips/boot/vmlinux.srec" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
  105. elif [ -f "${objtree}/vmlinux" ]; then
  106. cp -v -- "${objtree}/vmlinux" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
  107. fi
  108. ;;
  109. arm64)
  110. for i in Image.bz2 Image.gz Image.lz4 Image.lzma Image.lzo ; do
  111. if [ -f "${objtree}/arch/arm64/boot/${i}" ] ; then
  112. cp -v -- "${objtree}/arch/arm64/boot/${i}" "${tmpdir}/boot/vmlinuz-${KERNELRELEASE}"
  113. break
  114. fi
  115. done
  116. ;;
  117. riscv)
  118. for i in Image.bz2 Image.gz Image; do
  119. if [ -f "${objtree}/arch/riscv/boot/${i}" ] ; then
  120. cp -v -- "${objtree}/arch/riscv/boot/${i}" "${tmpdir}/boot/vmlinux-${KERNELRELEASE}"
  121. break
  122. fi
  123. done
  124. ;;
  125. *)
  126. [ -f "${KBUILD_IMAGE}" ] && cp -v -- "${KBUILD_IMAGE}" "${tmpdir}/boot/vmlinux-kbuild-${KERNELRELEASE}"
  127. echo "" >&2
  128. echo '** ** ** WARNING ** ** **' >&2
  129. echo "" >&2
  130. echo "Your architecture did not define any architecture-dependent files" >&2
  131. echo "to be placed into the tarball. Please add those to ${0} ..." >&2
  132. echo "" >&2
  133. sleep 5
  134. ;;
  135. esac
  136. if [ "${1}" = dir-pkg ]; then
  137. echo "Kernel tree successfully created in $tmpdir"
  138. exit 0
  139. fi
  140. #
  141. # Create the tarball
  142. #
  143. if tar --owner=root --group=root --help >/dev/null 2>&1; then
  144. opts="$opts --owner=root --group=root"
  145. fi
  146. tar cf $tarball -C $tmpdir $opts $dirs
  147. echo "Tarball successfully created in $tarball"
  148. exit 0