187fdd476SJan Kiszka#!/bin/sh -e 287fdd476SJan Kiszka# 387fdd476SJan Kiszka# Update Linux kernel headers QEMU requires from a specified kernel tree. 487fdd476SJan Kiszka# 587fdd476SJan Kiszka# Copyright (C) 2011 Siemens AG 687fdd476SJan Kiszka# 787fdd476SJan Kiszka# Authors: 887fdd476SJan Kiszka# Jan Kiszka <jan.kiszka@siemens.com> 987fdd476SJan Kiszka# 1087fdd476SJan Kiszka# This work is licensed under the terms of the GNU GPL version 2. 1187fdd476SJan Kiszka# See the COPYING file in the top-level directory. 1287fdd476SJan Kiszka 1387fdd476SJan Kiszkatmpdir=`mktemp -d` 1487fdd476SJan Kiszkalinux="$1" 1587fdd476SJan Kiszkaoutput="$2" 1687fdd476SJan Kiszka 1787fdd476SJan Kiszkaif [ -z "$linux" ] || ! [ -d "$linux" ]; then 1887fdd476SJan Kiszka cat << EOF 1987fdd476SJan Kiszkausage: update-kernel-headers.sh LINUX_PATH [OUTPUT_PATH] 2087fdd476SJan Kiszka 2187fdd476SJan KiszkaLINUX_PATH Linux kernel directory to obtain the headers from 2287fdd476SJan KiszkaOUTPUT_PATH output directory, usually the qemu source tree (default: $PWD) 2387fdd476SJan KiszkaEOF 2487fdd476SJan Kiszka exit 1 2587fdd476SJan Kiszkafi 2687fdd476SJan Kiszka 2787fdd476SJan Kiszkaif [ -z "$output" ]; then 2887fdd476SJan Kiszka output="$PWD" 2987fdd476SJan Kiszkafi 3087fdd476SJan Kiszka 312879636dSPeter Maydell# This will pick up non-directories too (eg "Kconfig") but we will 322879636dSPeter Maydell# ignore them in the next loop. 332879636dSPeter MaydellARCHLIST=$(cd "$linux/arch" && echo *) 342879636dSPeter Maydell 352879636dSPeter Maydellfor arch in $ARCHLIST; do 362879636dSPeter Maydell # Discard anything which isn't a KVM-supporting architecture 37b55f546eSPeter Maydell if ! [ -e "$linux/arch/$arch/include/asm/kvm.h" ] && 38b55f546eSPeter Maydell ! [ -e "$linux/arch/$arch/include/uapi/asm/kvm.h" ] ; then 392879636dSPeter Maydell continue 402879636dSPeter Maydell fi 412879636dSPeter Maydell 422879636dSPeter Maydell # Blacklist architectures which have KVM headers but are actually dead 432879636dSPeter Maydell if [ "$arch" = "ia64" ]; then 442879636dSPeter Maydell continue 452879636dSPeter Maydell fi 462879636dSPeter Maydell 4787fdd476SJan Kiszka make -C "$linux" INSTALL_HDR_PATH="$tmpdir" SRCARCH=$arch headers_install 4887fdd476SJan Kiszka 4987fdd476SJan Kiszka rm -rf "$output/linux-headers/asm-$arch" 5087fdd476SJan Kiszka mkdir -p "$output/linux-headers/asm-$arch" 5187fdd476SJan Kiszka for header in kvm.h kvm_para.h; do 5287fdd476SJan Kiszka cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch" 5387fdd476SJan Kiszka done 5487fdd476SJan Kiszka if [ $arch = x86 ]; then 5587fdd476SJan Kiszka cp "$tmpdir/include/asm/hyperv.h" "$output/linux-headers/asm-x86" 5687fdd476SJan Kiszka fi 57*d56af005SBharat Bhushan if [ $arch = powerpc ]; then 58*d56af005SBharat Bhushan cp "$tmpdir/include/asm/epapr_hcalls.h" "$output/linux-headers/asm-powerpc/" 59*d56af005SBharat Bhushan fi 6087fdd476SJan Kiszkadone 6187fdd476SJan Kiszka 6287fdd476SJan Kiszkarm -rf "$output/linux-headers/linux" 6387fdd476SJan Kiszkamkdir -p "$output/linux-headers/linux" 64df8c1b02SAlex Williamsonfor header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h; do 6587fdd476SJan Kiszka cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux" 6687fdd476SJan Kiszkadone 67256d046cSPeter Maydellrm -rf "$output/linux-headers/asm-generic" 68256d046cSPeter Maydellmkdir -p "$output/linux-headers/asm-generic" 69256d046cSPeter Maydellfor header in kvm_para.h; do 70256d046cSPeter Maydell cp "$tmpdir/include/asm-generic/$header" "$output/linux-headers/asm-generic" 71256d046cSPeter Maydelldone 7287fdd476SJan Kiszkaif [ -L "$linux/source" ]; then 7387fdd476SJan Kiszka cp "$linux/source/COPYING" "$output/linux-headers" 7487fdd476SJan Kiszkaelse 7587fdd476SJan Kiszka cp "$linux/COPYING" "$output/linux-headers" 7687fdd476SJan Kiszkafi 7787fdd476SJan Kiszka 7887fdd476SJan Kiszkarm -rf "$tmpdir" 79