raspberrypi / linux

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/
Other
11.22k stars 5.02k forks source link

TFTP/NFS booted Pi 3 Model B+ locks up when using official V4L2 driver #2963

Open jorisvervuurt opened 5 years ago

jorisvervuurt commented 5 years ago

When booting a Raspberry Pi 3 Model B+ via TFTP/NFS (no SD card), there seems to be an issue with the official V4L2 driver. When trying to access /dev/video0, the entire Pi locks up.

I have the following setup:

I have configured a number of VLANs on the EdgeRouter X:

The Synology NAS acts as a TFTP server for the boot files and NFS server for the root filesystem; bootcode.bin is in the TFTP root directory, the rest of the boot files are in the <serial>/ directory. I have configured the Ubiquiti router’s DHCP server to add option 43 and provide the correct IP to the TFTP server. Booting the Pi from the NAS works perfectly fine without any errors. I’ve edited /etc/fstab to mount the <serial>/ boot file directory as /boot (this allows me to edit the boot files from the network-booted Pi).

I have added bcm2835-v4l2 to the /etc/modules file. After a reboot, /dev/video0 is available so it appears the V4L2 driver has loaded correctly.

I use v4l2rtspserver to serve an RTSP stream of /dev/video0, which works perfectly fine when the Pi is booted from an SD card (both the boot files and the root filesystem). As soon as I switch to full TFTP/NFS boot without an SD card, executing v4l2rtspserver completely locks up the Pi.

I've compiled and installed v4l2rtspserver as follows:

sudo apt-get install git cmake
git clone https://github.com/mpromonet/v4l2rtspserver.git
cd v4l2rtspserver && cmake . && make
sudo cp v4l2rtspserver /usr/local/bin/
cd .. && rm -rf v4l2rtspserver

This is where things become weird, because raspivid seems to work just fine. After running raspivid, the v4l2rtspserver command works just fine as well... I’ve tried running sudo rpi-update (and of course replaced the bootcode.bin file in the TFTP root directory) but unfortunately that didn't fix the issue either.

I then came across these two issues on GitHub: https://github.com/raspberrypi/linux/issues/2335 https://github.com/raspberrypi/linux/issues/2528

So, I created bcmhi.c with the following content:

#include "bcm_host.h"

int main(int argc, char* argv)
{
  bcm_host_init();
  return 0;
}

I then compiled it using sudo gcc bcmhi.c -I/opt/vc/include -L/opt/vc/lib -lbcm_host -o /usr/local/bin/bcmhi. When I executed bcmhi && v4l2rtspserver, the Pi no longer locked up and everything worked as it should (even after a reboot without running raspivid first).

So, in short, the issue is that bcm_host_init() needs to be called before /dev/video0 is usable. However, the weird thing is that this is only needed when the Pi is booted from TFTP/NFS without an SD card.

6by9 commented 5 years ago

As requested in the template for issues, please provide your kernel and firmware version.

System Copy and paste the results of the raspinfo command in to this section. Alternatively, copy and paste a pastebin link, or add answers to the following questions:

The fix for #2335 and #2528 was merged May 2018 so I was believing the issue was resolved.

jorisvervuurt commented 5 years ago

Thanks for your reply. Here’s the info you requested:

The issue as mentioned in the other threads indeed seems to be fixed, as loading the module (either via modprobe or via /etc/modules) no longer locks up the Pi. This issue however, seems to be somewhat related to the other two issues (same bcm_host_init() workaround)...

Thanks again!

vintozver commented 5 years ago

Having the same issue on both 3B and 3B+ (latest raspbian/kernel as of today)

alkisg commented 4 years ago

I too have the same issue on both rpi2 and rpi3b+, but not on rpi4. I commented on the "original thread" at https://github.com/raspberrypi/linux/issues/2335#issuecomment-576011598.

JamesH65 commented 4 years ago

@alkisg Are you using the latest Raspbian Buster?

alkisg commented 4 years ago

@JamesH65, I had the latest Raspbian Buster when I commented 25 days ago.

If I recall correctly, there was a kernel update since then, do you want me to test with that one too?

JamesH65 commented 4 years ago

So still present with that Buster then, might be worth am apt full-upgrade but suspect it's still broken. Thanks for the report.

alkisg commented 4 years ago

@JamesH65, I just ran apt full-upgrade in my Buster installation and I cannot reproduce this anymore with the latest 4.19.97-v7+ kernel. I tested 3 boots on an rpi3b+ and 2 boots on an rpi2. They booted fine over NFS-RW without having to specify modprobe.blacklist=bcm2835_v4l2 in cmdline.txt.

Thanks a lot, seems like problem solved; hopefully the others will confirm it as well.

JamesH65 commented 4 years ago

Great, will give it a few days, if nothing bad turns up, will close.