Search code examples
linuxlinux-kernellinux-device-driverdevice-tree

How to change the name of a label in a linux device tree?


I am building my own kernel. The device tree of the kernel is modified, because of an own designed mainboard.

I can enable the can devices by:

// here ATMEL is defining the can0 and can1 memory mapped devices
#include "sama5d3_can.dtsi"
...
can0: can@f000c000 {
    status = "okay";
};
can1: can@f8010000 {
    status = "okay";
};          

But now I want to switch the names of them. Can0 should become can1 and can1 should be can0.

How to do that? PS: the error print when switching the labels and building the kernel:

| ERROR (duplicate_label): Duplicate label 'can0' on /ahb/apb/can@f8010000 and /ahb/apb/can@f000c000
| ERROR (duplicate_label): Duplicate label 'can1' on /ahb/apb/can@f8010000 and /ahb/apb/can@f000c000

Solution

  • The network "devices" do not take their name from the DTS at all. They get it from the name that is given to the netdevice.name.

    In your case, the at91_can.c driver calls alloc_candev() that explicitely sets the interface's name to can%d (can0, can1, ...). The number "assigned" to each device in then strictly dependant on the sequence of the "enumeration" of the hardware and its registration with the at91_can driver.

    Changing the device tree will not help you in changing the name of the network interfaces. If you really need to change the name of the can interfaces, you could write udev rules that do so.