UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Adventurer
Adventurer
637 Views
Registered: ‎11-02-2014

Accepted process for modifying pl.dtsi with device tree overlays

Jump to solution

Hi,

I am trying to modify the device tree overlay for my programmable logic. Since the PL node is removed from the system.dts, clearly the solution is not to to redefine the fragment@x nodes in system-user.dtsi. I have tried this and, though the system compiles, it does not work (it seems to break uboot, in fact).


Petalinux does not seem to add an equivalent 'include system_user.dtsi' line to pl.dtsi, and since pl.dtsi is auto generated, I do not see how I can modify it to add a recipe to modify it's contents.

Any suggestions? Or am I misunderstanding something?

Best,

Brian

0 Kudos
1 Solution

Accepted Solutions
Highlighted
442 Views
Registered: ‎12-21-2018

Re: Accepted process for modifying pl.dtsi with device tree overlays

Jump to solution

Hi Brian,

I've managed to produce a customized PL device tree overlay using the following steps :

1) Create pl-user.dtsi file next to system-user.tdsi in the ./project-spec/meta-user/recipes-bsp/device-tree and add the content to be appended to the PL overlay device tree source :

In my case, I want to define the nodes of 2 GPIO expanders connected to an AXI I2C IP. So here is the pl-user.dtsi content :

 

/ {
    fragment@2 {
        target = <&amba>;
        overlay2: __overlay__ {        
            i2c@800f1000 {        
                gpio@23 {
                    #gpio-cells = <0x2>;
                    compatible = "ti,tca6424";
                    reg = <0x23>;
                    gpio-controller;
                };

                gpio@21 {
                    #gpio-cells = <0x2>;
                    compatible = "ti,tca6416";
                    reg = <0x21>;
                    gpio-controller;
                };
            };
        };
    };
};

 

 

2) Add some python code to device-tree.bbappend recipe  :
- reading the content of pl.dtsi
- reading the content of pl-user.dtsi
- creating a new file pl_custom.dtsi in the folder ./components/plnx_workspace/device-tree/device-tree/ where sit system-top.dts and pl.dtsi.
- appending to that file the content of pl.dtsi and pl-user.dtsi

device-tree.bbappend content :

 

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

SRC_URI += "file://system-user.dtsi \
            file://pl-user.dtsi \
            "

KERNEL_DEVICETREE += "pl_custom.dtbo"

do_compile_prepend() {
    
    # Read the pl.dtsi content
    fin = open(d.getVar('DT_FILES_PATH') + "/pl.dtsi", "r")
    pl_dtsi_content = fin.read()
    fin.close()
    
    # Read the pl-user.dtsi content
    fin = open(d.getVar('WORKDIR') + "/pl-user.dtsi", "r")
    pl_user_dtsi_content = fin.read()
    fin.close()
    
    # Append both pl.dtsi and pl-user.dtsi to output pl_custom.dtsi
    fout = open(d.getVar('DT_FILES_PATH') + '/pl_custom.dtsi', "w+")
    fout.write(pl_dtsi_content)
    fout.write("\n")
    fout.write(pl_user_dtsi_content)
    fout.close()
}

3) create an append file for the fpga-manager-util recipe (./project-spec/meta-user/recipes-bsp/fpga-manager-util/fpga-manager-util_%.bbappend) to deploy the compiled dtbo (pl_custom.dtbo) to /lib/firmware :

 

fpga-manager-util_%.bbappend content :

 

do_compile_append() {
    cp ${RECIPE_SYSROOT}/boot/devicetree/pl_custom.dtbo ${XSCTH_WS}/pl_custom.dtbo
}

do_install_append() {
    install -Dm 0644 pl_custom.dtbo ${D}/lib/firmware/base/pl_custom.dtbo
}

4) On the target board, instead of doing echo -n "base.dtbo" > full/path, do :

 echo -n "pl_custom.dtbo" > full/path

5) Bingo ! (the 2 I2C I/O expanders are seen and the right linux drivers loaded)

 

7 Replies
Moderator
Moderator
624 Views
Registered: ‎12-04-2016

Re: Accepted process for modifying pl.dtsi with device tree overlays

Jump to solution
0 Kudos
Adventurer
Adventurer
616 Views
Registered: ‎11-02-2014

Re: Accepted process for modifying pl.dtsi with device tree overlays

Jump to solution

Hi Shabbirk,

Yes, I have read the section you mentioned a few times. There is nothing in there describing how to change pl.dtsi, which again, is removed as an inclusion from system-top.dts, and cannot be modified by system-user.dtsi when the fpga manager and device tree overlays are enabled. It is compiled as its own device tree overlay. It would need an entry for a user inclusion in the components/plnx_workspace/devicetree/pl.dtsi source folder.

 

Thanks,

Brian

0 Kudos
Adventurer
Adventurer
586 Views
Registered: ‎11-02-2014

Re: Accepted process for modifying pl.dtsi with device tree overlays

Jump to solution

From page 109 of the Petalinux Reference Guide:

"Add /include/ “system-user-1.dtsi in project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi. The file should look like the following:/include/ "system-conf.dtsi"/include/ "system-user-1.dtsi"/ {};"

This is the instruction for adding additional user.dtsi files. However, if FPGA Manager is enabled, and device tree overlays are enabled then pl.dtsi is not added to system-top.dtsi in components/plnx_worskpace/device-tree/device-tree, therefore adding sources to system-user.dtsi will have no effect on the contents of pl.dtsi. Two seperate dtb generation commands are issued in this case, so the device tree and the device tree overlay are seperate entities.

I would really welcome any suggestions here, as it seems like a pretty big gap in the configuration setup, that could be very easily fixedby adding an "/include/ pl-user.dtsi" to the pl.dtsi file. I can't do that myself though, because the file is auto generated.

 

 

462 Views
Registered: ‎12-21-2018

Re: Accepted process for modifying pl.dtsi with device tree overlays

Jump to solution

Hi Brian,

I'm facing the same issue. I want to modify the PL device tree overlay to define some I2C GPIO expanders which are connected to an AXI-I2C IP, but I'ven't found an easy way to do it.

I've tried to add a custom dtsi including pl.dtsi in the device-tree.bbappend recipe, but it seems to not be compiled. I'll try to define a custom app recipe to compile dtsi and deploy dtbo for my custom device tree overlay.

But I think petalinux should provide a way to do that the same way we use the system-user.dtsi to customize  the system device tree.

Jeremy

0 Kudos
Highlighted
443 Views
Registered: ‎12-21-2018

Re: Accepted process for modifying pl.dtsi with device tree overlays

Jump to solution

Hi Brian,

I've managed to produce a customized PL device tree overlay using the following steps :

1) Create pl-user.dtsi file next to system-user.tdsi in the ./project-spec/meta-user/recipes-bsp/device-tree and add the content to be appended to the PL overlay device tree source :

In my case, I want to define the nodes of 2 GPIO expanders connected to an AXI I2C IP. So here is the pl-user.dtsi content :

 

/ {
    fragment@2 {
        target = <&amba>;
        overlay2: __overlay__ {        
            i2c@800f1000 {        
                gpio@23 {
                    #gpio-cells = <0x2>;
                    compatible = "ti,tca6424";
                    reg = <0x23>;
                    gpio-controller;
                };

                gpio@21 {
                    #gpio-cells = <0x2>;
                    compatible = "ti,tca6416";
                    reg = <0x21>;
                    gpio-controller;
                };
            };
        };
    };
};

 

 

2) Add some python code to device-tree.bbappend recipe  :
- reading the content of pl.dtsi
- reading the content of pl-user.dtsi
- creating a new file pl_custom.dtsi in the folder ./components/plnx_workspace/device-tree/device-tree/ where sit system-top.dts and pl.dtsi.
- appending to that file the content of pl.dtsi and pl-user.dtsi

device-tree.bbappend content :

 

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

SRC_URI += "file://system-user.dtsi \
            file://pl-user.dtsi \
            "

KERNEL_DEVICETREE += "pl_custom.dtbo"

do_compile_prepend() {
    
    # Read the pl.dtsi content
    fin = open(d.getVar('DT_FILES_PATH') + "/pl.dtsi", "r")
    pl_dtsi_content = fin.read()
    fin.close()
    
    # Read the pl-user.dtsi content
    fin = open(d.getVar('WORKDIR') + "/pl-user.dtsi", "r")
    pl_user_dtsi_content = fin.read()
    fin.close()
    
    # Append both pl.dtsi and pl-user.dtsi to output pl_custom.dtsi
    fout = open(d.getVar('DT_FILES_PATH') + '/pl_custom.dtsi', "w+")
    fout.write(pl_dtsi_content)
    fout.write("\n")
    fout.write(pl_user_dtsi_content)
    fout.close()
}

3) create an append file for the fpga-manager-util recipe (./project-spec/meta-user/recipes-bsp/fpga-manager-util/fpga-manager-util_%.bbappend) to deploy the compiled dtbo (pl_custom.dtbo) to /lib/firmware :

 

fpga-manager-util_%.bbappend content :

 

do_compile_append() {
    cp ${RECIPE_SYSROOT}/boot/devicetree/pl_custom.dtbo ${XSCTH_WS}/pl_custom.dtbo
}

do_install_append() {
    install -Dm 0644 pl_custom.dtbo ${D}/lib/firmware/base/pl_custom.dtbo
}

4) On the target board, instead of doing echo -n "base.dtbo" > full/path, do :

 echo -n "pl_custom.dtbo" > full/path

5) Bingo ! (the 2 I2C I/O expanders are seen and the right linux drivers loaded)

 

Adventurer
Adventurer
342 Views
Registered: ‎11-02-2014

Re: Accepted process for modifying pl.dtsi with device tree overlays

Jump to solution

Hi Jeremy,

Thanks very much for the feedback on this! I will be getting back to that process very soon, so your guide will be extremely helpful. although I can't yet confirm that it worked on my end, I will tentatively mark as the solution!

Best,

Brian

0 Kudos
Visitor galactic
Visitor
21 Views
Registered: ‎11-01-2019

Re: Accepted process for modifying pl.dtsi with device tree overlays

Jump to solution

I'm trying to utilize this solution but I keep getting cyrptic syntax errors when adding the python code to bb appends file, I'm using petalinux 2018.3, is there something that has to be installed/enabled to get this to work right?

Traceback (most recent call last):
  File "/home/bb.ibw5028/opt/petalinux_2018.3/components/yocto/source/aarch64/layers/core/bitbake/lib/bb/codeparser.py", line 370, in ShellParser._parse_shell(value='\n    # Read the pl.dtsi content\n    fin = open(d.getVar(\'DT_FILES_PATH\') + "/pl.dtsi", "r")\n    pl_dtsi_content = fin.read()\n    fin.close()\n\n    # Read the pl-user.dtsi content\n    fin = open(d.getVar(\'WORKDIR\') + "/pl-user.dtsi", "r")\n    pl_user_dtsi_content = fin.read()\n    fin.close()\n\n    # Append both pl.dtsi and pl-user.dtsi to output pl_custom.dtsi\n    fout = open(d.getVar(\'DT_FILES_PATH\') + \'/pl_custom.dtsi\', "w+")\n    fout.write(pl_dtsi_content)\n    fout.write("\\n")\n    fout.write(pl_user_dtsi_content)\n    fout.close()\n\t[ -e /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree/system.dts ] && rm /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree/system.dts\n\tfor DTS_FILE in /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree/*.dts*; do\n\t\tDTS_NAME=`basename -s .dts ${DTS_FILE}`\n\t\tgcc  -E  \t\t-nostdinc -Ulinux -x assembler-with-cpp \t\t-I/home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree -I/home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -I/home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/arch/arm64/boot/dts/xilinx -I/home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -I/home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work/plnx_zynqmp-xilinx-linux/device-tree/xilinx+gitAUTOINC+b7466bbeee-r0 \t\t -o `basename ${DTS_FILE}`.pp ${DTS_FILE}\n\n\t\t# for now use the existance of the \'/plugin/\' tag to detect overlays\n\t\tif grep -qse "/plugin/;" `basename ${DTS_FILE}`.pp; then\n\t\t\tDTS_NAME=`basename -s .dtsi ${DTS_FILE}`\n\t\t\tdtc -@ -H epapr -I dts -O dtb  \t\t-R 8 -p 0x1000 -b 0 \t\t-i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/arch/arm64/boot/dts/xilinx -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work/plnx_zynqmp-xilinx-linux/device-tree/xilinx+gitAUTOINC+b7466bbeee-r0 \t\t -@ \t\t  -o ${DTS_NAME}.dtbo `basename ${DTS_FILE}`.pp\n\t\telif [ "${DTS_FILE##*.}" = "dts" ]; then\n\t\t\tdtc -I dts -O dtb  \t\t-R 8 -p 0x1000 -b 0 \t\t-i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/arch/arm64/boot/dts/xilinx -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work/plnx_zynqmp-xilinx-linux/device-tree/xilinx+gitAUTOINC+b7466bbeee-r0 \t\t -@ \t\t  -o ${DTS_NAME}.dtb `basename ${DTS_FILE}`.pp\n\t\t\tdtc -I dtb -O dts -o ${DTS_NAME}.dts ${DTS_NAME}.dtb\n\t\tfi\n\tdone\n'):
             try:
    >            tokens, _ = pyshyacc.parse(value, eof=True, debug=False)
             except pyshlex.NeedMore:
  File "/home/bb.ibw5028/opt/petalinux_2018.3/components/yocto/source/aarch64/layers/core/bitbake/lib/bb/pysh/pyshyacc.py", line 673, in parse(input='\n    # Read the pl.dtsi content\n    fin = open(d.getVar(\'DT_FILES_PATH\') + "/pl.dtsi", "r")\n    pl_dtsi_content = fin.read()\n    fin.close()\n\n    # Read the pl-user.dtsi content\n    fin = open(d.getVar(\'WORKDIR\') + "/pl-user.dtsi", "r")\n    pl_user_dtsi_content = fin.read()\n    fin.close()\n\n    # Append both pl.dtsi and pl-user.dtsi to output pl_custom.dtsi\n    fout = open(d.getVar(\'DT_FILES_PATH\') + \'/pl_custom.dtsi\', "w+")\n    fout.write(pl_dtsi_content)\n    fout.write("\\n")\n    fout.write(pl_user_dtsi_content)\n    fout.close()\n\t[ -e /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree/system.dts ] && rm /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree/system.dts\n\tfor DTS_FILE in /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree/*.dts*; do\n\t\tDTS_NAME=`basename -s .dts ${DTS_FILE}`\n\t\tgcc  -E  \t\t-nostdinc -Ulinux -x assembler-with-cpp \t\t-I/home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree -I/home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -I/home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/arch/arm64/boot/dts/xilinx -I/home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -I/home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work/plnx_zynqmp-xilinx-linux/device-tree/xilinx+gitAUTOINC+b7466bbeee-r0 \t\t -o `basename ${DTS_FILE}`.pp ${DTS_FILE}\n\n\t\t# for now use the existance of the \'/plugin/\' tag to detect overlays\n\t\tif grep -qse "/plugin/;" `basename ${DTS_FILE}`.pp; then\n\t\t\tDTS_NAME=`basename -s .dtsi ${DTS_FILE}`\n\t\t\tdtc -@ -H epapr -I dts -O dtb  \t\t-R 8 -p 0x1000 -b 0 \t\t-i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/arch/arm64/boot/dts/xilinx -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work/plnx_zynqmp-xilinx-linux/device-tree/xilinx+gitAUTOINC+b7466bbeee-r0 \t\t -@ \t\t  -o ${DTS_NAME}.dtbo `basename ${DTS_FILE}`.pp\n\t\telif [ "${DTS_FILE##*.}" = "dts" ]; then\n\t\t\tdtc -I dts -O dtb  \t\t-R 8 -p 0x1000 -b 0 \t\t-i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/../components/plnx_workspace/device-tree/device-tree -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/arch/arm64/boot/dts/xilinx -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work-shared/plnx-zynqmp/kernel-source/include -i /home/bb.ibw5028/hdl/axidmatest/axidmatest/build/tmp/work/plnx_zynqmp-xilinx-linux/device-tree/xilinx+gitAUTOINC+b7466bbeee-r0 \t\t -@ \t\t  -o ${DTS_NAME}.dtb `basename ${DTS_FILE}`.pp\n\t\t\tdtc -I dtb -O dts -o ${DTS_NAME}.dts ${DTS_NAME}.dtb\n\t\tfi\n\tdone\n', eof=True, debug=False):
             debug = 2
    >    return yacc.parse(lexer=lexer, debug=debug), remaining
     
  File "/home/bb.ibw5028/opt/petalinux_2018.3/components/yocto/source/aarch64/layers/core/bitbake/lib/ply/yacc.py", line 267, in LRParser.parse(input=None, lexer=<bb.pysh.pyshlex.PLYLexer object at 0x7fe655e6f710>, debug=False, tracking=0, tokenfunc=None):
             else:
    >            return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
             
  File "/home/bb.ibw5028/opt/petalinux_2018.3/components/yocto/source/aarch64/layers/core/bitbake/lib/ply/yacc.py", line 1049, in LRParser.parseopt_notrack(input=None, lexer=<bb.pysh.pyshlex.PLYLexer object at 0x7fe655e6f710>, debug=False, tracking=0, tokenfunc=None):
                                 errtoken.lexer = lexer
    >                        tok = self.errorfunc(errtoken)
                             del errok, token, restart   # Delete special functions
  File "/home/bb.ibw5028/opt/petalinux_2018.3/components/yocto/source/aarch64/layers/core/bitbake/lib/bb/pysh/pyshyacc.py", line 646, in p_error(p=LexToken(TOKEN,"'DT_FILES_PATH'",0,0)):
             w('  %r\n' % n)
    >    raise sherrors.ShellSyntaxError(''.join(msg))
     
bb.pysh.sherrors.ShellSyntaxError: LexToken(TOKEN,"'DT_FILES_PATH'",0,0)
followed by:
  LexToken(RPARENS,')',0,0)
  LexToken(TOKEN,'+',0,0)
  LexToken(TOKEN,'"/pl.dtsi",',0,0)
  LexToken(TOKEN,'"r"',0,0)
  LexToken(RPARENS,')',0,0)



Summary: There were 2 WARNING messages shown.
Summary: There was 1 ERROR message shown, returning a non-zero exit code.
ERROR: Failed to build device-tree
0 Kudos