golemparts/rppal

Docker container - UnknownModel

sierrodc opened this issue · 1 comments

Hi,

I'm trying to run my application in a docker container. The code is the one listed in rppal main page:

use ...
const GPIO_LED: u8 = 23;

fn main() -> Result<(), Box<dyn Error>> {
    println!("Blinking an LED on a {}.", DeviceInfo::new()?.model());
    let mut pin = Gpio::new()?.get(GPIO_LED)?.into_output();
    ...
}
  • running on raspberry pi4 (r.os x64) works fine
  • running inside docker alpine with --privileged flag works fine (but a little bit too permissive)
  • running inside docker alpine fails (even with --device /dev/gpiomem --device /dev/mem -v /sys:/sys flags) with following errors:
    • UnknownModel calling DeviceInfo::new()
    • io(Os { code: 2, kind: NotFound, message: "No such file or directory" }) calling Gpio::new()

in all the cases I'm able to see /proc/cpuinfo. What am I missing?

/proc/cpuinfo contains
Hardware : BCM2835
Revision : c03112
and it should be parsed correctly to RP4B. I'll try to debug DeviceInfo::new() code.

Executing the code in master branch (parse_proc_cpuinfo function) everything works fine.
Is it possible that rppal 0.11.3 isn't aligned with master code (so it is not able to read from /proc/cpuinfo, tries to read from other locations /sys/firmware/* that without --privileged docker flag aren't availble by default)?

Ok.

If I use the source code (master), RaspberryPI 4 model B is detected correctly. The error raised by Gpio::new() is due to the fact that /dev/gpiochip0 must be shared. So, if I run:

docker run --device /dev/gpiomem --device /dev/gpiochip0 -it my-image-musl

everything works fine.