Compiling a Linux Kernel for DUO3D Arm Module/Driver

As part of their developer program ($95 per year @ https://duo3d.com/program/developers), Code Laboratories provides a kernel level driver source for their DUO cameras that can be compiled on an embedded Linux kernel. This compilation produces a .ko file that can be inserted into the kernel (the level of the operating system that handles communication between the user and the user interface and the actual physical components of the system, such as the DUO camera and USB drives) to drive the camera on almost any embedded Linux device (although only some are powerful enough to run the camera). Here, we will go over the general method of compiling these DUO drivers, although I will be using the Odroid XU3, one of the boards that Code Laboratories recommends. It is important to note that, in our experience, boards like the Beaglebone and the Raspberry Pi, while useful in their own right, are not powerful enough to run a DUO camera in any useful capacity. We recommend using the Odroid XU3 as it is the smallest of Code Laboratory's recommended boards or another of their recommended boards, like the Nvidia Jetson.

After applying for Code Laboratory's developer program, you should be able to download a from your account page a special package of DUO software for arm under the section DUO Developers. Store this in your user profile folder (/home/[user] or simply ~) on your Linux device. Inside the folder should be a readme file with specific instructions on how to compile the driver for the Nvidia Jetson. These instructions are pretty close to universal, but not quite.

The next step is to get the latest kernel source for your device. Many companies, like Odroid, distribute custom kernel sources for each of their devices (the Odroid XU3 Linux Ubuntu source can be found here: https://github.com/hardkernel/linux/tree/odroidxu3-3.10.y and can be downloaded using the command:

git clone --depth 1 https://github.com/hardkernel/linux.git -b odroidxu3-3.10.y

in the directory in which you want to download it [we recommend ~ also]). The latest Linux kernels can be found here 

Make sure you get one that is right for your device. This may require using google on your part, but any documentation for your device should include a location for the kernel source. Once you have the source, take a look at the readme provided by Code Laboratories (CL). you can largely ignore the prerequisites as most systems embedded have GCC compilers and debuggers. You also don't need QT, Cmake or opencv unless you are planning on compiling CL's examples. Start by following their example and cd-ing into your kernel source directory, which, if you used the command above to get your kernel, would be 

 cd odroidxu3-3.10.y

You now have to configure your kernel. The kernel has thousands of configuration files for different systems. For the Odorid XU3, you can use make odroidxu3_defconfig to configure the kernel. Otherwise, you can look for a similar command for your own kernel online or use make menuconfig or make oldconfig to configure manually. 

Next, follow steps two and three as laid out by CL's readme. You don't have to use gedit to edit the file you are patching but can replace it with "nano," a more common but less robust utility, and then use ctrl + W to search for the lines they want you to comment out.

Now you're ready to make your kernel. Enter these commands in succession, waiting for each to finish (which may take a while) before entering the next. NOTE: the -j switch specifies the number of cores you wish to use while compiling the kernel. The number you pass it is 1 + the number of cores you want to use. The Odroid XU3 has 8 cores, so use 9 for the maximum compilation power.

make zImage -j9 

make modules

make modules_install

Before you do anything else, check the output of the command uname -r and record it. This is your current kernel version and you will want to check if it has updated. Now follow the last command in step 5 of the CL instructions to copy the newly generated zImage from the kernel source to your devices boot directory. Before you do this, you may want to do some searching to make sure that this is where you need to move your zImage (it sometimes depends on the device or on the version of the kernel). 

Now restart your device and again execute the command uname -r to check if your kernel version now matches that of the one you downloaded and patched. If it does not, you may have put the zImage in the wrong directory. 

Next, cd into the DUODrivers directory in the file you downloaded from CL. There are three files of interest: InstallDriver, LoadDriver, and UnloadDriver. Run the command: chmod +x targeting all three of these files, then ./ the first two to load your driver and ensure that it loads whenever you start your device. To check if it has loaded, verify the duo0 node is in the /dev diectory and run the command  lsmod to list active modules. Look for the duo module there. If this all checks out, you should be all set.

Finally, make sure you copy the libDUO.so library into the /usr/lib directory as the linker needs to know where this library is at run-time.

And that's it! The kernel is now compiled. 

No comments:

Post a Comment