Compiling an Overlay

Now that we've manually enabled an overlay, let's take an overlay created and used in the Adafruit BBIO Python library for enabling the SPI0 device and bus. You can find the latest copy of this overlay at the Adafruit Github repository for Adafruit_BBIO.

Below is a copy of the overlay for SPI0 that we'll use to compile, and enable:
/dts-v1/;
/plugin/;

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

    /* identification */
    part-number = "ADAFRUIT-SPI0";

    /* version */
    version = "00A0";

    [email protected] {
        target = <&am33xx_pinmux>;
        __overlay__ {
            spi0_pins_s0: spi0_pins_s0 {
                pinctrl-single,pins = <
                  0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */
                  0x154 0x30 /* spi0_d0, INPUT_PULLUP | MODE0 */
                  0x158 0x10 /* spi0_d1, OUTPUT_PULLUP | MODE0 */
                  0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */
                >;
            };
        };
    };

    [email protected] {
        target = <&spi0>;
        __overlay__ {
             #address-cells = <1>;
             #size-cells = <0>;

             status = "okay";
             pinctrl-names = "default";
             pinctrl-0 = <&spi0_pins_s0>;

             [email protected] {
                 spi-max-frequency = <24000000>;
                 reg = <0>;
                 compatible = "spidev";
             };
             [email protected] {
                 spi-max-frequency = <24000000>;
                 reg = <1>;
                 compatible = "spidev";
             };
        };
    };
};
Quickly looking at the above overlay, we can see it follows the same pattern as the overlay for UART1. there are two fragments, with the first one utilizing the pinctrl-single driver to mux the pins. We're using 4 of the SPI0 pins, setting everything to Mode 0. Then, [email protected] is targeting the spi0 device with the proper pins, and setting various parameters specific to using the spi device, such as the 'spi-max-frequency'. You can see the available options in the spi-bus documentation.

Navigate to your home directory, and open nano to copy and paste the new file. You'll need to save it exactly as named below as well:
[email protected]:/tmp# cd ~
[email protected]:~# nano ADAFRUIT-SPI0-00A0.dts
Next, we'll execute the command to compile this file into the device tree overlay compiled format (.dtbo):
dtc -O dtb -o ADAFRUIT-SPI0-00A0.dtbo -b 0 [email protected] ADAFRUIT-SPI0-00A0.dts
The compilation should be nearly instant, and you should end up with the newly compiled file:
[email protected]:~# ls -ltr
...
-rw-r--r-- 1 root root 1255 Jul 29 14:33 ADAFRUIT-SPI0-00A0.dts
-rw-r--r-- 1 root root 1042 Jul 29 14:35 ADAFRUIT-SPI0-00A0.dtbo
Let's break down the options used to compile the overlay.

To start with we're using the device tree compiler (dtc). Everything required to compile DT overlays are included with the latest Angstrom distribution.

-O dtb is the output format. We're outputting device tree binaries.
-o is the output filename.
-b 0 is setting the physical boot CPU. (a zero)
[email protected] generates a symbols node as part of the dynamic DT loading of the overlay

You'll know if you don't have a new enough version of dtc if the compiler complains about the missing [email protected] flag. You can attempt an upgrade of dtc by executing the following (this may need to be done on Ubuntu for now):
wget -c https://raw.githubusercontent.com/RobertCNelson/tools/master/pkgs/dtc.sh
chmod +x dtc.sh
./dtc.sh
Last updated on 2015-05-04 at 04.27.11 PM Published on 2013-07-29 at 11.37.59 AM