Adding custom driver to Kernel locally

Hi,

we are planning on developing an FPGA firmware which will be connected to NVidia Jetson TX2 module via PCIe.
What is the proper way to add a customer driver to the Kernel build - as a driver? module?

Which portion of the device tree supposed to be modified?

Thanks,

Igal

hello igal.kroyter,

please referring to PLATFORM ADAPTATION AND BRING-UP GUIDE for more information.
you could access the documentation from [Release 28.1 Development Guide ]->[PDF Documents]->[Tegra Linux Driver Package TX2 Adaptation Guide]
thanks

@JerryChang, hi,

thanks for the reply.

I have read the document and could not find any data that I consider relevant, though I might be wrong.

I was looking for the following:

  1. A way to configure the device tree with a new PCIe driver.
  2. A way to add the driver to the kernel library directories
  3. A way to register the driver into the boot sequence

Is there some documentation that depicts the above or the above methodology is incorrect?

Thanks,

Igal

So far as actual procedure to modify a device tree goes there are differences in R28.1 versus earlier L4T releases (it used to be you could use the FDT entry of extlinux.conf, but this is no longer the case). If you are looking for just the procedure (without specific information on some part of a device tree), then the “Documentation” link talks about modifying device tree and parts of booting or kernel build in a generic way:
[url]https://developer.nvidia.com/embedded/linux-tegra[/url]

Be careful to note the “source_sync.sh” script for kernel download since it downloads some files which are part of Tegra kernel builds, but which are not directly in the kernel source tree. You’ll probably want to take a look at building an unmodified kernel via the source_sync.sh version, and only then moving on to customizing (the same Documentation URL in the above web page has information on that). Much of the kernel driver change part of your question is probably generic and not really hardware-dependent, so much of what you find on adding drivers on the internet will be valid.

So if " (it used to be you could use the FDT entry of extlinux.conf, but this is no longer the case)" how exactly do you specify a custom dtb with entries for your own drive/module?

@cobrien,

I am not sure, on other platform (MPSOC by Xilinx running Petalinux) I had to ad something like this under he amba bus:

mySymbolName:myModule@adress{
    compatible = "company,drivername";
    reg = < 0x0 0x1000000 0x0 0x1000 >; /* this defines the memory range where PCIe device mapped to relative to the CPU on a 64bit machine*/
    interrupt-parent = <&gic> /* defines the interrupt generator */
    interrupts = < 0 104 4>; /* interrupt identifiers */
    channel = <2>; /* some parameters pass to the driver */
}

but here it is a new world which is quite a puzzle to me as I do not know were exactly the above structure can be inserted and the exact definition.

Hope that some good people will assist…

thanks,

Igal

Sorry, I might not have been clear. I’m somewhat familiar with extending and modifying the .dts files,
my problem is getting the kernel to use my modified .dtb (binary) device tree file.

With older BSPs it seems it was possible to specify this in /boot/extlinux/extlinux.conf with A “FDT”
entry, but if I do this with R28.1, even though my device entry shows up, networking is disabled.

Searching the forums seems to indicate a) the FDT entry method doesn’t work any more, and
b) the DTB is in partition 15 of the internal flash. Unfortunately
this is not very flexible, since it isn’t on removable storage. (As it would be using the
extlinux.conf approach).

How u-boot locates this is also not clear, it doesn’t seem to be referenced in the uboot env
commands.

The goal is first to be able to rapidly and safely extend the device tree entry or entries for my driver during development and second to be able to occasionally, but reliably, update the dtb in the field.
Having only a single copy of the dtb is a bit of a risk.

I did find out why the FDT entry in /boot/extlinux/extlinux.conf doesn’t work any more (more
correctly why it breaks networking). Seems as if uboot puts a bunch of entries into the device
tree during the boot process:

serialnumber
ramoops_carveout.reg (no clue what this is)
bpmp.carveout.size
choosen.nvidia.ether-mac (this is probably what breaks ethernet)
… and others …

So it looks like the only way is to dd a modified dtb into /dev/mmcblk0p15.

Any other suggestions?

@linuxdev,

thanks for your advised. It worked.

Igal

FYI, the TX2 R28.1 way of flashing just the dtb is:

<s>sudo ./flash.sh -k -r kernel-dtbjetson-tx2 mmcblk0p1</s>
sudo ./flash.sh -r -k kernel-dtb jetson-tx2 mmcblk0p1

(EDIT: Corrected)

The mentioned Documentation download explains putting the dtb in place before running that command.

I think the flags are switched. I got …

DTBFILE=my_new_device_tree.dtb ./flash.sh -r -k kernel-dtb jetson-tx2 mmcblk0p1

to work though. Thanks, much faster than flashing the whole thing!

You are correct…I’ve edited the original to reflect this.

Any flash of the rootfs (even with a compressed/sparse image) is a couple of gigabytes or more…the other partitions are just a tiny drop in the bucket, so flashing those will be almost instant.