]>
Commit | Line | Data |
---|---|---|
87fdd476 JK |
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 | ||
13 | tmpdir=`mktemp -d` | |
14 | linux="$1" | |
15 | output="$2" | |
16 | ||
17 | if [ -z "$linux" ] || ! [ -d "$linux" ]; then | |
18 | cat << EOF | |
19 | usage: update-kernel-headers.sh LINUX_PATH [OUTPUT_PATH] | |
20 | ||
21 | LINUX_PATH Linux kernel directory to obtain the headers from | |
22 | OUTPUT_PATH output directory, usually the qemu source tree (default: $PWD) | |
23 | EOF | |
24 | exit 1 | |
25 | fi | |
26 | ||
27 | if [ -z "$output" ]; then | |
28 | output="$PWD" | |
29 | fi | |
30 | ||
1ff0b555 MT |
31 | cp_virtio() { |
32 | from=$1 | |
33 | to=$2 | |
412a8245 | 34 | virtio=$(find "$from" -name '*virtio*h' -o -name "input.h" -o -name "pci_regs.h") |
1ff0b555 MT |
35 | if [ "$virtio" ]; then |
36 | rm -rf "$to" | |
37 | mkdir -p "$to" | |
38 | for f in $virtio; do | |
39 | if | |
40 | grep '#include' "$f" | grep -v -e 'linux/virtio' \ | |
41 | -e 'linux/types' \ | |
120758fb | 42 | -e 'stdint' \ |
1ff0b555 | 43 | -e 'linux/if_ether' \ |
2fe7c318 | 44 | -e 'sys/' \ |
1ff0b555 MT |
45 | > /dev/null |
46 | then | |
47 | echo "Unexpected #include in input file $f". | |
48 | exit 2 | |
49 | fi | |
50 | ||
51 | header=$(basename "$f"); | |
52 | sed -e 's/__u\([0-9][0-9]*\)/uint\1_t/g' \ | |
2fe7c318 | 53 | -e 's/__s\([0-9][0-9]*\)/int\1_t/g' \ |
1ff0b555 MT |
54 | -e 's/__le\([0-9][0-9]*\)/uint\1_t/g' \ |
55 | -e 's/__be\([0-9][0-9]*\)/uint\1_t/g' \ | |
56 | -e 's/<linux\/\([^>]*\)>/"standard-headers\/linux\/\1"/' \ | |
57 | -e 's/__bitwise__//' \ | |
58 | -e 's/__attribute__((packed))/QEMU_PACKED/' \ | |
c16758cb | 59 | -e 's/__inline__/inline/' \ |
e2f6bac3 | 60 | -e '/sys\/ioctl.h/d' \ |
1ff0b555 MT |
61 | "$f" > "$to/$header"; |
62 | done | |
63 | fi | |
64 | } | |
65 | ||
2879636d PM |
66 | # This will pick up non-directories too (eg "Kconfig") but we will |
67 | # ignore them in the next loop. | |
68 | ARCHLIST=$(cd "$linux/arch" && echo *) | |
69 | ||
70 | for arch in $ARCHLIST; do | |
71 | # Discard anything which isn't a KVM-supporting architecture | |
b55f546e PM |
72 | if ! [ -e "$linux/arch/$arch/include/asm/kvm.h" ] && |
73 | ! [ -e "$linux/arch/$arch/include/uapi/asm/kvm.h" ] ; then | |
2879636d PM |
74 | continue |
75 | fi | |
76 | ||
77 | # Blacklist architectures which have KVM headers but are actually dead | |
78 | if [ "$arch" = "ia64" ]; then | |
79 | continue | |
80 | fi | |
81 | ||
87fdd476 JK |
82 | make -C "$linux" INSTALL_HDR_PATH="$tmpdir" SRCARCH=$arch headers_install |
83 | ||
84 | rm -rf "$output/linux-headers/asm-$arch" | |
85 | mkdir -p "$output/linux-headers/asm-$arch" | |
86 | for header in kvm.h kvm_para.h; do | |
87 | cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch" | |
88 | done | |
89 | if [ $arch = x86 ]; then | |
90 | cp "$tmpdir/include/asm/hyperv.h" "$output/linux-headers/asm-x86" | |
91 | fi | |
d56af005 BB |
92 | if [ $arch = powerpc ]; then |
93 | cp "$tmpdir/include/asm/epapr_hcalls.h" "$output/linux-headers/asm-powerpc/" | |
94 | fi | |
44fb1dd4 MT |
95 | |
96 | cp_virtio "$tmpdir/include/asm" "$output/include/standard-headers/asm-$arch" | |
87fdd476 JK |
97 | done |
98 | ||
99 | rm -rf "$output/linux-headers/linux" | |
100 | mkdir -p "$output/linux-headers/linux" | |
05e492b0 | 101 | for header in kvm.h kvm_para.h vfio.h vhost.h \ |
2872e192 | 102 | psci.h; do |
87fdd476 JK |
103 | cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux" |
104 | done | |
256d046c PM |
105 | rm -rf "$output/linux-headers/asm-generic" |
106 | mkdir -p "$output/linux-headers/asm-generic" | |
107 | for header in kvm_para.h; do | |
108 | cp "$tmpdir/include/asm-generic/$header" "$output/linux-headers/asm-generic" | |
109 | done | |
87fdd476 JK |
110 | if [ -L "$linux/source" ]; then |
111 | cp "$linux/source/COPYING" "$output/linux-headers" | |
112 | else | |
113 | cp "$linux/COPYING" "$output/linux-headers" | |
114 | fi | |
115 | ||
05e492b0 MT |
116 | cat <<EOF >$output/linux-headers/linux/virtio_config.h |
117 | #include "standard-headers/linux/virtio_config.h" | |
118 | EOF | |
119 | cat <<EOF >$output/linux-headers/linux/virtio_ring.h | |
120 | #include "standard-headers/linux/virtio_ring.h" | |
121 | EOF | |
1ff0b555 MT |
122 | |
123 | cp_virtio "$tmpdir/include/linux/" "$output/include/standard-headers/linux" | |
124 | ||
125 | cat <<EOF >$output/include/standard-headers/linux/types.h | |
126 | #include <stdint.h> | |
127 | #include "qemu/compiler.h" | |
128 | EOF | |
129 | cat <<EOF >$output/include/standard-headers/linux/if_ether.h | |
130 | #define ETH_ALEN 6 | |
131 | EOF | |
132 | ||
87fdd476 | 133 | rm -rf "$tmpdir" |