blob: 9680e2711a595037dd65b6966fdc7b7a0d9ba46b [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
Michael S. Tsirkin1ff0b552015-02-16 22:35:25 +010031cp_virtio() {
32 from=$1
33 to=$2
34 virtio=$(find "$from" -name '*virtio*h')
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' \
42 -e 'linux/if_ether' \
43 > /dev/null
44 then
45 echo "Unexpected #include in input file $f".
46 exit 2
47 fi
48
49 header=$(basename "$f");
50 sed -e 's/__u\([0-9][0-9]*\)/uint\1_t/g' \
51 -e 's/__le\([0-9][0-9]*\)/uint\1_t/g' \
52 -e 's/__be\([0-9][0-9]*\)/uint\1_t/g' \
53 -e 's/<linux\/\([^>]*\)>/"standard-headers\/linux\/\1"/' \
54 -e 's/__bitwise__//' \
55 -e 's/__attribute__((packed))/QEMU_PACKED/' \
56 "$f" > "$to/$header";
57 done
58 fi
59}
60
Peter Maydell28796362012-07-18 11:11:09 +010061# This will pick up non-directories too (eg "Kconfig") but we will
62# ignore them in the next loop.
63ARCHLIST=$(cd "$linux/arch" && echo *)
64
65for arch in $ARCHLIST; do
66 # Discard anything which isn't a KVM-supporting architecture
Peter Maydellb55f5462012-10-22 12:54:39 +010067 if ! [ -e "$linux/arch/$arch/include/asm/kvm.h" ] &&
68 ! [ -e "$linux/arch/$arch/include/uapi/asm/kvm.h" ] ; then
Peter Maydell28796362012-07-18 11:11:09 +010069 continue
70 fi
71
72 # Blacklist architectures which have KVM headers but are actually dead
73 if [ "$arch" = "ia64" ]; then
74 continue
75 fi
76
Jan Kiszka87fdd472011-06-08 18:22:17 +020077 make -C "$linux" INSTALL_HDR_PATH="$tmpdir" SRCARCH=$arch headers_install
78
79 rm -rf "$output/linux-headers/asm-$arch"
80 mkdir -p "$output/linux-headers/asm-$arch"
81 for header in kvm.h kvm_para.h; do
82 cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
83 done
84 if [ $arch = x86 ]; then
85 cp "$tmpdir/include/asm/hyperv.h" "$output/linux-headers/asm-x86"
86 fi
Bharat Bhushand56af002012-12-18 01:13:58 +000087 if [ $arch = powerpc ]; then
88 cp "$tmpdir/include/asm/epapr_hcalls.h" "$output/linux-headers/asm-powerpc/"
89 fi
Michael S. Tsirkin44fb1dd2015-02-16 22:36:48 +010090
91 cp_virtio "$tmpdir/include/asm" "$output/include/standard-headers/asm-$arch"
Jan Kiszka87fdd472011-06-08 18:22:17 +020092done
93
94rm -rf "$output/linux-headers/linux"
95mkdir -p "$output/linux-headers/linux"
Michael S. Tsirkin05e492b2015-02-16 22:36:32 +010096for header in kvm.h kvm_para.h vfio.h vhost.h \
Alexander Graf2872e192014-06-04 12:03:03 +020097 psci.h; do
Jan Kiszka87fdd472011-06-08 18:22:17 +020098 cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux"
99done
Peter Maydell256d0462012-07-25 16:29:07 +0100100rm -rf "$output/linux-headers/asm-generic"
101mkdir -p "$output/linux-headers/asm-generic"
102for header in kvm_para.h; do
103 cp "$tmpdir/include/asm-generic/$header" "$output/linux-headers/asm-generic"
104done
Jan Kiszka87fdd472011-06-08 18:22:17 +0200105if [ -L "$linux/source" ]; then
106 cp "$linux/source/COPYING" "$output/linux-headers"
107else
108 cp "$linux/COPYING" "$output/linux-headers"
109fi
110
Michael S. Tsirkin05e492b2015-02-16 22:36:32 +0100111cat <<EOF >$output/linux-headers/linux/virtio_config.h
112#include "standard-headers/linux/virtio_config.h"
113EOF
114cat <<EOF >$output/linux-headers/linux/virtio_ring.h
115#include "standard-headers/linux/virtio_ring.h"
116EOF
Michael S. Tsirkin1ff0b552015-02-16 22:35:25 +0100117
118cp_virtio "$tmpdir/include/linux/" "$output/include/standard-headers/linux"
119
120cat <<EOF >$output/include/standard-headers/linux/types.h
121#include <stdint.h>
122#include "qemu/compiler.h"
123EOF
124cat <<EOF >$output/include/standard-headers/linux/if_ether.h
125#define ETH_ALEN 6
126EOF
127
Jan Kiszka87fdd472011-06-08 18:22:17 +0200128rm -rf "$tmpdir"