# # Copyright (C) 2016 Yousong Zhou # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. # define KernelPackage/irqbypass SUBMENU:=Virtualization TITLE:=IRQ offload/bypass manager KCONFIG:=CONFIG_IRQ_BYPASS_MANAGER HIDDEN:=1 FILES:= $(LINUX_DIR)/virt/lib/irqbypass.ko AUTOLOAD:=$(call AutoProbe,irqbypass.ko) endef $(eval $(call KernelPackage,irqbypass)) define KernelPackage/kvm-x86 SUBMENU:=Virtualization TITLE:=Kernel-based Virtual Machine (KVM) support DEPENDS:=@TARGET_x86_generic||TARGET_x86_64 +kmod-irqbypass KCONFIG:=\ CONFIG_KVM \ CONFIG_KVM_MMU_AUDIT=n \ CONFIG_VIRTUALIZATION=y FILES:= $(LINUX_DIR)/arch/$(LINUX_KARCH)/kvm/kvm.ko AUTOLOAD:=$(call AutoProbe,kvm.ko) endef define KernelPackage/kvm-x86/description Support hosting fully virtualized guest machines using hardware virtualization extensions. You will need a fairly recent processor equipped with virtualization extensions. You will also need to select one or more of the processor modules. This module provides access to the hardware capabilities through a character device node named /dev/kvm. endef $(eval $(call KernelPackage,kvm-x86)) define KernelPackage/kvm-intel SUBMENU:=Virtualization TITLE:=KVM for Intel processors support DEPENDS:=+kmod-kvm-x86 KCONFIG:=CONFIG_KVM_INTEL FILES:= $(LINUX_DIR)/arch/$(LINUX_KARCH)/kvm/kvm-intel.ko AUTOLOAD:=$(call AutoProbe,kvm-intel.ko) endef define KernelPackage/kvm-intel/description Provides support for KVM on Intel processors equipped with the VT extensions. endef $(eval $(call KernelPackage,kvm-intel)) define KernelPackage/kvm-amd SUBMENU:=Virtualization TITLE:=KVM for AMD processors support DEPENDS:=+kmod-kvm-x86 KCONFIG:=CONFIG_KVM_AMD FILES:= $(LINUX_DIR)/arch/$(LINUX_KARCH)/kvm/kvm-amd.ko AUTOLOAD:=$(call AutoProbe,kvm-amd.ko) endef define KernelPackage/kvm-amd/description Provides support for KVM on AMD processors equipped with the AMD-V (SVM) extensions. endef $(eval $(call KernelPackage,kvm-amd)) define KernelPackage/vfio SUBMENU:=Virtualization TITLE:=VFIO Non-Privileged userspace driver framework DEPENDS:=@TARGET_x86_64||TARGET_armsr_armv8 KCONFIG:= \ CONFIG_VFIO \ CONFIG_VFIO_NOIOMMU=n \ CONFIG_VFIO_MDEV=n FILES:= \ $(LINUX_DIR)/drivers/vfio/vfio.ko \ $(LINUX_DIR)/drivers/vfio/vfio_virqfd.ko \ $(LINUX_DIR)/drivers/vfio/vfio_iommu_type1.ko AUTOLOAD:=$(call AutoProbe,vfio vfio_iommu_type1 vfio_virqfd) endef define KernelPackage/vfio/description VFIO provides a framework for secure userspace device drivers. endef $(eval $(call KernelPackage,vfio)) define KernelPackage/vfio-pci SUBMENU:=Virtualization TITLE:=Generic VFIO support for any PCI device DEPENDS:=@TARGET_x86_64||TARGET_armsr_armv8 @PCI_SUPPORT +kmod-vfio +kmod-irqbypass KCONFIG:= \ CONFIG_VFIO_PCI \ CONFIG_VFIO_PCI_IGD=n FILES:= \ $(LINUX_DIR)/drivers/vfio/pci/vfio-pci-core.ko \ $(LINUX_DIR)/drivers/vfio/pci/vfio-pci.ko AUTOLOAD:=$(call AutoProbe,vfio-pci) endef define KernelPackage/vfio-pci/description Support for the generic PCI VFIO bus driver which can connect any PCI device to the VFIO framework. endef $(eval $(call KernelPackage,vfio-pci)) define KernelPackage/vhost SUBMENU:=Virtualization TITLE:=Host kernel accelerator for virtio (base) KCONFIG:=CONFIG_VHOST FILES:=$(LINUX_DIR)/drivers/vhost/vhost.ko \ $(LINUX_DIR)/drivers/vhost/vhost_iotlb.ko AUTOLOAD:=$(call AutoProbe,vhost vhost_iotlb) endef $(eval $(call KernelPackage,vhost)) define KernelPackage/vhost-net SUBMENU:=Virtualization TITLE:=Host kernel accelerator for virtio-net DEPENDS:=+kmod-tun +kmod-vhost KCONFIG:=CONFIG_VHOST_NET FILES:=$(LINUX_DIR)/drivers/vhost/vhost_net.ko AUTOLOAD:=$(call AutoProbe,vhost_net) endef $(eval $(call KernelPackage,vhost-net)) ='linenumbers'>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * patch-cmdline.c - patch the kernel command line on rb532
 *
 * Copyright (C) 2006 Felix Fietkau <nbd@nbd.name>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <string.h>

#define SEARCH_SPACE	(16 * 1024)
#define CMDLINE_MAX		512

int main(int argc, char **argv)
{
	int fd, found = 0, len, ret = -1;
	char *ptr, *p;
	unsigned int search_space;

	if (argc <= 2 || argc > 4) {
		fprintf(stderr, "Usage: %s <file> <cmdline> [size]\n", argv[0]);
		goto err1;
	} else if (argc == 3) {
		fprintf(stdout, "search space used is default of 16KB\n");
		search_space = SEARCH_SPACE;
	} else {
		search_space = atoi(argv[3]);
	}
	len = strlen(argv[2]);
	if (len + 9 > CMDLINE_MAX) {
		fprintf(stderr, "Command line string too long\n");
		goto err1;
	}
	
	if (((fd = open(argv[1], O_RDWR)) < 0) ||
		(ptr = (char *) mmap(0, search_space + CMDLINE_MAX, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (void *) (-1)) {
		fprintf(stderr, "Could not open kernel image");
		goto err2;
	}
	
	for (p = ptr; p < (ptr + search_space); p += 4) {
		if (memcmp(p, "CMDLINE:", 8) == 0) {
			found = 1;
			p += 8;
			break;
		}
	}
	if (!found) {
		fprintf(stderr, "Command line marker not found!\n");
		goto err3;
	}

	memset(p, 0, CMDLINE_MAX - 8);
	strcpy(p, argv[2]);
	msync(p, CMDLINE_MAX, MS_SYNC|MS_INVALIDATE);
	ret = 0;

err3:
	munmap((void *) ptr, len);
err2:
	if (fd > 0)
		close(fd);
err1:
	return ret;
}