Adding custom camera sensor to the kernel

Hello! I’ve been trying to develop IMX283 driver for TX2 Dev kit (for now) and I can’t understand some things:

So I’ve used IMX185 example from Nvidia’s Sensor Programming guide and it seems okay. The trouble is with compiling the driver. Nevertheless my questions are:

  1. IMX185 has 5 DTSI files (tegra186-camera-imx185-a00.dtsi, tegra186-quill-camera-imx185-a00.dtsi, tegra194-camera-imx185-a00.dtsi, tegra194-e3900-0000-camera-imx185-a00.dtsi, tegra194-p2822-0000-camera-imx185-a00.dtsi). Do I also need all 5 of them? I understand that TX2 is Tegra186 - so do I need only Tegra186 DTSI files? Why isn’t there only one device tree file?

  2. When I compile the kernel, I put all the files on the same folder, where there is IMX185 files and add Kconfig and Makefile lines. Is this the right way? It does compile imx283.o in the end, but it doesn’t compile imx283.ko, when I’m building modules (I don’t know if the .ko modules are needed). Do I have to copy the .o files to somewhere before I flash DTB and Kernel or what?

  3. Why does IMX185 create dtb files in $L4T_Source_Dir/build/arch/arm64/boot/dts/ but my IMX283 are not created. Is there anything else than Makefile and Kconfig where you have to set up your own camera?

  4. Which DTB do I exactly have to flash for TX2 Dev Kit?
    I read that there are 2 of them? tegra186-quill-p3310-1000-c03-00-base.dtb and tegra186-quill-p3310-1000-a00-00-base.dtb. Does the “base” include my IMX283 device tree on compilation?

  5. Am I doing the flashing correctly - it does flash, but when I check boot logs via UART0, basically nothing about my driver appears:
    sudo ./flash.sh -r -k kernel-dtb -d kernel/dtb/tegra186-quill-p3310-1000-c03-00-base.dtb jetson-tx2-devkit mmcblk0p1
    After this I obviously copy compiled Image file to TX2 Dev Kit /boot/ folder and restart.

Thanks in advance!

Hi @therealmatiss

Let me help answering your questions.

  1. To add a custom device-tree you can create one DTSI file for you sensor and modify the TX2-devkit main DTS (hardware/nvidia/platform/t18x/quill/kernel-dts/tegra186-quill-p3310-1000-a00-00-base.dts):
  • Remove the following lines:
    #include <t18x-common-platforms/tegra186-quill-camera-modules.dtsi>
    #include <t18x-common-plugin-manager/tegra186-quill-camera-plugin-manager.dtsi>

  • Add the sensor DTSI include, for example:
    #include <t18x-common-modules/tegra186-camera-imx283.dtsi>

  • On your sensor DTSI you should follow this structure:

/ {
	host1x {
		vi@15700000 {
			num-channels = <1>;
			ports {
                   ...
			};
		};

		nvcsi@150c0000 {
			num-channels = <1>;
			#address-cells = <1>;
			#size-cells = <0>;
			channel@0 {
                      ...
			};
		};
	};

	i2c@XXXXX {
		status = "okay";
		#address-cells = <1>;
		#size-cells = <0>;
		imx283@XX {
                   ...
	               mode0 {
                          ...
		           };

					ports {
						#address-cells = <1>;
						#size-cells = <0>;

						port@0 {
                                ...
						};
					};
		};
	};

/ {
	tcp: tegra-camera-platform {
		compatible = "nvidia, tegra-camera-platform";
        ...
		modules {
                  ...
		};
	};
};`

  1. If you enable your driver to be build as built-in, the *.ko will not be created. It will be part of your Kernel Image. This happens if in your menu config the driver is selected with <y>. To build it as kernel module, you should selected as <m>.

  2. To create a new DTB, you just need to add the DTS to hardware/nvidia/platform/t18x/quill/kernel-dts/ and modify Makefile file found in the same directory to add this new DTB. However, if you follow the recommendation for on step 1, you don’t need to create a new DTB, just modify the existing one.

  3. tegra186-quill-p3310-1000-a00-00-base.dtb. Following the approach of step 1, this device-tree will include your custom device-tree for the IMX283 support.

  4. To update:

  • Flash device-tree
    sudo ./flash.sh -k -r kernel-dtb -d kernel/dtb/tegra186-quill-p3310-1000-a00-00-base.dtb jetson-tx2 mmcblk0p1
  • Copy tegra186-quill-p3310-1000-a00-00-base.dtb and Image to /boot/
  • Copy kernel modules dir to /lib/modules/ (in case you compiled the driver as kernel module)
  • Note: If you are using an older version of JP.4.4, you need to flash the Kernel Image (copy doesn’t work).

I hope this helps,
-Enrique

1 Like

Thank you for your in-depth answer! Most of the things now I understand but I have some notes:

About flashing - when I do your command:
sudo ./flash.sh -k -r kernel-dtb -d kernel/dtb/tegra186-quill-p3310-1000-a00-00-base.dtb jetson-tx2 mmcblk0p1
it says that -r is not supported. So I was flashing without -r and it went well. Is that okay?

Also - even though I have TX2 Devkit, I have to flash jetson-tx2 and not jetson-tx2-devkit?

How can I test if the camera driver is loaded correctly?

Another question - which may be a bit different. After I compiled everything and checked the UART0 logs on boot, I noticed this:
[ 0.524854] i2c i2c-2: of_i2c: modalias failure on /i2c@3180000/tca9548@70
This has something to do with a problem on my device tree? And yes, there’s a multiplexer TCA9548.

EDIT: I forgot to ask: Do I have to remove other camera devices on make menuconfig? Because I can’t delete
#include <t18x-common-platforms/tegra186-quill-camera-modules.dtsi>
#include <t18x-common-plugin-manager/tegra186-quill-camera-plugin-manager.dtsi>
otherwise it won’t compile.

Thank you!

@therealmatiss

I’m sorry, the order is wrong. Test the following command:
sudo ./flash.sh -r -k kernel-dtb -d kernel/dtb/tegra186-quill-p3310-1000-a00-00-base.dtb jetson-tx2 mmcblk0p1

I have always used jetson-tx2 for devkit, but probably jetson-tx2-devkit could work too.

Check camera developer’s guide for information bout camera drivers:
https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/camera_dev.html#

Regarding your issues:
Can you share how are you defining the TCA9548 node on the device-tree?
Can you share the compilation errors?