Back to Blog

TI AM5728 SDK Upgrade: Linux Device Tree Parsing, Taking the Network Port CPSW as an Example

#DTS#DTB#AM5728#DeviceTree

TI AM5728 SDK Upgrade: Linux Device Tree Parsing, Taking the Network Port CPSW as an Example

When working with Linux-based embedded systems, understanding the Linux device tree (DT) is crucial for device initialization and configuration. In this article, we will explore the Linux device tree parsing process, focusing on the network port CPSW (Common Platform Ethernet Switch) as an example.

What is the Linux Device Tree?

The Linux device tree is a data structure that describes the hardware components of a system, including their properties and relationships. It is used by the Linux kernel to initialize and configure devices during boot. The device tree is represented as a hierarchical structure, with nodes representing devices and properties representing their characteristics.

Device Tree Compilation

There are two ways to compile the device tree:

  1. Copy the device tree file to the kernel source code directory arch/<processor_platform>/boot/dts/<manufacturer>/ and execute make dtbs.
  2. Use the dtc tool to compile the device tree file: dtc -I dts -O dtb *.dts > my.dtb

Device Tree Reverse Compilation

To reverse compile the device tree file, use the dtc tool: dtc -I dtb -O dts *.dtb > my.dts

SDK Upgrade Device Tree Network Port CPSW Debugging

When upgrading the TI SDK from Linux kernel 4.4 to 4.14, we encountered an issue where the network port CPSW was not recognized. After analyzing the device tree descriptions for both kernel versions, we found that the main difference was in the reg property.

In the 4.4 kernel version, the reg property was set to a specific value, whereas in the 4.14 kernel version, the reg property was set to a different value that matched the specific hardware configuration.

To resolve the issue, we modified the reg property in the device tree file to match the specific hardware configuration. After making the changes, we were able to see the network address.

Example Device Tree File

Here is an example device tree file for the TI AM335x CPSW:

&cpsw {
    compatible = "ti,cpsw";
    ti,hwmods = "cpgmac0";
    clocks = <&cpsw_125mhz_gclk>, <&cpsw_cpts_rft_clk>;
    clock-names = "fck", "cpts";
    cpdma_channels = <8>;
    ale_entries = <1024>;
    bd_ram_size = <0x2000>;
    no_bd_ram = <0>;
    rx_descs = <64>;
    mac_control = <0x20>;
    slaves = <2>;
    active_slave = <0>;
    cpts_clock_mult = <0x80000000>;
    cpts_clock_shift = <29>;
    reg = <0x4a100000 0x800>;
    #address-cells = <1>;
    #size-cells = <1>;
    interrupt-parent =<&intc>;
    interrupts = <40 41 42 43>;
    ranges;
    davinci_mdio: mdio@4a101000 {
        compatible = "ti,davinci_mdio";
        #address-cells = <1>;
        #size-cells = <0>;
        ti,hwmods = "davinci_mdio";
        bus_freq = <1000000>;
        reg = <0x4a101000 0x100>;
    };
    cpsw_emac0: slave@4a100200 {
        /* Filled in by U-Boot */
        mac-address = [0000 00 00 00 00];
    };
    cpsw_emac1: slave@4a100300 {
        /* Filled in by U-Boot */
        mac-address = [0000 00 00 00 00];
    };
    phy_sel:cpsw-phy-sel@44e10650 {
        compatible = "ti,am3352-cpsw-phy-sel";
        reg = <0x44e10650 0x4>;
        reg-names = "gmii-sel";
    };
};

Conclusion

In this article, we explored the Linux device tree parsing process, focusing on the network port CPSW as an example. We discussed the device tree compilation and reverse compilation processes, as well as the device tree debugging process. We also provided an example device tree file for the TI AM335x CPSW. By understanding the Linux device tree and its properties, developers can better configure and initialize devices in their embedded systems.