Shop OBEX P1 Docs P2 Docs Learn Events
Run BSTC on Cubietruck, Raspberry PI, ... — Parallax Forums

Run BSTC on Cubietruck, Raspberry PI, ...

yetiyeti Posts: 818
edited 2017-05-17 13:45 in Propeller 1
First guinea pig: A Cubietruck (aka: Cubie(board)3) running Cubieez/Wheezy.
(yeti@cubietruck0:9)/opt/bst/bin$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
NAME="Debian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support/"
BUG_REPORT_URL="http://bugs.debian.org/"
(yeti@cubietruck0:9)/opt/bst/bin$ uname -a
Linux cubietruck0 3.4.79 #1 SMP PREEMPT Sat Nov 22 09:37:52 CST 2014 armv7l GNU/Linux
(yeti@cubietruck0:9)/opt/bst/bin$ qemu-i386 bstc -v
Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
Compiled for i386 Linux at 08:17:46 on 2009/07/20
So far I didn't find how to register "qemu-i386" as interpreter to execute Linux-i386-elf files (then recognised by magic, executed by binfmt_misc functions in kernel) without the need to type the prefix "qemu-i386". So for now I need to run "qemu-i386 bstc" explicitely:
(yeti@cubietruck0:3)/tmp$ cat huhu.spin
con
  _clkmode = xtal1|pll16x
  _clkfreq = 80_000_000
 
obj
  ser : "FullDuplexSerial"
 
pub main
  ser.start(31, 30, 0, 115200)
  ser.str(string("Huhu, OpenSpin!",13,10))
  waitcnt(_clkfreq + cnt)
  ser.stop
(yeti@cubietruck0:3)/tmp$ qemu-i386 /opt/bst/bin/bstc -b -Oa -L /opt/parallax.spin.src/spin huhu.spin 
Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
Compiled for i386 Linux at 08:17:46 on 2009/07/20
Loading Object huhu
Loading Object FullDuplexSerial
Program size is 568 longs
Compiled 182 Lines of Code in 1.073 Seconds
(yeti@cubietruck0:3)/tmp$ /opt/spinsim/bin/spinsim -b huhu.binary
Huhu, OpenSpin!

(yeti@cubietruck0:3)/tmp$ ls -l huhu.*
-rw-r--r-- 1 yeti yeti 572 Mai 14 18:18 huhu.binary
-rw-r--r-- 1 yeti yeti 207 Mai 14 18:15 huhu.spin
Well... hoping that OpenSpin will replace BSTC, this does not feel like a great success... it just feels like an additional layer colour covering some rust... but it may save the day... for someone... somewhen... so I think this hack(?) should be mentioned...

***some-minutes-of-elevator-music***

This is what I mean with registering with binfmt_misc to automagically select the right interpreter (here the one for Linux-elf-amd64 binaries):
(yeti@cubietruck0:3)~$ file ./Sync/openspin-linux-amd64  
./Sync/openspin-linux-amd64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=0x765690cb1416e3d30c4f24bc459b9b9f82aaf30e, stripped
(yeti@cubietruck0:3)~$ $ ./Sync/openspin-linux-amd64 2>/dev/null
Propeller Spin/PASM Compiler 'OpenSpin' (c)2012-2016 Parallax Inc. DBA Parallax Semiconductor.
Version 1.00.80 Compiled on May  8 2017 04:19:27
Currently I don't see why it works for x86_64 but not x86 (32bit)...

***some-minutes-of-elevator-music***

Hmmmm...
It even works for an OpenSpin binary for x86...
(yeti@cubietruck0:3)~/Sync$ file openspin 
openspin: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=0xeadae60d8421e98dd858823e8c6e7729b7ddaaa2, stripped
(yeti@cubietruck0:3)~/Sync$ ./openspin 2>/dev/null
Propeller Spin/PASM Compiler 'OpenSpin' (c)2012-2016 Parallax Inc. DBA Parallax Semiconductor.
Version 1.00.80 Compiled on Jun  6 2016 12:42:51
Ok... the many years older BSTC binary must have a different "magic header" than the newer x86 binary... I need to read more about this topic to narrow it down more... and I'm getting optimistic that this will give us BSTC on RasPI and siblings without the need to prefix the calls with qemu-i386...

***some-minutes-of-elevator-music***

Ok...
(yeti@cubietruck0:3)/tmp$ cat xyzzy
#!/bin/sh
echo ':bstc-i386:M::\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff:/usr/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register
(yeti@cubietruck0:3)/tmp$ sudo ./xyzzy
"xyzzy" has installed a "Lex-BSTC" in binfmt's rules:
(yeti@cubietruck0:3)/tmp$ cat /proc/sys/fs/binfmt_misc/bstc-i386
enabled
interpreter /usr/bin/qemu-i386
flags:
offset 0
magic 7f454c46010101030000000000000000020003
mask ffffffffffffffffffffffffffffffffffffff
...which handles files that start exactly like BSTC. I didn't want to screw up the other i386 rule, so an extra rule for BSTC seemed safer...
(-: There are lots of dead heroes and living cowards! :-)
(yeti@cubietruck0:3)/tmp$ /opt/bst/bin/bstc -v
Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
Compiled for i386 Linux at 08:17:46 on 2009/07/20
...and now BSTC can be run as transparently as any other binary and nobody will notice that it is an ancient i386 binary running on an ARMish system...

Edit@20170517

TODO:

Find how to set binfmt rules at boot on non-systemd-ish Linuxens.
https://www.freedesktop.org/software/systemd/man/binfmt.d.html looks like /etc/binfmt.d is a systemd invention.
Probably this will apply to pre-systemd Debian and systemd-free forks like Devuan.

The mask is not needed if it is only made of 0xff.

Comments

  • yetiyeti Posts: 818
    edited 2017-05-17 11:23
    Now the same for Raspbian-Jessie-Lite...
    (yeti@pi2-1:1)~$ cat /etc/os-release 
    PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
    NAME="Raspbian GNU/Linux"
    VERSION_ID="8"
    VERSION="8 (jessie)"
    ID=raspbian
    ID_LIKE=debian
    HOME_URL="http://www.raspbian.org/"
    SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
    BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
    

    Install needed helpers (epic output not copied)...
    (yeti@pi2-1:1)~$ sudo apt-get install binfmt-support qemu-user unzip wget
    

    Get and unpack bstc...
    (yeti@pi2-1:1)~$ wget http://www.fnarfbargle.com/bst/bstc/Latest/bstc-0.15.3.linux.zip
    converted 'http://www.fnarfbargle.com/bst/bstc/Latest/bstc-0.15.3.linux.zip' (ANSI_X3.4-1968) -> 'http://www.fnarfbargle.com/bst/bstc/Latest/bstc-0.15.3.linux.zip' (UTF-8)
    --2017-05-17 05:36:10--  http://www.fnarfbargle.com/bst/bstc/Latest/bstc-0.15.3.linux.zip
    Resolving www.fnarfbargle.com (www.fnarfbargle.com)... 93.93.131.67
    Connecting to www.fnarfbargle.com (www.fnarfbargle.com)|93.93.131.67|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 142221 (139K) [application/zip]
    Saving to: 'bstc-0.15.3.linux.zip'
    
    bstc-0.15.3.linux.zip     100%[=====================================>] 138.89K   813KB/s   in 0.2s   
    
    2017-05-17 05:36:11 (813 KB/s) - 'bstc-0.15.3.linux.zip' saved [142221/142221]
    
    (yeti@pi2-1:1)~$ unzip bstc-0.15.3.linux.zip 
    Archive:  bstc-0.15.3.linux.zip
      inflating: bstc.linux              
    

    First test...
    (yeti@pi2-1:1)~$ qemu-i386 bstc.linux -v
    Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
    Compiled for i386 Linux at 08:17:46 on 2009/07/20
    

    Make binfmt know bst-i386 and reboot...
    (yeti@pi2-1:1)~$ echo ':bstc-i386:M::\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03::/usr/bin/qemu-i386:' | sudo tee /etc/binfmt.d/bstc-i386.conf
    :bstc-i386:M::\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03::/usr/bin/qemu-i386:
    (yeti@pi2-1:1)~$ sudo reboot
    

    Second test...
    (yeti@pi2-1:1)~$ ./bstc.linux -v
    Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
    Compiled for i386 Linux at 08:17:46 on 2009/07/20
    
    ...now it works without qemu-i386 prefix.
Sign In or Register to comment.