zhemao / zhemao.github.com

Github pages page
http://zhemao.github.com
Other
4 stars 1 forks source link

How to Build UVC with Linaro #4

Closed bangonkali closed 10 years ago

bangonkali commented 10 years ago

I have been working on OpenCV for a particular project. My intention is to do some hardware acceleration on some segments of the computer vision library. However as for the moment I'm still working on understanding everything in the Linux side.

I have followed the instructions on rocketboards regarding a Prebuilt image of Linaro for my SocKit. I was able to run the Linux in it. I then compiled the OpenCV library. However when I use my Logitech C525 WebCam it seems it is not detected. I have worked on a similar project on a purely ARM Board the CubieBoard and was successful in making OpenCV run on it with live video feed from the WebCam. However I have not been able to do some custom hardware acceleration because it has no FPGA component.

I thought maybe it's because UVC (USB Video Class) is not installed on the Example image from rocketboards. After a brief search on the internet it seems UVC can only be enabled during compilation of the Kernel. Because of this I began searching for information on the build procedure for Linux for my SocKit.

I have not been able to avail of the seminar/workshops provided by Arrow for SocKit because I'm from the Philippines. After my search it seems it has been your documentation and the from Rocketboards that really provides sufficient information. I'm hoping to ask if you could guide me in this process.

I was able to make Part 1, and Part 3, but only until "Programming the FPGA from HPS" on Part 3. I totally encountered an error on Part 2 but I will post the concerns on the error on Part 2 on a different issue because I believe it's a separate question.

However my ultimate concern for this issue is how do I enable UVC during compilation using Buildroot? Is it even supported? Thanks.

Note: This issues were originally posted at. Sorry for the repost. It took some time to realize all the other issues for the tutorials were here. You may close the issues on the duplicate.

zhemao commented 10 years ago

Hi Bangon. The UVC drivers can be compiled separately as a Linux kernel module and then loaded into the kernel. Otherwise, you can choose it as an option when building the kernel.

My advice to you will depend on which approach you want to take. Do you want to stick with Linaro, or do you want to try doing it with Buildroot? I think the former would be easier if you've already installed Linaro successfully on the board.

Also, if you are using Linaro Ubuntu, have you tried installing OpenCV through Ubuntu's package manager, apt-get? There are probably binary OpenCV packages available so that you don't have to build it from source. The package manager will probably also take care of installing dependencies like the UVC drivers for you.

bangonkali commented 10 years ago

I have a successful install of Linaro based on this article i think it's powered by Ubuntu since apt-get works. I used the prebuilt image. However, it seems not all apt-get 'package' works, only a select few. Perhaps this is a limitation for ARM. For OpenCV's case I had to build it along with the dependencies i required. I was able to make some of the example OpenCV libraries work, including facedetect.c with a jpeg image as an input. However, the main intention is to supply input using an off-the-shelf webcam. I think I have to follow the Linaro path.

Just to make it clear, Linaro is an organization which produces tools. One tool they have is the 'Linaro ARM toolchain' which is a cross compiler. With your statement 'Do you want to stick with Linaro?' what do you actually mean? It seems we're using the Linaro Tool chain while also using Buildroot in your tutorial Part 2.

How do you suggest I go about compiling UVC as a module to the Kernel and loading it?

zhemao commented 10 years ago

I meant do you want to stick with Linaro Ubuntu. Sorry, I should have been more clear. If you want to stick with Ubuntu, we can go with the kernel module approach. You can find basic information about building kernel modules here. I also have instructions for cross-compiling kernel modules for the Cyclone V in Part 4 of my tutorials.

If you check out the kernel sources from the rocketboards tutorial, you can probably find the UVC driver sources somewhere in the drivers directory. You'll want to compile the drivers using the directions in the articles I mentioned previously and then install the modules to your SD card.

I think an easier way, though, if you don't mind a longer wait, is to compile the entire kernel from source with the UVC video driver module enabled. That way you won't have to manually load it yourself after startup. The kernel build system allows you to configure what modules are selected using the command make menuconfig. I don't know what the specific option for the UVC video driver is, but I can figure it out for you once I get back to my home computer.

bangonkali commented 10 years ago

I tried the Kernel Module approach and tried downloading the kernel headers from within sockit. I am having problems because if i issue the command to get the headers, they are not found.

root@localhost:~/Downloads# apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-3.8.0-00111-g85cc90f
E: Couldn't find any package by regex 'linux-headers-3.8.0-00111-g85cc90f'

Also, it seems that the vesrion of Kernel I'm working on is not mainstream as suggested here. Is this fine?

Version
mainline: 3.13
stable: 3.12.8
stable: 3.11.10 [EOL]
longterm: 3.10.27
longterm: 3.4.77
longterm: 3.2.54
longterm: 3.0.101 [EOL]
longterm: 2.6.34.14
longterm: 2.6.32.61
linux-next: next-20140123

I think I have to consider your suggestion:

I think an easier way, though, if you don't mind a longer wait, is to compile the entire kernel from source with the UVC video driver module enabled

I think I'll have to do it this way instead. Using your Buildroot method, can I still have a package system like apt-get or yum? And will I be able to install a lightweigh GUI with mouse and keyboard support? Or if no, can I still compile most source from within sockit, or if i choose buildroot, is it way better to crosscompile?

I did try to find UVC from within make menuconfig but it seems I'm at loss where I can find it. It is still my first time working with it though. I'll be looking forward on your input.

zhemao commented 10 years ago

You don't need to use Buildroot in order to use a kernel built from source. You can still use Ubuntu. There are instructions for building the kernel in the rocketboards.org article you've been using for Ubuntu. You just need to copy the resulting uImage and kernel modules to the right places on the SD card. Menuconfig is really confusing if you don't know where to look. I'll try it on my own copy of the kernel once I get home.

zhemao commented 10 years ago

Okay, try this. In menuconfig, go to "Device Drivers" -> "Multimedia Support" and select "Cameras/video grabbers support". Then go down into "Media USB Adapters" and select "USB Video Class" as a module (should be an M in the selection box). Then build the kernel uImage, followed by the modules. The instructions for this are in Part 2 of my tutorials, specifically in step 4 and step 6. Skip step 5 since you are not using Buildroot.

bangonkali commented 10 years ago

This might sound really stupid, but I have to ask, where do i really run make menuconfig? Can i only run this from a buildroot folder?

bangonkali commented 10 years ago

Ok got it, Is it correct that I ran make menuconfig at linux-socfpga directory (the one cloned from github)?

zhemao commented 10 years ago

Yes. You will want to set the CROSS_COMPILE variable to the prefix for your cross-compiler though.

bangonkali commented 10 years ago

I issued the following command and was able to compile successfully.

armmake -j4 uImage LOADADDR=0x8000
armmake dtbs
armmake -j4 modules

On ~/.bashrc I have alias armmake='make CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm'/

Is it correct to assume that the next step is to replace the existing kernel on my sd card with this new one? Should I be skipping the parts that tell about formatting but instead overwrite files by copying?

sudo cp arch/arm/boot/uImage /mnt
sudo cp arch/arm/boot/dts/socfpga_cyclone5.dtb /mnt/socfpga.dtb
sudo make ARCH=arm INSTALL_MOD_PATH=/mnt modules_install

Also I'm currently still fixing the SDCard connection with my Ubuntu VirtualBox Machine. At least for the moment I'm doing all the compilation.

zhemao commented 10 years ago

Yes, that's correct, except when you install the modules, you need to install to the root filesystem (ext2 formatted), not the boot partition (FAT formatted). So you will need to unmount the FAT filesystem after copying the uImage and dtb and then mount the ext2 partition before installing the modules.

bangonkali commented 10 years ago

I just received another board. It seems i have made UVC with your recommendations.

root@localhost:~# v4l2-ctl --set-fmt-video=width=640,height=480,pixelformat=1
root@localhost:~# v4l2-ctl --set-parm=30
Frame rate set to 30.000 fps
root@localhost:~# v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
        Index       : 0
        Type        : Video Capture
        Pixel Format: 'YUYV'
        Name        : YUV 4:2:2 (YUYV)

        Index       : 1
        Type        : Video Capture
        Pixel Format: 'MJPG' (compressed)
        Name        : MJPEG

I just have one problem. If I use a USB Hub, the WebCam Logitech C525 can't be detected. If I use the WebCam alone connected to the USB OTG, the WebCam is detected. I also tried a USB Hub with an independent power supply, still to no avail. It seems I can not use WebCam with Keyboard and Mouse, only WebCam alone. If I use USB OTG + USB Hub, I can use Keyboard and Mouse but not with WebCam. Do you have any idea what might have gone wrong?

zhemao commented 10 years ago

Perhaps you need to enable another kernel module to handle the USB hub? Try gathering some more information first. Plug in the USB hub and webcam, then run lsusb to see what USB devices are detected, then run dmesg | grep usb to see the kernel messages being logged by the USB subsystem.

bangonkali commented 10 years ago

Thank you for your tips @zhemao, I used the tools you suggested to debug my way through the problem. I have tabulated the following scenarios:

================= TEST 01 ===================== TEST 01 =====================
otg->logitec c525 webcam                                      = works

================= TEST 02 ===================== TEST 02 =====================
otg->a4 tech hub 56 (4port, 2amp supply)->logitec c525 webcam = works

================= TEST 03 ===================== TEST 03 =====================
otg->a4 tech hub 56 (4port, 2amp supply)->logitec c525 webcam = does not work
                                        ->usb mouse           = works
                                        ->usb keyboard        = works

================= TEST 04 ===================== TEST 04 =====================
otg->a4 tech hub 56 (4port, 2amp supply)->a4 tech webcam      = to test soon
                                        ->usb mouse           = to test soon
                                        ->usb keyboard        = to test soon

I am looking forward to buy a4tech and other variants of webcam because it seems according to this link and this link, Logitech Products do not support USB Hubs or KVM switches.

Do you have any recommendation how may I put a USB 2.0 controller perhaps connected to the HSMC?

I will update the graphs above to reflect future tests.

zhemao commented 10 years ago

No, sorry. I don't know anything about HSMC peripherals.

bangonkali commented 10 years ago

Thanks for all the help with UVC @zhemao, I finally got it to work. I used Synergy to route a separate computer's mouse and keyboard to my SocKit's desktop UI. I was then able to have the USB OTG available for the WebCam and for the WebCam only while still being able to navigate through the desktop. The next part is to find some way to accelerate some algorithms in OpenCV that can be implemented on the FPGA. This specific issue can probably be closed now.

zhemao commented 10 years ago

Wow! :clap: :clap: :clap: That's pretty cool. Glad you could get it working. Cool videos by the way. Good luck with the rest of your project.