blob: c8e026d37e31f16cd116d5f1bceb09f5656ba610 [file] [log] [blame]
Jan Kiszka87fdd472011-06-08 18:22:17 +02001#!/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
13tmpdir=`mktemp -d`
14linux="$1"
15output="$2"
16
17if [ -z "$linux" ] || ! [ -d "$linux" ]; then
18 cat << EOF
19usage: update-kernel-headers.sh LINUX_PATH [OUTPUT_PATH]
20
21LINUX_PATH Linux kernel directory to obtain the headers from
22OUTPUT_PATH output directory, usually the qemu source tree (default: $PWD)
23EOF
24 exit 1
25fi
26
27if [ -z "$output" ]; then
28 output="$PWD"
29fi
30
Peter Maydell28796362012-07-18 11:11:09 +010031# This will pick up non-directories too (eg "Kconfig") but we will
32# ignore them in the next loop.
33ARCHLIST=$(cd "$linux/arch" && echo *)
34
35for arch in $ARCHLIST; do
36 # Discard anything which isn't a KVM-supporting architecture
Peter Maydellb55f5462012-10-22 12:54:39 +010037 if ! [ -e "$linux/arch/$arch/include/asm/kvm.h" ] &&
38 ! [ -e "$linux/arch/$arch/include/uapi/asm/kvm.h" ] ; then
Peter Maydell28796362012-07-18 11:11:09 +010039 continue
40 fi
41
42 # Blacklist architectures which have KVM headers but are actually dead
43 if [ "$arch" = "ia64" ]; then
44 continue
45 fi
46
Jan Kiszka87fdd472011-06-08 18:22:17 +020047 make -C "$linux" INSTALL_HDR_PATH="$tmpdir" SRCARCH=$arch headers_install
48
49 rm -rf "$output/linux-headers/asm-$arch"
50 mkdir -p "$output/linux-headers/asm-$arch"
51 for header in kvm.h kvm_para.h; do
52 cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
53 done
54 if [ $arch = x86 ]; then
55 cp "$tmpdir/include/asm/hyperv.h" "$output/linux-headers/asm-x86"
56 fi
Bharat Bhushand56af002012-12-18 01:13:58 +000057 if [ $arch = powerpc ]; then
58 cp "$tmpdir/include/asm/epapr_hcalls.h" "$output/linux-headers/asm-powerpc/"
59 fi
Jan Kiszka87fdd472011-06-08 18:22:17 +020060done
61
62rm -rf "$output/linux-headers/linux"
63mkdir -p "$output/linux-headers/linux"
Alexander Graf2872e192014-06-04 12:03:03 +020064for header in kvm.h kvm_para.h vfio.h vhost.h virtio_config.h virtio_ring.h \
65 psci.h; do
Jan Kiszka87fdd472011-06-08 18:22:17 +020066 cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux"
67done
Peter Maydell256d0462012-07-25 16:29:07 +010068rm -rf "$output/linux-headers/asm-generic"
69mkdir -p "$output/linux-headers/asm-generic"
70for header in kvm_para.h; do
71 cp "$tmpdir/include/asm-generic/$header" "$output/linux-headers/asm-generic"
72done
Jan Kiszka87fdd472011-06-08 18:22:17 +020073if [ -L "$linux/source" ]; then
74 cp "$linux/source/COPYING" "$output/linux-headers"
75else
76 cp "$linux/COPYING" "$output/linux-headers"
77fi
78
79rm -rf "$tmpdir"