qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: "Andreas Färber" <afaerber@suse.de>
Cc: Laurent Vivier <laurent@vivier.eu>,
	Riku Voipio <riku.voipio@iki.fi>,
	qemu-devel@nongnu.org, Alexander Graf <agraf@suse.de>
Subject: [Qemu-devel] [PATCH 2/3] scripts: define qemu-update-binfmt
Date: Sun, 20 Jan 2013 00:20:59 +0100	[thread overview]
Message-ID: <1358637660-8625-2-git-send-email-laurent@vivier.eu> (raw)
In-Reply-To: <1358637660-8625-1-git-send-email-laurent@vivier.eu>

qemu-update-binfmt uses update-binfmts to set qemu as an ELF interpreter
for a given cpu type.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 scripts/qemu-update-binfmt |   59 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100755 scripts/qemu-update-binfmt

diff --git a/scripts/qemu-update-binfmt b/scripts/qemu-update-binfmt
new file mode 100755
index 0000000..eddcf89
--- /dev/null
+++ b/scripts/qemu-update-binfmt
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+if [ ! -f /usr/sbin/update-binfmts ] ; then
+    echo "ERROR: this scripts needs update-binfmts" 1>&2
+    exit 1
+fi
+
+MAGIC=$(dirname $(readlink -f "$0"))/binfmts-magic
+
+if [ ! -e "$MAGIC" ] ; then
+    echo "ERROR: file $MAGIC is missing !" 1>&2
+    exit 1
+fi
+
+. "$MAGIC"
+
+# interpreter to install
+
+cpu="$1"
+if [ "$cpu" = "" ] ; then
+    echo "ERROR: you need to specify the cpu target" 1>&2
+    echo "       available targets are:" 1>&2
+    for target in  $qemu_target_list ; do
+        echo "       $target " 1>&2
+    done
+    exit 1
+fi
+
+# interpreter path
+
+QEMU_PATH="$2"
+if [ "$QEMU_PATH" = "" ] ; then
+    QEMU_PATH=/usr/local/bin
+fi
+
+# probe cpu type
+
+host_family=$(qemu_get_family)
+
+magic=$(eval echo \$${cpu}_magic)
+mask=$(eval echo \$${cpu}_mask)
+family=$(eval echo \$${cpu}_family)
+
+if [ "$magic" = "" -o "$mask" = "" -o "$family" = "" ] ; then
+    echo "INTERNAL ERROR: unknown cpu $cpu" 1>&2
+    exit 1
+fi
+
+if [ "$host_family" = "$family" ] ; then
+    echo "WARNING: don't install interpreter for current cpu !" 1>&2
+    exit 0
+fi
+
+qemu="$QEMU_PATH/qemu-$cpu"
+if [ "$cpu" = "i486" ] ; then
+    qemu="$QEMU_PATH/qemu-i386"
+fi
+
+update-binfmts --install $cpu ${qemu} --magic $magic --mask $mask
-- 
1.7.10.4

  reply	other threads:[~2013-01-19 23:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-14 21:36 [Qemu-devel] [PATCH] linux-user: Some scripts to create linux container using qemu-linux-user Laurent Vivier
2013-01-14 21:54 ` Andreas Färber
2013-01-19 23:20 ` [Qemu-devel] [PATCH 1/3] scripts: extract ELF magics from qemu-binfmt-conf.sh Laurent Vivier
2013-01-19 23:20   ` Laurent Vivier [this message]
2013-01-19 23:21   ` [Qemu-devel] [PATCH 3/3] scripts: A script to create linux container using qemu-linux-user Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1358637660-8625-2-git-send-email-laurent@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).