From 74a59c2b1a4b23978ac9aad56540aec64cc3f3e0 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 12 Aug 2019 14:01:46 +0200 Subject: [vmware-version-check] CPU support check helper --- .../opt/openslx/bin/vmware-get-supported-version | 22 ++++++++++++++++++++++ core/modules/vmware-version-check/module.build | 13 +++++++++++++ core/modules/vmware-version-check/module.conf | 6 ++++++ .../vmware-version-check/module.conf.ubuntu | 4 ++++ .../openslx/scripts/systemd-download_slx_addons | 14 ++++---------- core/rootfs/rootfs-stage32/module.conf | 1 + core/targets/stage32-bwlp/vmware-version-check | 1 + 7 files changed, 51 insertions(+), 10 deletions(-) create mode 100755 core/modules/vmware-version-check/data/opt/openslx/bin/vmware-get-supported-version create mode 100644 core/modules/vmware-version-check/module.build create mode 100644 core/modules/vmware-version-check/module.conf create mode 100644 core/modules/vmware-version-check/module.conf.ubuntu create mode 120000 core/targets/stage32-bwlp/vmware-version-check diff --git a/core/modules/vmware-version-check/data/opt/openslx/bin/vmware-get-supported-version b/core/modules/vmware-version-check/data/opt/openslx/bin/vmware-get-supported-version new file mode 100755 index 00000000..82bd7d50 --- /dev/null +++ b/core/modules/vmware-version-check/data/opt/openslx/bin/vmware-get-supported-version @@ -0,0 +1,22 @@ +#!/bin/ash +# This script checks whether given VMware version supports the CPU: +# * Intel: check for "VMX Unrestricted Guest" CPU flag +# * AMD: check if CPU family is Bulldozer or newer + +export PATH=$PATH:/opt/openslx/sbin:/opt/openslx/bin + +get_supported_version() { + local vendor="$( awk '$1 == "vendor_id" {print $NF;exit}' /proc/cpuinfo )" + local version=12 + if [ "$vendor" = "GenuineIntel" ]; then + modprobe msr + flag="$( rdmsr --bitfield 5:5 0x485 )" + [ "$flag" = 1 ] && version=15 + elif [ "$vendor" = "AuthenticAMD" ]; then + family="$( awk '$1$2 == "cpufamily" {print $NF;exit}' /proc/cpuinfo )" + [ "$family" -ge 21 ] && version=15 + fi + echo "$version" +} + +get_supported_version diff --git a/core/modules/vmware-version-check/module.build b/core/modules/vmware-version-check/module.build new file mode 100644 index 00000000..5086d1bc --- /dev/null +++ b/core/modules/vmware-version-check/module.build @@ -0,0 +1,13 @@ +#!/bin/bash +# fake module simply copying its data/ files +fetch_source() { + : +} + +build() { + : +} + +post_copy() { + : +} diff --git a/core/modules/vmware-version-check/module.conf b/core/modules/vmware-version-check/module.conf new file mode 100644 index 00000000..49255291 --- /dev/null +++ b/core/modules/vmware-version-check/module.conf @@ -0,0 +1,6 @@ +#!/bin/bash +REQUIRED_BINARIES=" + rdmsr +" +REQUIRED_LIBRARIES="" +REQUIRED_DIRECTORIES="" diff --git a/core/modules/vmware-version-check/module.conf.ubuntu b/core/modules/vmware-version-check/module.conf.ubuntu new file mode 100644 index 00000000..3bab77c9 --- /dev/null +++ b/core/modules/vmware-version-check/module.conf.ubuntu @@ -0,0 +1,4 @@ +#!/bin/bash +REQUIRED_CONTENT_PACKAGES=" + msr-tools +" diff --git a/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-download_slx_addons b/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-download_slx_addons index 8c14b0d4..735c72c0 100755 --- a/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-download_slx_addons +++ b/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-download_slx_addons @@ -14,6 +14,8 @@ # ###################################################################################### +export PATH=$PATH:/opt/openslx/sbin:/opt/openslx/bin + # read global OpenSLX config . /opt/openslx/config || { echo "Could not source config!"; exit 23; } @@ -56,16 +58,8 @@ if [ $# -eq 1 ]; then # Select proper VMware version FILE="$ADDON" if [ "$ADDON" = "vmware" ]; then - vendor="$( awk '$1 == "vendor_id" {print $NF;exit}' /proc/cpuinfo )" - version=12 - if [ "$vendor" = "GenuineIntel" ]; then - modprobe msr - flag="$( rdmsr --bitfield 5:5 0x485 )" - [ "$flag" = 1 ] && version=15 - elif [ "$vendor" = "AuthenticAMD" ]; then - family="$( awk '$1$2 == "cpufamily" {print $NF;exit}' /proc/cpuinfo )" - [ "$family" -ge 21 ] && version=15 - fi + # check with the helper + version="$(vmware-get-supported-version)" FILE="vmware$version" echo "Deciding to download $FILE instead of $ADDON after checking CPU" fi diff --git a/core/rootfs/rootfs-stage32/module.conf b/core/rootfs/rootfs-stage32/module.conf index 409af2ba..f0d5d5a4 100644 --- a/core/rootfs/rootfs-stage32/module.conf +++ b/core/rootfs/rootfs-stage32/module.conf @@ -1,6 +1,7 @@ #!/bin/bash REQUIRED_MODULES=" kernel + vmware-version-check " REQUIRED_BINARIES=" bash diff --git a/core/targets/stage32-bwlp/vmware-version-check b/core/targets/stage32-bwlp/vmware-version-check new file mode 120000 index 00000000..fac1392c --- /dev/null +++ b/core/targets/stage32-bwlp/vmware-version-check @@ -0,0 +1 @@ +../../modules/vmware-version-check \ No newline at end of file -- cgit v1.2.3-55-g7522