From patchwork Sat Jan 19 23:20:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2/3] scripts: define qemu-update-binfmt Date: Sat, 19 Jan 2013 13:20:59 -0000 From: Laurent Vivier X-Patchwork-Id: 213886 Message-Id: <1358637660-8625-2-git-send-email-laurent@vivier.eu> To: =?UTF-8?q?Andreas=20F=C3=A4rber?= Cc: Laurent Vivier , Riku Voipio , qemu-devel@nongnu.org, Alexander Graf qemu-update-binfmt uses update-binfmts to set qemu as an ELF interpreter for a given cpu type. Signed-off-by: Laurent Vivier --- 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