Browse Source

create_arm - fix binfmt for arm

Émile Morel 10 years ago
parent
commit
d74b19fb3b
2 changed files with 36 additions and 3 deletions
  1. 33 0
      olinux/binfmt-misc-arm.sh
  2. 3 3
      olinux/create_arm_debootstrap.sh

+ 33 - 0
olinux/binfmt-misc-arm.sh

@@ -0,0 +1,33 @@
+#!/bin/bash
+# Script from http://tinkering-is-fun.blogspot.fr/2009/12/running-arm-linux-on-your-desktop-pc_12.html
+
+UNREGISTER=0
+if [ "$1" == "unregister" ]; then
+    UNREGISTER=1
+fi
+
+FORMAT_NAME='arm'
+FORMAT_MAGIC='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'
+FORMAT_MASK='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
+FORMAT_INTERP='/usr/bin/qemu-arm-static'
+
+FORMAT_REGISTRATION=":$FORMAT_NAME:M::$FORMAT_MAGIC:$FORMAT_MASK:$FORMAT_INTERP:"
+
+BINFMT_MISC="/proc/sys/fs/binfmt_misc"
+
+if [ $UNREGISTER -ne 1 ]; then
+    # Check if format is not registered already
+    if [ ! -f "$BINFMT_MISC/$FORMAT_NAME" ]; then
+        echo "Registering SH4 binfmt_misc support"
+        echo "$FORMAT_REGISTRATION" > /proc/sys/fs/binfmt_misc/register
+    else
+        echo "Format $FORMAT_NAME already registered."
+    fi
+else
+    # We were asked to drop the registration
+    if [ -f "$BINFMT_MISC/$FORMAT_NAME" ]; then
+	echo -1 > "$BINFMT_MISC/$FORMAT_NAME"
+    else
+	echo "Format $FORMAT_NAME not registered."
+    fi
+fi

+ 3 - 3
olinux/create_arm_debootstrap.sh

@@ -53,10 +53,10 @@ rm -rf $targetdir && mkdir -p $targetdir
 apt-get install --force-yes -y debootstrap dpkg-dev qemu binfmt-support qemu-user-static dpkg-cross
 
 # Debootstrap
-debootstrap --arch=armhf --foreign $distro $targetdir
-update-binfmts --disable
 mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
-update-binfmts --enable
+bash /olinux/binfmt-misc-arm.sh unregister
+bash /olinux/binfmt-misc-arm.sh 
+debootstrap --arch=armhf --foreign $distro $targetdir
 cp /usr/bin/qemu-arm-static $targetdir/usr/bin/
 cp /etc/resolv.conf $targetdir/etc
 chroot $targetdir /debootstrap/debootstrap --second-stage