From patchwork Wed Jan 8 14:25:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 22974 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f72.google.com (mail-vb0-f72.google.com [209.85.212.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9867E202E2 for ; Wed, 8 Jan 2014 14:25:14 +0000 (UTC) Received: by mail-vb0-f72.google.com with SMTP id x8sf2323390vbf.7 for ; Wed, 08 Jan 2014 06:25:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=aiAC5L9zLkxVFARZQZJfWRXlsvRK+nCsm2A7LoKSvB0=; b=UfqQwINp+k21HCEwTMI9fUncT0YrJwygKVy6602FEsgjDXLeG48T5sMTHLbshRpsqa oDo5Elbp1+Lle4wVy4XU5xaaJNZRda/bo97SWuMQ2QE6uyodmdtOPTTD/0LKFJsWQUsi u5KdREx76YAo9Lt8X8WRKhyjws+2vXqfgD+k7J1KJN5zvscetgCpa83JVjANF5GDhnPb iuDSHD2WDobAxjKWNmReOyy06SekRTCIy6QITOWx3Ch+bZiuKB5cqPXK7axinCVwwlH4 kwNSL7NId9mAMZhjBsgvvxIAYNiIapVBJNwdSoxwfMEnmbdjvnBKBsZtX1VyM2LzBMhx KMFg== X-Gm-Message-State: ALoCoQk/ievYYolQmaPiU67Di2gt1bXu8Up/K2+HUHRsjVv2YgaF0XHXbge3ldroNGWrpVhTDbtm X-Received: by 10.58.118.231 with SMTP id kp7mr25833752veb.36.1389191113764; Wed, 08 Jan 2014 06:25:13 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.47.103 with SMTP id c7ls663714qen.24.gmail; Wed, 08 Jan 2014 06:25:13 -0800 (PST) X-Received: by 10.52.109.105 with SMTP id hr9mr2473855vdb.71.1389191113681; Wed, 08 Jan 2014 06:25:13 -0800 (PST) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id fb12si673254veb.52.2014.01.08.06.25.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 06:25:13 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.181; Received: by mail-ve0-f181.google.com with SMTP id oy12so1262583veb.40 for ; Wed, 08 Jan 2014 06:25:13 -0800 (PST) X-Received: by 10.58.49.67 with SMTP id s3mr2008698ven.75.1389191113510; Wed, 08 Jan 2014 06:25:13 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.13.131 with SMTP id ey3csp228908ved; Wed, 8 Jan 2014 06:25:12 -0800 (PST) X-Received: by 10.14.114.71 with SMTP id b47mr100047802eeh.26.1389191111753; Wed, 08 Jan 2014 06:25:11 -0800 (PST) Received: from socrates.bennee.com (static.88-198-71-155.clients.your-server.de. [88.198.71.155]) by mx.google.com with ESMTPS id i1si93421012eev.236.2014.01.08.06.25.11 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 08 Jan 2014 06:25:11 -0800 (PST) Received-SPF: neutral (google.com: 88.198.71.155 is neither permitted nor denied by best guess record for domain of alex.bennee@linaro.org) client-ip=88.198.71.155; Received: from localhost ([127.0.0.1] helo=zen.linaro.local) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1W0u71-0004At-Gk; Wed, 08 Jan 2014 15:28:03 +0100 From: alex.bennee@linaro.org To: qemu-devel@nongnu.org Cc: patches@linaro.org Subject: [PATCH 1/2] scripts/qemu-binfmt-conf.sh: re-factor and clean-up Date: Wed, 8 Jan 2014 14:25:33 +0000 Message-Id: <1389191134-16597-2-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1389191134-16597-1-git-send-email-alex.bennee@linaro.org> References: <1389191134-16597-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: alex.bennee@linaro.org X-SA-Exim-Scanned: No (on socrates.bennee.com); SAEximRunCond expanded to false X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: alex.bennee@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Alex Bennée I was looking to set-up for development but found the script made some hard-coded assumptions. It doesn't seem the script is used by the distros but if it had a little more love maybe it would be ;-) * Add usage() instructions * Move all registering to a single function * Check for existence of executable qemu before registering * Add -d (devel) mode for subscribing in-src tree binaries * error handling when setting binfmt fails * add support for aarch64 --- scripts/qemu-binfmt-conf.sh | 124 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 105 insertions(+), 19 deletions(-) mode change 100644 => 100755 scripts/qemu-binfmt-conf.sh diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh old mode 100644 new mode 100755 index 0da2618..8cfb387 --- a/scripts/qemu-binfmt-conf.sh +++ b/scripts/qemu-binfmt-conf.sh @@ -1,5 +1,89 @@ #!/bin/sh -# enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390 program execution by the kernel +# Enable automatic i386/ARM/aarch64/M68K/MIPS/SPARC/PPC/s390 +# program execution by the kernel using the binfmt_misc feature +# + +# Base path for finding QEMU binary +BINFMT_DEVEL_MODE="" +BINFMT_VERBOSE="" +BINFMT_BASE_PATH=/usr/local/bin + +# Print out some simple usage instructions +usage() { + echo "Usage: `basename $0` options (-hdp)" + echo " +This script is used to configure binfmt_misc on a system +to automatically call QEMU when a binary that it can +deal with is detected by the kernel. + +Parameters: + -p PATH - base path to find QEMU binaries + (default: $BINFMT_BASE_PATH) + -d - developer mode, search source tree for + the QEMU binaries. + -v - more verbose output +" + exit 1 +} + +# Register an individual binfmt +# +# Before registering the format we check for the +# existence of the binary and if VERBOSE is set we +# specify what exactly has been registered. + +register_binfmt () { + name=$1 + qbin=$2 + binfmt_string=$3 + warning=$4 + + if [ -n "${BINFMT_DEVEL_MODE}" ]; then + qemu_check_path=${BINFMT_BASE_PATH}/${qbin}-linux-user/qemu-${qbin} + else + qemu_check_path=${BINFMT_BASE_PATH}/qemu-${qbin} + fi + + if [ -x "$qemu_check_path" ]; then + bfmt=":$name:M::$binfmt_string:$qemu_check_path:" + echo $bfmt > /proc/sys/fs/binfmt_misc/register + res=$? + if [ "$res" != "0" ]; then + echo "Error ($res): $bfmt > /proc/sys/fs/binfmt_misc/register" + else + if [ -n "${BINFMT_VERBOSE}" ] ; then + echo "registered $qemu_check_path for $name binaries" + fi + if [ -n "$warning" ]; then + echo "$warning" + fi + fi + fi +} + +while getopts "vhdp:" opt +do + case $opt in + h) + usage + ;; + p) + BINFMT_BASE_PATH=$OPTARG + ;; + d) + BINFMT_DEVEL_MODE=1 + script_dir=`dirname $0` + BINFMT_BASE_PATH=`realpath $script_dir/..` + ;; + v) + BINFMT_VERBOSE=1 + ;; + *) + echo "Unknown option." + usage + ;; + esac +done # load the binfmt_misc module if [ ! -d /proc/sys/fs/binfmt_misc ]; then @@ -31,39 +115,41 @@ esac # register the interpreter for each cpu except for the native one if [ $cpu != "i386" ] ; then - echo ':i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register - echo ':i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register + register_binfmt i386 i386 "\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" + register_binfmt i486 i386 "\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" fi if [ $cpu != "alpha" ] ; then - echo ':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-alpha:' > /proc/sys/fs/binfmt_misc/register + register_binfmt alpha alpha "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" fi if [ $cpu != "arm" ] ; then - echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-arm:' > /proc/sys/fs/binfmt_misc/register - echo ':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-armeb:' > /proc/sys/fs/binfmt_misc/register + register_binfmt arm arm "\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" + register_binfmt armeb armeb "\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff" +fi +if [ $cpu != "aarch64" ] ; then + register_binfmt aarch64 aarch64 "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" fi if [ $cpu != "sparc" ] ; then - echo ':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sparc:' > /proc/sys/fs/binfmt_misc/register + register_binfmt sparc sparc "\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff" fi if [ $cpu != "ppc" ] ; then - echo ':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-ppc:' > /proc/sys/fs/binfmt_misc/register + register_binfmt ppc ppc "\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff" fi if [ $cpu != "m68k" ] ; then - echo 'Please check cpu value and header information for m68k!' - echo ':m68k:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-m68k:' > /proc/sys/fs/binfmt_misc/register + register_binfmt m68k m68k "\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff" 'Please check cpu value and header information for m68k!' fi if [ $cpu != "mips" ] ; then # FIXME: We could use the other endianness on a MIPS host. - echo ':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips:' > /proc/sys/fs/binfmt_misc/register - echo ':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsel:' > /proc/sys/fs/binfmt_misc/register - echo ':mipsn32:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mipsn32:' > /proc/sys/fs/binfmt_misc/register - echo ':mipsn32el:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsn32el:' > /proc/sys/fs/binfmt_misc/register - echo ':mips64:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips64:' > /proc/sys/fs/binfmt_misc/register - echo ':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mips64el:' > /proc/sys/fs/binfmt_misc/register + register_binfmt mips mips "\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff" + register_binfmt mipsel mipsel "\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" + register_binfmt mipsn32 mipsn32 "\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff" + register_binfmt mipsn32el mipsn32el "\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" + register_binfmt mips64 mips64 "\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff" + register_binfmt mips64el mips64el "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" fi if [ $cpu != "sh" ] ; then - echo ':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-sh4:' > /proc/sys/fs/binfmt_misc/register - echo ':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sh4eb:' > /proc/sys/fs/binfmt_misc/register + register_binfmt sh4 sh4 "\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" + register_binfmt sh4eb sh4eb "\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff" fi if [ $cpu != "s390x" ] ; then - echo ':s390x:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-s390x:' > /proc/sys/fs/binfmt_misc/register + register_binfmt s390x s390x "\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff" fi