5

I am trying to understand the following snippet from a DTS file.

/dts-v1/;

/ {
    model = "MPC8313ERDB";
    compatible = "MPC8313ERDB", "MPC831xRDB", "MPC83xxRDB";
    #address-cells = <1>;
    #size-cells = <1>;

    aliases {
        ethernet0 = &enet0;
        serial0 = &serial0;
        serial1 = &serial1;
        pci0 = &pci0;
    };

What does the aliases part does?
My understanding is as follows.
For ethernet0, we can use enet0.
But why serial0=&serial0?
and serial1 = &serial1
Can anyone brief please?

Thanks.

TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
New to Rails
  • 2,824
  • 5
  • 27
  • 43

1 Answers1

12

In the aliases section of a DTS, we see entries of the format

property = &label;

Each of the entries consists of :
a. property -- A new property defined here.
b. &label -- Complete DTS path to the node referenced by the label.

It basically assigns the value of b to a. Henceforth, the long-name to the node identified by the label can be accessed using the shorthand property.

Note that the RHS of this assignment is using labels and NOT the short-names of the individual nodes. Just like a label in C code refers to an instruction on the line where it is defined, a label in DTS refers to the individual node (using its complete long path) that is defined on that line.

For example, considering the following DTS,
lxr.free-electrons.com/source/arch/powerpc/boot/dts/mpc8313erdb.dts

whose aliases section consists of the following :

 20         aliases {
 21                 ethernet0 = &enet0;
 22                 ethernet1 = &enet1;
 23                 serial0 = &serial0;
 24                 serial1 = &serial1;
 25                 pci0 = &pci0;
 26         };

The newly defined properties (LHS)

  • ethernet0
  • ethernet1
  • serial0
  • serial1
  • pci0

refer to the corresponding labels (RHS)

For example, the property ethernet0 is now set to "/soc8313@e0000000/ethernet@24000" i.e. the node defined on the line where the label enet0 is defined.


UPDATE :

  1. Why are aliases defined ONLY for ethernet0, serial0 ... ?

    • Further down the line, the developer intends to access these nodes in the kernel source code. Once an alias is defined in the DTS, a handle to the node it is referring to is obtained by simply searching for it in the aliases section rather than searching for it in the entire DTS.

      Source: The function find_node_by_alias() in the Linux kernel source.

  2. Why pci0 node in NOT under the soc8313 node?

    • On MPC8313, the PCI and DMA blocks are interfaced via the IO-Sequencer(IOS). Hence the special treatment as compared to the other blocks (ethernet, I2C, UART) that are connected directly to the system bus.
TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
  • Thank you so much TheCodeArtist for rescuing me again. Now I understand they are more like the aliases we set in unix shell to refer to complete path. mpc8313erdb.dts is the exact dts file I am investigating. You are my saviour. Why are we defining aliases only for ethernet0 = &enet0; serial0 = &serial0; serial1 = &serial1; pci0 = &pci0; And pci0 is not under soc. – New to Rails Jul 19 '13 at 11:17
  • In my dts file pic0 is set to "/pci@e0008500" ? What is the need to do this? – New to Rails Jul 19 '13 at 12:20
  • I have updated the answer with details. While i am unable to find the exact location where `pci0` is referenced in code i did find one for `ethernet0` **[here](http://lxr.free-electrons.com/source/arch/powerpc/boot/cuboot-83xx.c#L27)**. Studying that function's internals should help you understand and appreciate the beauty of device-tree. – TheCodeArtist Jul 19 '13 at 13:30
  • Holy cow.. TheCodeArtist you just know everything. Thank you so much. – New to Rails Jul 19 '13 at 13:47
  • How did you find the function using the aliases? " find_node_by_alias()" and the node where "ethernet0" is referenced? Grepped "ethernet0"? Can you kindly share? I would like to know. And where do you get the explanation of the DTS file. I am trying to reverse engineer the whole file. I am referring to http://devicetree.org/Device_Tree_Usage and https://www.power.org/documentation/epapr-version-1-1/ Can you kindly share your resources? – New to Rails Jul 19 '13 at 13:54
  • Yup, you are **absolutely** right - grep-ing `ethernet0` inside `arch/powerpc` and following the chain of function calls [all the way down](http://lxr.free-electrons.com/source/arch/powerpc/boot/ops.h#L171). Here is a **[series of articles](http://xillybus.com/tutorials/device-tree-zynq-1)** explaining the basics of device-tree. – TheCodeArtist Jul 19 '13 at 14:01
  • Thank you so much friend. You are amazing. Thanks for sharing the technique and the link. – New to Rails Jul 19 '13 at 20:04