xref: /kvmtool/util/update_headers.sh (revision 393e2187cf68a14e107f9fa75b1da4f5632b379b)
145b624beSAndre Przywara#!/bin/sh
245b624beSAndre Przywara
345b624beSAndre Przywara########################################################################
445b624beSAndre Przywara# Updates the kvmtool tree with up-to-date public header files from
545b624beSAndre Przywara# a Linux source tree.
645b624beSAndre Przywara# If no directory is given on the command line, it will try to find one
745b624beSAndre Przywara# using the lib/modules/`uname -r`/source link.
845b624beSAndre Przywara########################################################################
945b624beSAndre Przywara
109f520be5SDave Martinset -ue
119f520be5SDave Martin
12*393e2187SAndre PrzywaraVIRTIO_LIST="virtio_9p.h virtio_balloon.h virtio_blk.h virtio_config.h \
13*393e2187SAndre Przywara	     virtio_console.h virtio_ids.h virtio_mmio.h virtio_net.h \
14*393e2187SAndre Przywara	     virtio_pci.h virtio_ring.h virtio_rng.h virtio_scsi.h \
15*393e2187SAndre Przywara	     virtio_vsock.h"
16*393e2187SAndre Przywara
1745b624beSAndre Przywaraif [ "$#" -ge 1 ]
1845b624beSAndre Przywarathen
1945b624beSAndre Przywara	LINUX_ROOT="$1"
2045b624beSAndre Przywaraelse
213baf13c7SDave Martin	LINUX_ROOT="/lib/modules/$(uname -r)/source"
2245b624beSAndre Przywarafi
2345b624beSAndre Przywara
243baf13c7SDave Martinif [ ! -d "$LINUX_ROOT/include/uapi/linux" ]
2545b624beSAndre Przywarathen
2645b624beSAndre Przywara	echo "$LINUX_ROOT does not seem to be valid Linux source tree."
2745b624beSAndre Przywara	echo "usage: $0 [path-to-Linux-source-tree]"
2845b624beSAndre Przywara	exit 1
2945b624beSAndre Przywarafi
3045b624beSAndre Przywara
313baf13c7SDave Martincp -- "$LINUX_ROOT/include/uapi/linux/kvm.h" include/linux
3245b624beSAndre Przywara
33*393e2187SAndre Przywarafor header in $VIRTIO_LIST
34*393e2187SAndre Przywarado
35*393e2187SAndre Przywara	cp -- "$LINUX_ROOT/include/uapi/linux/$header" include/linux
36*393e2187SAndre Przywaradone
37*393e2187SAndre Przywara
38292435bcSDave Martinunset KVMTOOL_PATH
39292435bcSDave Martin
40292435bcSDave Martincopy_optional_arch () {
41292435bcSDave Martin	local src="$LINUX_ROOT/arch/$arch/include/uapi/$1"
42292435bcSDave Martin
43292435bcSDave Martin	if [ -r "$src" ]
44292435bcSDave Martin	then
45292435bcSDave Martin		cp -- "$src" "$KVMTOOL_PATH/include/asm/"
46292435bcSDave Martin	fi
47292435bcSDave Martin}
48292435bcSDave Martin
492e996783SAnup Patelfor arch in arm64 mips powerpc riscv x86
5045b624beSAndre Przywarado
5145b624beSAndre Przywara	case "$arch" in
52292435bcSDave Martin		arm64)	KVMTOOL_PATH=arm/aarch64
53292435bcSDave Martin			copy_optional_arch asm/sve_context.h ;;
5445b624beSAndre Przywara		*) KVMTOOL_PATH=$arch ;;
5545b624beSAndre Przywara	esac
563baf13c7SDave Martin	cp -- "$LINUX_ROOT/arch/$arch/include/uapi/asm/kvm.h" \
573baf13c7SDave Martin		"$KVMTOOL_PATH/include/asm"
5845b624beSAndre Przywaradone
59