ardera / flutter_packages

My collected packages for pub.dev
MIT License
28 stars 7 forks source link

ODROID C4 support #4

Closed apiraino closed 2 years ago

apiraino commented 2 years ago

hello!

I'm trying to compile and deploy a sample application ODROID C4 but when I run the app it crashes:

E/flutter ( 4463): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libc.so.6': dlopen failed: library "libc.so.6" not found
E/flutter ( 4463): #0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:55)
E/flutter ( 4463): #1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:20:12)
E/flutter ( 4463): #2      new PlatformInterface._private (package:flutter_gpiod/src/gpiod.dart:189:42)
E/flutter ( 4463): #3      PlatformInterface.instance (package:flutter_gpiod/src/gpiod.dart:240:37)
E/flutter ( 4463): #4      FlutterGpiod.instance (package:flutter_gpiod/src/gpiod.dart:668:43)
E/flutter ( 4463): #5      main (package:marchivum/main.dart:9:30)
E/flutter ( 4463): #6      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:145:25)
E/flutter ( 4463): #7      _rootRun (dart:async/zone.dart:1428:13)
E/flutter ( 4463): #8      _CustomZone.run (dart:async/zone.dart:1328:19)
E/flutter ( 4463): #9      _runZoned (dart:async/zone.dart:1863:10)
E/flutter ( 4463): #10     runZonedGuarded (dart:async/zone.dart:1851:12)
E/flutter ( 4463): #11     _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:141:5)
E/flutter ( 4463): #12     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
E/flutter ( 4463): #13     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter ( 4463): 
Syncing files to device ODROID C4...                                90ms

Do I need to install anything on my development machine (like, the Android NDK?). Is the ODROID C4 supported?

thanks!

apiraino commented 2 years ago

ref: https://github.com/ardera/flutter_gpiod/issues/9#issuecomment-687787952

ardera commented 2 years ago

what distro are you using? can you do ldd /bin/true (if it works for you) and give me the output?

apiraino commented 2 years ago

thanks for the quick reply!

I am compiling with debian testing (bookworm):

$ ldd /bin/true
    linux-vdso.so.1 (0x00007fff6a1d3000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe02577a000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fe025960000)

and on the ODROID with their Android 9 distro (ldd not present there):

Bildschirmfoto 2021-10-19 um 15 13 09

I think the error happens on the device. After some hacking with your Android patches from September 2020 (basically replacing s/libc.so.6/libc.so/g in lib/src/gpiod.dart I could make it start on the ODROID. But then I am blocked with an error when polling the GPIO ports:

I/flutter ( 5597): GpiodChip(index: 0, name: 'gpiochip0', label: 'aobus-banks', numLines: 16)
...
I/flutter ( 5597): GpiodChip(index: 1, name: 'gpiochip1', label: 'periphs-banks', numLines: 86)
...
E/flutter ( 5597): [ERROR:flutter/runtime/dart_isolate.cc(1138)] Unhandled exception:
E/flutter ( 5597): Could not wait for GPIO events., epoll_wait: Interrupted system call
E/flutter ( 5597): #0      _eventIsolateEntry (package:flutter_gpiod/src/gpiod.dart:150:7)
E/flutter ( 5597): #1      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:286:17)
E/flutter ( 5597): #2      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

I'm not 100% sure but it looks like I can read the GPIO lines but fail to poll them, makes sense?

ardera commented 2 years ago

I think the error happens on the device. After some hacking with your Android patches from September 2020 (basically replacing s/libc.so.6/libc.so/g in lib/src/gpiod.dart I could make it start on the ODROID.

Ah, yeah that makes sense. I should probably add some tests to make sure this doesn't regress again (it was working fine on android once)

But then I am blocked with an error when polling the GPIO ports:

I/flutter ( 5597): GpiodChip(index: 0, name: 'gpiochip0', label: 'aobus-banks', numLines: 16)
...
I/flutter ( 5597): GpiodChip(index: 1, name: 'gpiochip1', label: 'periphs-banks', numLines: 86)
...
E/flutter ( 5597): [ERROR:flutter/runtime/dart_isolate.cc(1138)] Unhandled exception:
E/flutter ( 5597): Could not wait for GPIO events., epoll_wait: Interrupted system call
E/flutter ( 5597): #0      _eventIsolateEntry (package:flutter_gpiod/src/gpiod.dart:150:7)
E/flutter ( 5597): #1      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:286:17)
E/flutter ( 5597): #2      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

I'm not 100% sure but it looks like I can read the GPIO lines but fail to poll them, makes sense?

That's most likely a bug inside flutter_gpiod. Interrupted system call is the description for the EINTR errno, which is an indication that a signal was handled (i.e. things like SIGTERM) and the system call should just be restarted. Seems like it's just bad luck you get a lot of signals in your case, on raspberry pi I never had that error.

What flutter_gpiod should be doing is running every syscall, including epoll_wait, in a loop until either it executed successfully or failed with an error != EINTR

ardera commented 2 years ago

I think this is working now.

apiraino commented 2 years ago

confirmed (and sorry for getting back to you)

thank you @ardera so much for your help :)