How to add a driver on Xavier NX

I add a simple linux driver on Xavier NX, but probe function of the driver can not enter.

Test steps are follow:

  1. add the test driver source file to /sources/kernel/kernel-4.9/drivers/gpio/

static int robot_ctrl_probe(struct platform_device *pdev)
{
printk(“robot_ctrl_probe enter\n”); // —> this log is not printed
return 1;
}

static struct of_device_id robot_match_table = {
{ .compatible = “test,nx_gpio”,},
{},
};

static struct platform_driver robot_gpio_driver = {
.driver = {
.name = “robot_gpio”,
.owner = THIS_MODULE,
.of_match_table = robot_match_table,
},
.probe = robot_ctrl_probe,
};

static int robot_gpio_init(void)
{
printk(“robot_gpio_init() enter\n”); // —> this log is printed
return platform_driver_register(&robot_gpio_driver);
}
module_init(robot_gpio_init);

  1. add device tree definition in /sources/hardware/nvidia/platform/t19x/jakku/kernel-dts/common/tegra194-p3668-common.dtsi

    gpio_common {
    compatible = “test,nx_gpio”;
    status = “okay”;
    };

  2. bulid kernel success and replace Image & tegra194-p3668-all-p3509-0000.dtb files on the NX device

  3. this driver test OK on the other linux platform.

Question

  1. What causes the probe function not to enter?
  2. Is this DTSI file for NX platform?

hello liangs,

you could check the flash messages for correct dtb files used by NX platform.
for example,

[ 464.1538 ] Writing partition kernel-dtb with tegra194-p3668-all-p3509-0000_sigheader.dtb.encrypt
[ 464.1617 ] [................................................] 100%

please also check CBoot session, you might refer to [Kernel Boot Sequence Using extlinux.conf] for loading kernel and kernel-dtb binary file from configuration file.
thanks

Hello Jerry,

I try to use flash.sh tool to update kernel & dtb file on NX device, but failed.

Test steps are follow:

  1. build kernel successfully.

  2. copy kernel-4.9/out/arch/arm64/boot/Image to /Linux_for_Tegra/kernel/

  3. copy kernel-4.9/out/arch/arm64/boot/dts/tegra194-p3668-all-p3509-0000.dtb to /Linux_for_Tegra/kernel/dtb/

  4. update kernel image
    $sudo ./flash.sh -k kernel jetson-xavier-nx-devkit mmcblk0p1

log:
。。。。。
[ 9.3823 ] Writing partition
[ 9.3837 ] tegradevflash_v2 --write kernel 1_boot_sigheader.img.encrypt
[ 9.3852 ] Bootloader version 01.00.0000
[ 9.3871 ] Writing partition kernel with 1_boot_sigheader.img.encrypt
[ 9.3878 ] […] 100%
[ 18.7184 ]
[ 18.7187 ] Coldbooting the device
[ 18.7214 ] tegrarcm_v2 --ismb2
[ 18.7260 ]
[ 18.7290 ] tegradevflash_v2 --reboot coldboot
[ 18.7317 ] Bootloader version 01.00.0000
[ 18.7346 ]
*** The [kernel] has been updated successfully. ***

  1. update dtb
    $sudo ./flash.sh -k kernel-dtb jetson-xavier-nx-devkit mmcblk0p1

log:
。。。。。
[ 7.7939 ]
[ 7.7940 ] Writing partition
[ 7.7967 ] tegradevflash_v2 --write kernel-dtb 1_tegra194-p3668-all-p3509-0000_sigheader.dtb.encrypt
[ 7.7993 ] Bootloader version 01.00.0000
[ 7.8018 ] Writing partition kernel-dtb with 1_tegra194-p3668-all-p3509-0000_sigheader.dtb.encrypt
[ 7.8034 ] […] 100%
[ 9.1134 ]
[ 9.1136 ] Coldbooting the device
[ 9.1167 ] tegrarcm_v2 --ismb2
[ 9.1217 ]
[ 9.1247 ] tegradevflash_v2 --reboot coldboot
[ 9.1278 ] Bootloader version 01.00.0000
[ 9.1313 ]
*** The [kernel-dtb] has been updated successfully. ***

  1. cat /proc/version, But the kernel version is not update.

  2. ls /proc/device-tree/, But can not find “test,nx_gpio” device string

hello liangs,

it looks we could also reproduce the same issue locally, even using -k options to update kernel and kernel-dtb partition successfully but it did not actual update.
could you please replace below files with your customize files, and reboot the system make the change takes effect.
for example,

# When testing a custom kernel, it is recommended that you create a backup of
# the original kernel and add a new entry to this file so that the device can
# fallback to the original kernel. To do this:
#
# 1, Make a backup of the original kernel
#      sudo cp /boot/Image /boot/Image.backup
#
# 2, Copy your custom kernel into /boot/Image
#
# 3, Uncomment below menu setting lines for the original kernel
#
# 4, Reboot

you should also modify /boot/extlinux/extlinux.conf to add FDT path for kernel-dtb update.
thanks

hello liangs,

please refer to CBoot session, you should check the kernel boot sequence which refer to extlinux.conf file.
for example,
if you’re using flash.sh -k kernel commands to update kernel partition, you should delete LINUX entry extlinux.conf, hence the kernel binary would loaded from the kernel partition instead.
there’s on FDT entry by default extlinux.conf file, the kernel-dtb binary is loaded from the kernel-dtb partition.
thanks

The issue is solved,thanks!