elixir-vision / picam

Elixir library used to capture MJPEG video on a Raspberry Pi using the camera module.
Other
122 stars 27 forks source link

Cryptic error when burning firmware #43

Closed Odiumediae closed 5 years ago

Odiumediae commented 5 years ago

I'm trying to build firmware with Nerves and Picam, but so far I haven't been able to, due to an error that I cannot quite understand.

I'm trying to build formware for a "Raspberry Pi Zero W", which should be supported, at least that's what's the README.md seems to say.

Updating base firmware image with Erlang release...
scrub-otp-release.sh: ERROR: Unexpected executable format for '/home/jesterprince/Projects/elixir/nervesy/camera/_build/_nerves-tmp/rootfs-additions/srv/erlang/lib/picam-0.4.0/priv/raspijpgs'

Got:
 readelf:ARM;0x5000400, Version5 EABI, hard-float ABI

Expecting:
 readelf:ARM;0x5000200, Version5 EABI, soft-float ABI

This file was compiled for the host or a different target and probably
will not work.

Check the following:

1. Are you using a path dependency in your mix deps? If so, run
   'mix clean' in that directory to avoid pulling in any of its
   build products.

2. Did you recently upgrade to Nerves 1.3 or Distillery 2.0? Make
   sure that your 'rel/config.exs' has 'plugin Nerves'. See
   https://hexdocs.pm/nerves/updating-projects.html#updating-from-v1-0-to-v1-3-0

3. Did you recently upgrade or change your Nerves system? If so,
   try cleaning and rebuilding this project and its deps.

4. Are you building outside of Nerves' mix integration? If so,
   make sure that you've sourced 'nerves-env.sh'.

If you're still having trouble, please file an issue on Github
at https://github.com/nerves-project/nerves_system_br/issues.

** (Mix) Nerves encountered an error. %IO.Stream{device: :standard_io, line_or_bytes: :line, raw: true}

It's definitely an error related to Picam, because the firmware builds when I don't use Picam. The source is literally just a default Nerves project with {:picam, "~> 0.4.0"} added to the mix.exs.

I also checked the 4 suggestions, and I'm sure none of them are the reason for the problem.

Is this a bug, am I doing something blatantly wrong or am I just being an idiot? Any Help would be appreciated.

fhunleth commented 5 years ago

To resolve this, rm -fr deps/picam, run mix deps.get and rebuild. There's might be a better way, but the goal is to clean out the picam dependency's source directory.

The issue is that picam compiles its C source code to deps/picam instead of _build. At some point, you changed the Nerves system that you were using - maybe switching between one Raspberry Pi to a different one or upgrading the Nerves system. Since the C code is not compiled to _build, elixir_make doesn't know to rebuild it. The code in question might work on the Raspberry Pi Zero without being rebuilt, but it's not guaranteed and debugging that problem is hard. Nerves detects this and raises the error that you saw.

The right fix for this is for picam to update its Makefile and mix.exs to build to the _build directory. @GregMefford - check out Elixir Circuits or nerves_runtime for examples.

GregMefford commented 5 years ago

Thanks @fhunleth! I’ll work on a fix for that, probably tonight. :thumbsup:

Odiumediae commented 5 years ago

Thanks for you help, @fhunleth!

Unfortunately, this workaround does not work for me. I was positive that I had tried this already, but I tried it again for good measure. First, I made sure I had the bare project, as if freshly cloned from a repo:

rm -rf _build deps mix.lock

Then:

export MIX_TARGET=rpi0
mix do deps.get, firmware

Followed by the same error as quoted above (of course).

Then:

rm -rf deps/picam
mix do deps.get, firmware

But then I get the same error again. I suppose, I'm still doing something wrong.

Odiumediae commented 5 years ago

I tried everything, but I cannot get it to work, probably because I don't have any experience with C and makefiles.

When I use {:picam, "~> 0.3.0"}, though, the Nerves project builds and the image gets burned on the SD-card without any problems.

I'd have liked to fix this bug myself, but unfortunately I really don't get it, sorry. I'll try the latest version again after you've patched it. Thanks in advance!

fhunleth commented 5 years ago

Wow, I reproduced the problem. I think that you did everything right. There's another issue. I'm totally tied up with family this week, so I won't be looking into it soon, but I'm curious as to what causing the issue now.

GregMefford commented 5 years ago

Yeah I got the Makefile updated but ended up seeing the same error, so working on digging into what the cause is (but likely won't solve it tonight).

Odiumediae commented 5 years ago

I'll have another try at fixing it (or at least finding probable causes) myself, tonight. Anyway, thank you both!

GregMefford commented 5 years ago

New developments:

I am suspecting that it's something related to https://github.com/elixir-lang/elixir_make/pull/32 since Picam is still using a priv directory, so I'm going to try reworking that to match @fhunleth's comments in that issue thread and see if that solves the problem when building from a path dep.

GregMefford commented 5 years ago

Yep, the path dep works after I did some more re-work to eliminate the priv directory in Picam, and only copy things into the _build directory instead. See #44 if you're curious.

Until that gets merged and released, feel free to try building your project using the following as a picam dependency and let me know if that works for you! 🚀

{:picam, github: "elixir-vision/picam", branch: "build_outside_deps"}
GregMefford commented 5 years ago

@JesterPrince I was planning to merge that PR and make an updated release, but wanted to check and see if you'd had a chance to try this branch and if it solved the problem for you.

GregMefford commented 5 years ago

Version 0.4.1 has been released, which will hopefully solve the issue you were running into. I'd love to hear back whether or not it works for you. 🚀