Rpi 4 & 5 Libcamera & Mmap permission issue on Android 14

jan at radicalsystems.co.za jan at radicalsystems.co.za
Tue Jun 4 16:25:22 CEST 2024


My apologies if I don't respond correctly to the list email.
Perhaps someone can help 😊
See answers below:

-----Original Message-----
From: Kieran Bingham <kieran.bingham at ideasonboard.com> 
Sent: Tuesday, June 4, 2024 3:45 PM
To: jan at radicalsystems.co.za; libcamera-devel at lists.libcamera.org
Subject: Re: Rpi 4 & 5 Libcamera & Mmap permission issue on Android 14

Quoting jan at radicalsystems.co.za (2024-06-04 11:26:20)
>> Hi Libcamera Fundis!
>> 
>>  
>> 
>> Having a problem capturing an image on Android 14 (& 13).
>> 
>> Tombstone looks like this:
>> 
>>  
>> 
>> 06-03 15:13:03.880 308 578 I DMABUFHEAPS: Using : Non-legacy ION heaps
>> 
>> 06-03 15:13:03.880 308 578 I [minigbm:gbm_mesa_internals.cpp(233)]: 
>> Found GPU v3d
>> 
>> 06-03 15:13:04.052 308 359 E libcamera: ERROR Buffer
>> mapped_framebuffer.cpp:230 Failed to mmap plane: Permission denied
>> 
>> .... lots of Permission denied!
>> 
>> 06-03 15:13:11.282 308 359 E libcamera: ERROR Buffer
>> mapped_framebuffer.cpp:230 Failed to mmap plane: Permission denied
>> 
>> 06-03 15:13:12.008 308 579 E libcamera: ERROR Camera camera.cpp:675 
>> Camera in Running state trying acquire() requiring state Available

>Aside from all the permission denieds - this is somethign interesting that should be looked into. You appear to have already got the camera acquired running (or perhaps never released, maybe due to a bad error path on the failures above) so that then next aquire is failing...

This is stock standard Android with MLKIT ontop. So yes streaming is working and Tensor Flow analytics. We can do facial detection.
Once we request to take the snapshot while streaming it fails.
This is standard implementation and works 100% on a Samsung tablet for instance.
A USB camera connected to the Rpi5 also works.

>> 
>> 06-03 15:13:12.008 308 579 E libcamera: ERROR HAL 
>> camera_device.cpp:390
>> '/base/axi/pcie at 120000/rp1/i2c at 88000/imx708 at 1a': Failed to acquire the 
>> camera
>> 
>> 06-03 15:13:12.008 308 579 E libcamera: ERROR HAL camera3_hal.cpp:81 
>> Failed to open camera module '0'
>> 
>> 06-03 15:13:12.008 308 579 E libcamera: FATAL HAL
>> generic_frame_buffer_allocator.cpp:106 gralloc_open() failed: -87

>I think there are two memory allocators for libcamera to work with both android, and chromeos. I also recall that it takes quite some manual effort to build libcamera for android.

>Can you explain more about how you are building this and setting things up? Was it packaged for you by one of the android builds? Or is there anything else in control of the overall system configuration here?

Packaged android builds Lineage, Emteria and AOSP (https://github.com/raspberry-vanilla), custom built as well.
I'm not sure, I used the Android manifest file straight as is to build the Boot, Vendor & System images.

 
>> MLKIT Streaming & analyzing works until trying to capture an image the 
>> above happens.
>> 
>> The various Android versions for Rpi5 I could find gave the same issue.

>Have you had this working in the past? or on any other devices? Or with a USB camera?

USB camera works 100%, it will capture the photo.
So just to explain we are running Google MLKIT to do facial detection, once all parameters are met, it will take a photo.
The photo part is the problem.
This works on a tablet obviously, but we are trying to get it onto a different platform.
 

>> I tried Emteria, AOSP & LineageOS 13 & 14
>> 
>> Android built from Raspberry Vanilla and even replacing with later 
>> libcamera had the same issue.
>> 
>>  
>> 
>> I'm not sure if this is purely a configuration problem, wrt to 
>> policies or permissions or specifically to the RPi's architecture.

>Failing to get memory sounds like configuration regarding the memory allocators. I think there are specific options to select for this!

The is a partial snippet of the logging, I added additional debugging and grepped mmap:

06-04 13:46:26.475  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=28800 flags=3
06-04 13:46:26.476  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=28800 flags=3
06-04 13:46:26.476  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=28800 flags=3
06-04 13:46:26.476  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=28800 flags=3
06-04 13:46:26.476  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=28800 flags=3
06-04 13:46:26.561  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=307200 flags=3
06-04 13:46:26.561  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:233 Failed to mmap plane: Permission denied
06-04 13:46:26.640  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=307200 flags=3
06-04 13:46:26.641  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:233 Failed to mmap plane: Permission denied
06-04 13:46:26.673  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=307200 flags=3
06-04 13:46:26.673  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:233 Failed to mmap plane: Permission denied
06-04 13:46:26.706  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=307200 flags=3
06-04 13:46:26.706  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:233 Failed to mmap plane: Permission denied
06-04 13:46:26.742  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=307200 flags=3
06-04 13:46:26.743  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:233 Failed to mmap plane: Permission denied
06-04 13:46:26.772  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:226 mmap plane: len=307200 flags=3
06-04 13:46:26.772  3324  3326 E libcamera: ERROR Buffer mapped_framebuffer.cpp:233 Failed to mmap plane: Permission denied

Further investigation I discovered that the above error occurs while I'm streaming. So, it seems it is not the direct result of the "Capture Image" part.

>> Please help, I can rebuild and test.
>> 
>> I have tried the latest code pulled into RaspVanilla, but had the same 
>> issue.

>What is 'RaspVanilla' ?
https://github.com/raspberry-vanilla

As above I discovered that the "Permission denied" occur while streaming as well, therefor I'm now only reporting and will investigate further the cause of my error.
A sample logcat is attached, the crash occurred at around line 970.
Maybe someone can point me in the right direction.
I did report this initially to raspberrypi/libcamera.

Thanks for the reply!

--
Kieran
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logcat3
Type: application/octet-stream
Size: 199660 bytes
Desc: not available
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20240604/57cce6c3/attachment.obj>


More information about the libcamera-devel mailing list