How to compile dtsi for sensor driver development

Hi everyone, I want to add new sensor with MIPI-CIS connector. I have read “Tegra Linux Driver” document that have an chapter “Camera Modules and Device Tree”. That chapter tell me which file I need make, some .c,.h,.dtsi, but it doesn’t show me how to make them work. May be that’s some basic knowledge of Linux development but I mostly develop window application and driver. So my question is:

  1. How to compile dtsi file? I know use dtc command and use CPP to solve the problem of ‘#include’, but compile still fail with ‘syntax error FATAL ERROR: Unable to parse input tree’.
    Actually I didn’t add or change any code, just want to try the code of Sony IMX219.
    I found tegra210-camera-rbpcv2-imx219.dtsi include by tegra210-porg-p3448-common.dtsi that include in tegra210-p3448-0000-p3449-0000-a00.dts (that in directory /public_sources/hardware/nvidia/platform/t210/porg/kernel-dts). So I try below script to compile…
device="tegra210-p3448-0000-p3449-0000-a00"
src_dts=$device.dts
tmp_dts=$device.tmp.dts
dst_dtb=$device.dtb

cpp -nostdinc -I. \
              -isystem /home/leon/Downloads/public_sources/hardware/nvidia/platform/t210/common/kernel-dts \
              -isystem /home/leon/Downloads/public_sources/hardware/nvidia/soc/t210/kernel-dts \
              -isystem /home/leon/Downloads/public_sources/hardware/nvidia/soc/tegra/kernel-include \
              -undef -x assembler-with-cpp $src_dts > $tmp_dts

dtc -I dts -O dtb -b 0 -o $dst_dtb $tmp_dts
rm $tmp_dts

but fail… I don’t know what’s meaning about the error code

leon@leon-ubuntu:~/Downloads/public_sources/hardware/nvidia/platform/t210/porg/kernel-dts$ ./dts2dtb.sh 
Error: /home/leon/Downloads/public_sources/hardware/nvidia/platform/t210/common/kernel-dts/t210-common-platforms/tegra210-common.dtsi:0.136-137 syntax error
FATAL ERROR: Unable to parse input tree
  1. Another question is if I succeeded compile driver code(.c,.h file) and .dtsi file, e.g. got imx219.ko and tegra210-p3448-0000-p3449-0000-a00.dtb. Does the new driver will work if I overlay old files of ubuntu and reboot it?? If don’t work how should I do?

I’m appreciated for any help

Hi zhaoxiang,

If you need to compile Kernel and Device-tree, I suggest you to follow this guide:
[url]https://developer.ridgerun.com/wiki/index.php?title=NVIDIA_Jetson_Nano_-_Building_the_Kernel_from_Source[/url]

You need to install the toolchain, sources and the rest of dependencies and compile the sources from a host linux-system. The you need to flash the new images in your Jetson system.

You can access the Kernel sources and make changes in the drivers and the build a new image.

Regards,
-Enrique

Hi Enrique,

Thanks for your reply.
Do you mean if I want to add a new sensor with MIPI-CIS connector I must compile kernel and flash image?

I used to thought new driver could work if I just compile driver and dtsi file and copy them to system directory.

Regards

Hi zhaoxiang,

For older JetPack versions, the device-tree could be updated by just copying it in the right directory and rebooting the system.
However, to update the device-tree in JetPack-4.2, it’s needed to flash it into the right partition using the flash.sh script or performing the procedure described here: [url]How to build NVIDIA Jetson Nano kernel - RidgeRun Developer Connection

Regarding the driver, if you already have a Kernel module compiled, it should work when you load it. However, the default JetPack-4.2 image created for Jetson-Nano is been configured with the IMX219 driver enabled as built-in, so I think you will face compatibility issues if you try to load your imx219.ko module without disabling the built-in driver.

You can try loading your imx219.ko module and see if it works. If it failed, I recommend you to compile Kernel sources to disable the IMX219 built-in driver to load the module, or modify this driver according to your needs.

Regards,
-Enrique

Hi Enrique,

These days I modified imx219.c and tegra210-camera-rbpcv2-imx219.dtsi and compile kernel follow the guide. When I flash DTB use command of section “Flash custom DTB on the Jetson Nano”, it’s work.

But When I flash kernel image follow steps of section “Flash Custom Kernel Image”, after reboot there is an error when booting: “[FAILED] Failed to start Resize SD Card root partition and filesystem.” and halted with “Host read timeout at address 5458045c” print

I don’t know what’s wrong. Do I miss any step?

Thanks & Regards

I lost one step…

Execute the following commands to install the kernel modules:
$ sudo make ARCH=arm64 O=$TEGRA_KERNEL_OUT modules_install
INSTALL_MOD_PATH=Linux_for_Tegra/rootfs/

Hi zhaoxiang,

Were you able to compile the sources and flash the Jetson Nano?