Confused between Device Tree and Device Tree Overlay.What to use for the new Driver?

918 views
Skip to first unread message

Jane

unread,
Jul 25, 2016, 2:31:10 AM7/25/16
to BeagleBoard
Hi, 

I have been following this famous link from Robert Nelson for kernel building : https://eewiki.net/display/linuxonarm/BeagleBone+Black 

I have been reading and trying the concept of Device Tree for a new Driver i am writing.To start with I tried to build a sample dts file( leds-ns2.dts) by copying it into the KERNEL/scripts/dtc folder 

dtc -I dts -O dtb -o mydtb.dtb leds-ns2.dts

below is the content of the leds-ns2.dts

******************************************************************************************
#include <dt-bindings/leds/leds-ns2.h>

 ns2-leds {
          compatible = "lacie,ns2-leds";

          blue-sata {
                  label = "ns2:blue:sata";
                  slow-gpio = <&gpio0 29 0>;
                  cmd-gpio = <&gpio0 30 0>;
                  modes-map = <NS_V2_LED_OFF  0 1
                               NS_V2_LED_ON   1 0
                               NS_V2_LED_ON   0 0
                               NS_V2_LED_SATA 1 1>;
          };
  };
******************************************************************************************


but I am getting this error : 

DTC: dts->dtb  on file "leds-ns2.dts"
Error: leds-ns2.dts:1.1-2 syntax error
FATAL ERROR: Unable to parse input tree

On further googling in forums I found that I have to build the dts using the below command-> 

make ARCH=arm CROSS_COMPILE=${CC} dtbs ( i put the leds-ns2.dts file into /arch/arm/boot/dts/. folder before this,I skipped : make ARCH=arm CROSS_COMPILE=arm-none-eabi- am335x_evm_defconfig since kernel is already been built with this.)

After building I didn't see any error but I didn't find any leds-ns2.dtb in the folder.Does that mean that do I have to enable it in the .config file first by running tools/rebuild.sh script?

once I will be able to built it successfully do I have to run this command to copy the dtbs to the BBB .

sudo tar xfv ./bb-kernel/deploy/${kernel_version}-dtbs.tar.gz -C /media/rootfs/boot/dtbs/${kernel_version}/


Is there a way I can just build the dtb for the device I want and transfer it to the BBB and test my driver using that dtb.

I think device tree overlay must be doing this?
Please advice the directions .

Thanks and Regards,
J






Greg

unread,
Jul 25, 2016, 10:51:18 AM7/25/16
to BeagleBoard
I'm not sure there is a one-stop shop for understanding the Device Tree anywhere.

There are at least 4 file types involved:

1.  dts-  This is the source code (text file) which is a data structure to describe hardware.
2.  dtsi-  A sub-chunk or "include" file which is used inside dts files.  It's somewhat similar to an "include" or "import" in programming languages.
3.  dtb-  Device tree blob.  This is the compiled version of the dts.  This is what gets loaded at boot time.  It's the foundation of the system used by the kernel.
4.  dtbo-  Device tree overlay.  This can be loaded after boot time.  This is how the Beaglebone adjusts itself when different "capes" are plugged in.  It does this by reading information stored in the EEPROM in the cape.  These "overlays" can also be loaded at the command line using the "slots" in the sysfs virtual file system.  Look for a substantial collection of already done overlays in the directory /lib/firmware.  If you want to make your own overlay, /lib/firmware is where you want to place it.

This topic is really confusing, and no doubt my notes above are full of flaws.

You can work through and understand all of the above.  However, depending on the complexity of what you are trying to do, this may be sufficient:

https://github.com/cdsteinkuehler/beaglebone-universal-io

Using the config-pin -f option and a simple text file you can use your .profile or similar start-up configuration file to set the pins to your requirements.
This is a relatively straight-forward solution to tacking the problem.

In my opinion the device tree is a major hurdle to making progress with the Beaglebones.  If you google you will get a bunch of out-dated information, so be careful what you read on the net.  Perhaps someone will suggest single source of accurate information on this topic.

Regards,
Greg

Raul Piper

unread,
Jul 25, 2016, 1:54:26 PM7/25/16
to beagl...@googlegroups.com
Hi Greg,
Thankyou for the elaborative post and the link you sent.My understanding is mainly theoretical and inlined with what you wrote..

Yes,I have been scanning across many links on google and stack overflow but not able to find single one convincing.

I came to conclusion that i will write a hello world gpio driver with lots of printk and build it along with the dts file by placing it in arch/arm/boot/dts and then loading that kernel image.According to R.Nelson's link i will copy the dtb files as well.
Init--> probe-->register platform driver(.compatible string in the platform_device structure ) should throw something to go ahead with then. 

But still the loop holes in the understanding like why to copy all the dtb files,how to build only that dtb file and copy it in the lib/firmware and dynamically insmod the driver ....where does overlays come into the picture...can the drivers without dtb implementation be accepted in kernelmain line...

Really looking for some example code here.
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to a topic in the Google Groups "BeagleBoard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beagleboard/cLDC6Le0Z4A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/2a565144-1715-4bc2-ae74-b6415a30dea1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

William Hermans

unread,
Jul 27, 2016, 12:47:42 AM7/27/16
to beagl...@googlegroups.com
Note the structure here form this modified file( Modified from Charles S' Universal IO overlay 'univ-all' ) This is for a single pin instead of all pins.https://github.com/beagleboard/bb.org-overlays/blob/master/src/arm/univ-all-00A0.dts

IN short here is what is required:

  • /dts-v1/;
  • /plugin/;
  • / {
  •     compatible = "ti,beaglebone", "ti,beaglebone-black", "ti,beaglebone-green";
  • part-number = "univ-P8_07";
  • version = "00A0";

Passed that exclusive-use =    "P8.7"; ive seen in each overlay for pins each uses. BUt if you examine this file closely it should become apparent what is required to make a like overlay function. This specific file is mean to offer the ability to change pin mux dynamically as the system is running. So there are 5 possibilities from this file, but initially the pin is configured as input.

I will tell you what helps me a good bit while editing device tree files. You need a good editor that will allow you to arbitrarily set syntax highlighting. Then, I personally set syntax highlighting to "C".

 
/dts-v1/;
/plugin/;

/ {
    compatible = "ti,beaglebone", "ti,beaglebone-black", "ti,beaglebone-green";

    /* identification */
    part-number = "univ-P8_07";
    version = "00A0";

    /* state the resources this cape uses */
    exclusive-use =    "P8.7";
       
    /* P8_07 (ZCZ ball R7 ) */
    P8_07_default_pin: pinmux_P8_07_default_pin {
        pinctrl-single,pins = <0x090  0x37>; };     /* Mode 7, Pull-Up, RxActive */
    P8_07_gpio_pin: pinmux_P8_07_gpio_pin {
        pinctrl-single,pins = <0x090  0x2F>; };     /* Mode 7, RxActive */
    P8_07_gpio_pu_pin: pinmux_P8_07_gpio_pu_pin {
        pinctrl-single,pins = <0x090  0x37>; };     /* Mode 7, Pull-Up, RxActive */
    P8_07_gpio_pd_pin: pinmux_P8_07_gpio_pd_pin {
        pinctrl-single,pins = <0x090  0x27>; };     /* Mode 7, Pull-Down, RxActive */
    P8_07_timer_pin: pinmux_P8_07_timer_pin {
        pinctrl-single,pins = <0x090  0x32>; };     /* Mode 2, Pull-Up, RxActive */

    fragment@1 {
        target = <&ocp>;
        __overlay__ {

            P8_07_pinmux {
                compatible = "bone-pinmux-helper";
                status = "okay";
                pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "timer";
                pinctrl-0 = <&P8_07_default_pin>;
                pinctrl-1 = <&P8_07_gpio_pin>;
                pinctrl-2 = <&P8_07_gpio_pu_pin>;
                pinctrl-3 = <&P8_07_gpio_pd_pin>;
                pinctrl-4 = <&P8_07_timer_pin>;
            };
        };
    };

    fragment@2 {
        target = <&ocp>;
        __overlay__ {

            cape-universal {
                compatible = "gpio-of-helper";
                status = "okay";
                pinctrl-names = "default";
                pinctrl-0 = <>;

                P8_07 {
                    gpio-name = "P8_07";
                    gpio = <&gpio2 2 0>;
                    input;
                    dir-changeable;
                };
            };
        };
    };
};


You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/CAEwN%2BMB16im1R%2BtCPjpSk86sQ-2Lr4207yRU9Y_OrCBZfqeOEw%40mail.gmail.com.

Jane

unread,
Jul 28, 2016, 6:30:33 AM7/28/16
to BeagleBoard
 Can you name the editor?Is the dt is also like python where the Tabs and special character may ruin its compiling?
Also does dtc compiler checks for the sanity of the file besides checking these tabs,syntax,etc.I mean what if it compiles fine but there is an issue in the dt?
 Also can you please elaborate more on the example dt below.Is it a device tree or device tree overlay?Also way to compile it.
To unsubscribe from this group and all its topics, send an email to beagleboard+unsubscribe@googlegroups.com.

William Hermans

unread,
Jul 28, 2016, 6:32:40 AM7/28/16
to beagl...@googlegroups.com
I use sublime text 3. And no device tree syntax is nothing like python.

To unsubscribe from this group and all its topics, send an email to beagleboard...@googlegroups.com.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/CAEwN%2BMB16im1R%2BtCPjpSk86sQ-2Lr4207yRU9Y_OrCBZfqeOEw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.

Jane

unread,
Aug 1, 2016, 4:56:38 AM8/1/16
to BeagleBoard
Hi William, 
can you please elaborate on the purpose for the cape-overlay you have written.How did you compile and pushed it into the beagleboneblack?Where did you place the compiled .dtb/.dtbo?

To unsubscribe from this group and all its topics, send an email to beagleboard+unsubscribe@googlegroups.com.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/CAEwN%2BMB16im1R%2BtCPjpSk86sQ-2Lr4207yRU9Y_OrCBZfqeOEw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages