QuantumEntangledAndy / neolink

An RTSP bridge to Reolink IP cameras
GNU Affero General Public License v3.0
297 stars 44 forks source link

Illegal instruction when running on Raspberry Pi Model B Rev 2 #94

Closed sgargel closed 1 year ago

sgargel commented 1 year ago

Describe the bug

pi@raspberrypi:~/neolink_linux_armhf$ ./neolink help
Illegal instruction
pi@raspberrypi:~/neolink_linux_armhf$ ./neolink --help
Illegal instruction
pi@raspberrypi:~/neolink_linux_armhf$ uname -a
Linux raspberrypi 4.19.65+ #1252 Fri Aug 9 18:00:11 BST 2019 armv6l GNU/Linux
pi@raspberrypi:~$ cat /proc/cpuinfo
processor       : 0
model name      : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS        : 697.95
Features        : half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xb76
CPU revision    : 7

Hardware        : BCM2835
Revision        : 000f
Serial          : 00000000913da422

To Reproduce Steps to reproduce the behavior. Example:

  1. Download and open latest version of NeoLink
  2. Launch Neolink

Expected behavior The help is displayed

Versions

sgargel commented 1 year ago

Here partial strace output:

mprotect(0xb6315000, 8192, PROT_READ)   = 0
mprotect(0xb632c000, 4096, PROT_READ)   = 0
openat(AT_FDCWD, "/proc/cpuinfo", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "processor\t: 0\nmodel name\t: ARMv6"..., 1024) = 292
close(3)                                = 0
getrandom("\x6a", 1, GRND_NONBLOCK)     = 1
stat64("/etc/gnutls/config", 0xbef134b0) = -1 ENOENT (No such file or directory)
access("/etc/gcrypt/fips_enabled", F_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/proc/sys/crypto/fips_enabled", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/gcrypt/hwf.deny", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/proc/self/auxv", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0400, st_size=0, ...}) = 0
read(3, "\20\0\0\0\326\201\0\0\6\0\0\0\0\20\0\0\21\0\0\0d\0\0\0\3\0\0\0004\320A\0"..., 1024) = 152
read(3, "", 1024)                       = 0
close(3)                                = 0
openat(AT_FDCWD, "/proc/cpuinfo", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "processor\t: 0\nmodel name\t: ARMv6"..., 1024) = 292
read(3, "", 1024)                       = 0
close(3)                                = 0
munmap(0xb6f3d000, 67120)               = 0
clock_gettime64(CLOCK_REALTIME, 0xbef13ba0) = -1 ENOSYS (Function not implemented)
clock_gettime(CLOCK_REALTIME, {tv_sec=1685202247, tv_nsec=294447742}) = 0
brk(0x2c15000)                          = 0x2c15000
futex(0xb6cb49a0, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0xb6cb49a0, FUTEX_WAKE_PRIVATE, 2147483647) = 0
--- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPC, si_addr=0x4c74e2} ---
+++ killed by SIGILL +++
Illegal instruction
si458 commented 1 year ago

i believe armhf is 32bit, have u tried the arm64 version instead?

sgargel commented 1 year ago

i believe armhf is 32bit, have u tried the arm64 version instead?

No, with arm64 version says something like Exec format error.

@si458 I believe it's something related to missing feature of my CPU....

QuantumEntangledAndy commented 1 year ago

What version of raspberry pi is this? It must be at least 3 to support hardware floats hf. If it's not you'll need to compile it yourself.

sgargel commented 1 year ago

@QuantumEntangledAndy oh I see!

cat /sys/firmware/devicetree/base/model
Raspberry Pi Model B Rev 2

Can you point me to the docs for building it by my own? I have near zero experience with cargo and rust.

Is it possible to build it on amd64 targeting my raspberry architecture?

QuantumEntangledAndy commented 1 year ago

Your architecture is arm32 without hardware floats. You cannot build and amd64 for it. It must be an armv6.

Anyways here it is.

Last time I tried this on a pi it took hours and burned out the sd card

  1. Install rustup
  2. Install gstreamer dev packages
  3. Clone the repo with git
  4. Build the project with cargo
    cargo build --release
  5. Grab the newly build binary from target/release/neolink

That's for building in on the pi itself.

If you want to cross compile from another machine I'd have to recommend you set up a docker image with armv6 Debian on it and the right emulation (qemu) setup. It will be slow still because of this emulation. Or you can try and find and install a relevant cross compilers and all the dependencies in armv6 format.

It's a lot of work so I don't support. But if you want to try it it's up to you.

sgargel commented 1 year ago

Thanks @QuantumEntangledAndy I'll probably buy a new RPI :rofl:

Just to be sure to buy the right one, What RPI version was NeoLink tested on?

sgargel commented 1 year ago

Your architecture is arm32 without hardware floats. You cannot build and amd64 for it. It must be an armv6.

@QuantumEntangledAndy I'm investigating further on my RPI version and I found this: https://raspberrypi.stackexchange.com/a/4681

It says that if exists (and I have it on my RPI) the folder /lib/arm-linux-gnueabihf, the RPI has hardware floats.

I done some other check with readelf and seems that the problem is more on the CPU arch rather than having HF or not.

$ readelf -A neolink_linux_armhf/neolink
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7-A"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Application
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_FP_arch: VFPv3
  Tag_Advanced_SIMD_arch: NEONv1
  Tag_ABI_PCS_GOT_use: GOT-indirect
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_enum_size: int
  Tag_ABI_VFP_args: VFP registers
  Tag_CPU_unaligned_access: v6
  Tag_ABI_FP_16bit_format: IEEE 754
pi@raspberrypi ~ $ readelf -A $(which dpkg)
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "6"
  Tag_CPU_arch: v6
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_FP_arch: VFPv2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_ABI_VFP_args: VFP registers
  Tag_CPU_unaligned_access: v6

Based on https://raspberrypi.stackexchange.com/a/70806

On a hard-float (hf) system, you will see this as part of the output:

Tag_ABI_VFP_args: VFP registers

sgargel commented 1 year ago

Cool... Im falling down the rabbit hole :rofl:

How strange. Digging around, it looks like the GCC that’s shipped with Debian / Ubuntu has some interesting defaults, which means that building for ARMv6 is somewhat tricky: https://stackoverflow.com/questions/35132319/build-for-armv6-with-gnueabihf/51201725#51201725. I’d probably go as far as saying that it looks like building for anything less than ARMv7 on the GCC toolchain that Debian supplies isn’t supported. Why the hard-float toolchain chucks out an ARMv7 binary, but the soft-float an ARMv6 one is beyond me. Computers!

-- https://www.growse.com/2020/04/26/adventures-in-rust-and-cross-compilation-for-the-raspberry-pi.html

QuantumEntangledAndy commented 1 year ago

You have from the look of that armv6

armv7 is armv6 with hardware floats. I believe that's the main difference between them.

Regardless you'll need to compile for armv6 called armel on Debian.

I did actually use to compile it on GitHub for armv6 but it was so slow and I think at some point we had trouble getting gatreamer at the needed version. So it was dropped

QuantumEntangledAndy commented 1 year ago

Closing as support for armv6 is not planned