Personal tools

How to customize Debian 9.2 device tree

From SomLabs Wiki

Jump to: navigation, search

How to customize Debian 9.2 device tree



Sl wiki new version 600x180.jpg


Linux version 3.5.7 and newer include a new feature - device trees, they represent connections and structure of the machine it is run on. Modules used in earlier kernels are replaced with Device Tree Blobs (DTB).

We recommend Ubuntu 16 x64 on host PC for customizing Device Tree. Before customizing the device tree you need to download and install VisionSOM-6ULL rootfs image and run it on your host system:

jz@ubuntu:~$ sudo apt install qemu-user-static
jz@ubuntu:~$ wget http://ftp.somlabs.com/somlabs-visionsom-6ull-debian-rootfs-qemu.tar.xz
jz@ubuntu:~$ sudo tar -xvf somlabs-visionsom-6ull-debian-rootfs-qemu.tar.xz
jz@ubuntu:~$ sudo cp /etc/hostname ~/somlabs-debian/etc/hostname
jz@ubuntu:~$ sudo cp /etc/hosts ~/somlabs-debian/etc/hosts
jz@ubuntu:~$ sudo ./somlabs-debian/chtoolchain

Before customizing your device tree for the first time you must build the kernel, to do that enter proper directory, copy default configuration and run make:

root@ubuntu:~$ cd /home/developer/source/kernel/linux-rel_imx_4.1.15_2.1.0_ga
root@ubuntu:/home/developer/source/kernel/linux-rel_imx_4.1.15_2.1.0_ga# cp /home/developer/source/somlabs-dts-1.0/visionsom-6ull-linux_defconfig /home/developer/source/kernel/linux-rel_imx_4.1.15_2.1.0_ga/.config
root@ubuntu:/home/developer/source/kernel/linux-rel_imx_4.1.15_2.1.0_ga# make deb-pkg -j8 CFLAGS_MODULE=-fno-pic

Now you can modify the device tree file:

root@ubuntu:~$ nano /home/developer/source/somlabs-dts-1.0/somlabs-visionsom-6ull.dts

Adding new interface definition usually requires two steps, first you need to add interface to the device tree, for example the code below activates I2C interface:

&i2c2 {
        clock_frequency = <100000>;
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_i2c2>;
        status = "okay";
};

Second step is iomux pins definition (pinctrl_i2c2):

&iomuxc {
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_hog_1>;
        imx6ul-evk {
  
                ...
                ...

                pinctrl_i2c2: i2c2grp {
                        fsl,pins = <
                                MX6UL_PAD_UART5_TX_DATA__I2C2_SCL 0x4001b8b0
                                MX6UL_PAD_UART5_RX_DATA__I2C2_SDA 0x4001b8b0
                        >;
                }
                
                ...
                ...
                
};

Pin definition has three parts, first is the physical pad name (for example MX6UL_PAD_UART5_RX_DATA__I2C2_SDA 0x4001b8b0), second one is selected pin function (for example MX6UL_PAD_UART5_RX_DATA__I2C2_SDA 0x4001b8b0). All possible combinations are defined in /home/developer/source/kernel/linux-rel_imx_4.1.15_2.1.0_ga/arch/arm/boot/dts/imx6ul-pinfunc.h. The third part (for example MX6UL_PAD_UART5_RX_DATA__I2C2_SDA 0x4001b8b0) can be used to perform additional pin configuration, its bits are defined as follows:

PAD_CTL_HYS                     (1 << 16)
PAD_CTL_PUS_100K_DOWN           (0 << 14)
PAD_CTL_PUS_47K_UP              (1 << 14)
PAD_CTL_PUS_100K_UP             (2 << 14)
PAD_CTL_PUS_22K_UP              (3 << 14)
PAD_CTL_PUE                     (1 << 13)
PAD_CTL_PKE                     (1 << 12)
PAD_CTL_ODE                     (1 << 11)
PAD_CTL_SPEED_LOW               (0 << 6)
PAD_CTL_SPEED_MED               (1 << 6)
PAD_CTL_SPEED_HIGH              (3 << 6)
PAD_CTL_DSE_DISABLE             (0 << 3)
PAD_CTL_DSE_260ohm              (1 << 3)
PAD_CTL_DSE_130ohm              (2 << 3)
PAD_CTL_DSE_87ohm               (3 << 3)
PAD_CTL_DSE_65ohm               (4 << 3)
PAD_CTL_DSE_52ohm               (5 << 3)
PAD_CTL_DSE_43ohm               (6 << 3)
PAD_CTL_DSE_37ohm               (7 << 3)
PAD_CTL_SRE_FAST                (1 << 0)
PAD_CTL_SRE_SLOW                (0 << 0)

You can also use 0x80000000 value, then default pin configuration will be used.

After you finish customization you can create Debian package:

root@ubuntu:~$ cd /home/developer/source/somlabs-dts-1.0/
root@ubuntu:/home/developer/source/somlabs-dts-1.0# dpkg-buildpackage -us -uc

If you enabled SSH access for root on your target board then you can upload package via SCP:

root@ubuntu:~$ scp /home/developer/source/somlabs-dts_1.0.0_armhf.deb root@<TARGET_IP>:/root/

You can also use any other method to put the file in your target system.

Now install package on your target system:

root@somlabs:~# dpkg -i /root/somlabs-dts_1.0.0_armhf.deb

Reboot target system, after reboot new device tree will be used.

NOTE! It is strongly recommended to check startup messages after loading the device tree. If one of I/O lines is requested by more than one driver then you will get message like the one below:

[    0.322774] imx6ul-pinctrl 20e0000.iomuxc: pin MX6UL_PAD_JTAG_TCK already requested by 20e0000.iomuxc; cannot claim for 20f4000.pwm
[    0.322821] imx6ul-pinctrl 20e0000.iomuxc: pin-21 (20f4000.pwm) status -22
[    0.322859] imx6ul-pinctrl 20e0000.iomuxc: could not request pin 21 (MX6UL_PAD_JTAG_TCK) from group pwm6grp  on device 20e0000.iomuxc
NXP Partner ST Partner Renesas Partner