10

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 use armv7. 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 equivalent armv7 binary a good idea? (opcode conversion)

If so, can anyone give some idea on how to do it?

11

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).

  • In the being time this solution doesn't work, I always get error 404 while doing apt update after adding i386 arch. – Mohammed Noureldin Jan 6 '17 at 20:55
  • @Mohammed what distribution are you using? – Stephen Kitt Jan 6 '17 at 21:58
  • Raspbian, 11.2016 release. and I wanted to emulate i386 – Mohammed Noureldin Jan 7 '17 at 13:47
  • OK, 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. – Stephen Kitt Jan 7 '17 at 13:53
  • I had to mention that I tried that with both Rasbian and Ubuntu. Any good disto suggesion where I can emulate i386 on armhf host? – Mohammed Noureldin Jan 7 '17 at 14:05
1

Thanks for your detailed replay.

I use Rasbian OS,and adding of i386 architecture fails in raspbian during sudo apt-get update. Can I download the i386 package separately for raspbian and install?. If so can you share any links to download.

Can I copy the filters dependent .so files from i386 (Linux mint running in x86) and paste in appropriate paths in raspbain and use Qemu to run the filter?

Following are the ldd echo of the filter:

linux-gate.so.1 =>  (0xb779c000)
libcups.so.2 => /usr/lib/i386-linux-gnu/libcups.so.2 (0xb7716000)
libcupsimage.so.2 => /usr/lib/i386-linux-gnu/libcupsimage.so.2 (0xb770d000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb755c000)
libgssapi_krb5.so.2 => /usr/lib/i386-linux-gnu/libgssapi_krb5.so.2 (0xb7517000)
libgnutls.so.26 => /usr/lib/i386-linux-gnu/libgnutls.so.26 (0xb7451000)
libavahi-common.so.3 => /usr/lib/i386-linux-gnu/libavahi-common.so.3 (0xb7443000)
libavahi-client.so.3 => /usr/lib/i386-linux-gnu/libavahi-client.so.3 (0xb7431000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb7414000)
libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb73fa000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb73b4000)
/lib/ld-linux.so.2 (0xb779d000)
libkrb5.so.3 => /usr/lib/i386-linux-gnu/libkrb5.so.3 (0xb72f6000)
libk5crypto.so.3 => /usr/lib/i386-linux-gnu/libk5crypto.so.3 (0xb72c6000)
libcom_err.so.2 => /lib/i386-linux-gnu/libcom_err.so.2 (0xb72c0000)
libkrb5support.so.0 => /usr/lib/i386-linux-gnu/libkrb5support.so.0 (0xb72b4000)
libgcrypt.so.11 => /lib/i386-linux-gnu/libgcrypt.so.11 (0xb722d000)
libtasn1.so.6 => /usr/lib/i386-linux-gnu/libtasn1.so.6 (0xb7219000)
libp11-kit.so.0 => /usr/lib/i386-linux-gnu/libp11-kit.so.0 (0xb71dd000)
libdbus-1.so.3 => /lib/i386-linux-gnu/libdbus-1.so.3 (0xb7191000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb718c000)
libkeyutils.so.1 => /lib/i386-linux-gnu/libkeyutils.so.1 (0xb7188000)
libresolv.so.2 => /lib/i386-linux-gnu/libresolv.so.2 (0xb7170000)
libgpg-error.so.0 => /lib/i386-linux-gnu/libgpg-error.so.0 (0xb716b000)
libffi.so.6 => /usr/lib/i386-linux-gnu/libffi.so.6 (0xb7163000)
librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb715a000)

Regard, Nash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.