2
0

update-linux-headers.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/sh -e
  2. #
  3. # Update Linux kernel headers QEMU requires from a specified kernel tree.
  4. #
  5. # Copyright (C) 2011 Siemens AG
  6. #
  7. # Authors:
  8. # Jan Kiszka <jan.kiszka@siemens.com>
  9. #
  10. # This work is licensed under the terms of the GNU GPL version 2.
  11. # See the COPYING file in the top-level directory.
  12. tmpdir=`mktemp -d`
  13. linux="$1"
  14. output="$2"
  15. if [ -z "$linux" ] || ! [ -d "$linux" ]; then
  16. cat << EOF
  17. usage: update-kernel-headers.sh LINUX_PATH [OUTPUT_PATH]
  18. LINUX_PATH Linux kernel directory to obtain the headers from
  19. OUTPUT_PATH output directory, usually the qemu source tree (default: $PWD)
  20. EOF
  21. exit 1
  22. fi
  23. if [ -z "$output" ]; then
  24. output="$PWD"
  25. fi
  26. # This will pick up non-directories too (eg "Kconfig") but we will
  27. # ignore them in the next loop.
  28. ARCHLIST=$(cd "$linux/arch" && echo *)
  29. for arch in $ARCHLIST; do
  30. # Discard anything which isn't a KVM-supporting architecture
  31. if ! [ -e "$linux/arch/$arch/include/asm/kvm.h" ] &&
  32. ! [ -e "$linux/arch/$arch/include/uapi/asm/kvm.h" ] ; then
  33. continue
  34. fi
  35. # Blacklist architectures which have KVM headers but are actually dead
  36. if [ "$arch" = "ia64" ]; then
  37. continue
  38. fi
  39. make -C "$linux" INSTALL_HDR_PATH="$tmpdir" SRCARCH=$arch headers_install
  40. rm -rf "$output/linux-headers/asm-$arch"
  41. mkdir -p "$output/linux-headers/asm-$arch"
  42. for header in kvm.h kvm_para.h; do
  43. cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
  44. done
  45. if [ $arch = x86 ]; then
  46. cp "$tmpdir/include/asm/hyperv.h" "$output/linux-headers/asm-x86"
  47. fi
  48. if [ $arch = powerpc ]; then
  49. cp "$tmpdir/include/asm/epapr_hcalls.h" "$output/linux-headers/asm-powerpc/"
  50. fi
  51. done
  52. rm -rf "$output/linux-headers/linux"
  53. mkdir -p "$output/linux-headers/linux"
  54. for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h \
  55. psci.h; do
  56. cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux"
  57. done
  58. rm -rf "$output/linux-headers/asm-generic"
  59. mkdir -p "$output/linux-headers/asm-generic"
  60. for header in kvm_para.h; do
  61. cp "$tmpdir/include/asm-generic/$header" "$output/linux-headers/asm-generic"
  62. done
  63. if [ -L "$linux/source" ]; then
  64. cp "$linux/source/COPYING" "$output/linux-headers"
  65. else
  66. cp "$linux/COPYING" "$output/linux-headers"
  67. fi
  68. rm -rf "$tmpdir"