Running X86 binaries on armv7
You can't easily convert an x86 binary to ARM. If you can't get the source code, or an ARM binary from the manufacturer, and you really do want to use the printer with your Pi2, then the Qemu approach is the correct one in this case, although it will likely be very slow. Qemu does full system emulation but it also works very well for single process emulation.
I'm assuming you have some sort of Debian derivative on your Pi2 (I'm not sure this will work with Raspbian though), and that the binary you have is for i386
(if it's 64-bit, use amd64
instead). Start by adding i386
as a foreign architecture:
sudo dpkg --add-architecture i386
sudo apt-get update
Then run ldd
on the binary and add any required libraries; typically
sudo apt-get install libc6:i386
and anything else with the :i386
suffix added. Make sure this doesn't remove any installed package; hopefully everything you need is multiarch-enabled. (Otherwise the rest won't work.)
Once you've done that, install qemu-user-static
if it isn't already installed (along with its binfmt-support
recommendation); then you can use qemu-i386-static
to run your program:
qemu-i386-static /usr/lib/cups/filter/rasterorp3150
In fact thanks to binfmt-support
it should run directly (as pointed out by Toby Speight):
/usr/lib/cups/filter/rasterorp3150
(binfmt-support
will use Qemu to make this work transparently.)
If you don't want to use binfmt-support
, move rasterorp3150
away:
sudo mv /usr/lib/cups/filter/rasterorp3150 /usr/lib/cups/filter/rasterorp3150.x86
and install a script containing
#!/bin/sh
exec qemu-i386-static /usr/lib/cups/filter/rasterorp3150.x86 "$@"
as /usr/lib/cups/filter/rasterorp3150
.
If you'd rather you can set up a chroot for all this; see debootstrap
and its --foreign
option (the chroot can be set up to use Qemu automatically).
Related videos on Youtube
![Gilles 'SO- stop being evil'](https://i.stack.imgur.com/cFyP6.jpg?s=256&g=1)
Gilles 'SO- stop being evil'
Updated on September 18, 2022Comments
-
Gilles 'SO- stop being evil' over 1 year
I am trying to run a SNBC USB printer on Raspberry Pi2.
For that I need to copy the filter binary of the SNBC USB printer to
/usr/lib/cups/filter
. But the filter binary is compiled using a x86 processor (Manufacturer does not have interest to support arm) where as I usearmv7
. I know it will not work but for a curiosity I tried and cups says/usr/lib/cups/filter/rasterorp3150 failed
.I looked for solutions on the internet and people suggest to use Qemu. But it is for a complete x86 to arm platform. Is there a way to convert the x86 binary to arm binary in a easy uncomplicated way?
By the way, is converting the x86 binary using a
hexedit
tool to an equivalentarmv7
binary a good idea? (opcode
conversion)If so, can anyone give some idea on how to do it?
-
Admin almost 9 years
-
-
Mohammed Noureldin over 7 yearsIn the being time this solution doesn't work, I always get error 404 while doing
apt update
after adding i386 arch. -
Stephen Kitt over 7 years@Mohammed what distribution are you using?
-
Mohammed Noureldin over 7 yearsRaspbian, 11.2016 release. and I wanted to emulate i386
-
Stephen Kitt over 7 yearsOK, so the error you're getting is normal, Raspbian doesn't provide
i386
binaries. This only works with architectures which are supported in the distro you're using. -
Mohammed Noureldin over 7 yearsI had to mention that I tried that with both Rasbian and Ubuntu. Any good disto suggesion where I can emulate i386 on armhf host?
-
Stephen Kitt over 7 years@Mohammed I would have expected this to work with Ubuntu. I know it works with Debian (8 or 9), that's what I use on my ARM devices and it's what I tested with when writing this answer.
-
Mohammed Noureldin over 7 yearsOK now by help of a friend, we managed to get it work, but now the server crashes always in some time after running, in
top
I can see it still running, but of course I cannot connect to it any more untill Ikill -9
the process and restart it. Any idea?d -
Stephen Kitt over 7 years@Mohammed Unfortunately not, I suggest you ask a new question.