cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
wfrederi
Observer
Observer
2,073 Views
Registered: ‎04-14-2020

How to update device-tree in PetaLinux 2019.2

Jump to solution

I am trying to add gpio-keys for the SW5 and SW7 pushbuttons on the ZC702 Eval Board in PetaLinux 2019.2.  From the ZC702 documentation, these appear to be mapped to GPIO 54 and 55 via EMIO.  From what I have read, all I should need to do is add them to the system-user.dtsi file (under project-spec/meta-user/recipes-bsp/device-tree/files/).  This is what I put in the file:

/dts-v1/;
/include/ "system-conf.dtsi"
/ {
	gpio-keys {
		compatible = "gpio-keys";
		sw14 {
			label = "sw14";
			gpios = <&gpio0 12 0>;
			linux,code = <108>; /* down */
			wakeup-source;
			autorepeat;
		};
		sw13 {
			label = "sw13";
			gpios = <&gpio0 14 0>;
			linux,code = <103>; /* up */
		};
		sw5 {
			label = "sw5";
			linux,code = <105>; /* Left */
			gpios = <&gpio 54 0>;
		};
		sw7 {
			label = "sw7";
			linux,code = <106>; /* Right */
			gpios = <&gpio 55 0>;
		};
	};
};

This is what is in the device-tree.bbappend one folder up from that (this is unchanged).

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

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

According to what I have read online and in the guides, I should be able to just run petalinux-build and it should build in these changes, which should override what is in the base device-tree.  However, after I reinstall the image to the Eval Board there are no gpio-keys for SW5 and SW7.  Looking at the system.dtb file, the only pushbutton references appear to be SW13 and SW14, which are available in the base device-tree. It looks like the system.dtb file isn't even being rebuilt.

I've also tried various methods of cleaning the PetaLinux build and the device-tree, but nothing seems to have any effect.

What am I missing?

0 Kudos
1 Solution

Accepted Solutions
wfrederi
Observer
Observer
1,881 Views
Registered: ‎04-14-2020

Sorry for the suspense.  I got distracted by shiny objects and wanted to check out a couple things before I finalized my results.  This is the process that I came up with:

First, copy the system-user.dtsi file into the <Project Path>/components/plnx_workspace/device-tree/device-tree folder (if not already there) from <Project Path>/project-spec/meta-user/recipes-bsp/device-tree/files.  Update the file with desired device-tree changes.  I have attached the file with the updates that I made for the gpio-keys (in a zip file since it doesn't seem to like dtsi files as attachments).

Modify the system-top.dts file to replace all instances of #include with /include/.  In my project, this is the only file with #includes.  This is really just to make a change to this file.  EDIT: You can actually just add a space character and save.

Perform the following commands (see note below about distclean):

petalinux-build -c device-tree -x cleansstate
petalinux-build -c device-tree
petalinux-build -c kernel -x distclean
petalinux-build -c kernel

The device-tree builds update the system.dtb file in the <Project Path>/images/Linux folder.  The kernel builds pull those changes into the kernel images (e.g. image.ub).  EDIT: As an alternative to distclean, which will wipe out any kernel configuration changes that you may have made, you could use "petalinux-config -c kernel", toggle anything on and off (resulting in no actual configuration change), save the kernel, and then just perform a petalinux-build.  Or better yet, you could probably just run the touch command on the kernel configuration file (if you know where it is) and then perform the petalinux-build.

I tested this by adding a 0 to each of the labels in my modified gpio-keys.  I then verified that a dts file generated from the system.dtb using dtc and the /proc/interrupts output showed the labels with the added 0 character.

There was a point where I thought that the petalinux-build commands had to be preceded by the following dtc commands for this to work, but I have since run without these commands and everything was updated as expected. 

dtc -I dts -O dtb -o system-top-mod.dtb system-top.dts
dtc -I dtb -O dts -o system-top-mod.dts system-top_mod.dtb

NOTE: I had removed the system-top-mod.* files prior to performing the above update/build process.

View solution in original post

0 Kudos
13 Replies
ksloatdesignlinx
Explorer
Explorer
2,022 Views
Registered: ‎02-24-2020

That looks correct. How are you examining system.dtb?

If you are not sure system.dtsi is being built, I would inject some incorrect statements in the file and make sure you see a failure when you build.

Ken Sloat - Embedded Software Engineer
https://www.designlinxhs.com
0 Kudos
wfrederi
Observer
Observer
2,011 Views
Registered: ‎04-14-2020

I was just using a Text Editor (gedit) to look at the system.dtb file.  I realize that it is a binary file, but the string identifiers are still strings.  So, I saw sw13 and sw14, but not the sw5 and sw7 strings for the nodes I was trying to add.  Also, the file size didn't change at all.

I tried removing some random semicolons and added an extra curly brace and did not get any errors when I ran the following commands:

petalinux-build -c device-tree -x cleansstate
petalinux-build -c device-tree
petalinux-build

So, no, it does not appear to be included in the build.

0 Kudos
ksloatdesignlinx
Explorer
Explorer
2,003 Views
Registered: ‎02-24-2020

Can you open "./components/plnx_workspace/device-tree/device-tree/system-top.dts" and check if "system-user.dtsi" is included there?

Ken Sloat - Embedded Software Engineer
https://www.designlinxhs.com
0 Kudos
wfrederi
Observer
Observer
1,995 Views
Registered: ‎04-14-2020

Yes, it does.  This is the contents of system-top.dts:

/*
 * CAUTION: This file is automatically generated by Xilinx.
 * Version:  
 * Today is: Tue Jul 21 14:40:26 2020
 */


/dts-v1/;
#include "zynq-7000.dtsi"
#include "zc702.dtsi"
#include "pl.dtsi"
#include "pcw.dtsi"
/ {
	chosen {
		bootargs = "earlycon";
		stdout-path = "serial0:115200n8";
	};
	aliases {
		ethernet0 = &gem0;
		i2c0 = &i2c0;
		serial0 = &uart1;
		serial1 = &uart0;
		spi0 = &qspi;
	};
	memory {
		device_type = "memory";
		reg = <0x0 0x40000000>;
	};
};
#include "system-user.dtsi"

 

Just to verify that I can compile the device-tree manually, I used dtc (Device Tree Compiler).  In order for it to compile, I had to modify all #include references to /include/ (apparently, dtc doesn't recognize #include) and had to copy the system-user.dtsi locally (since dtc doesn't know about the path to the file).  I did actually find a couple minor errors by doing this (e.g. the gpio references in sw5/sw7 should have been gpio0).  So, the normal PetaLinux build should have already had problems if it was really including the device tree with the changed user file.

cp <Project Folder>/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi .
dtc -I dts -O dtb -o system-top-test.dtb system-top.dts
dtc -I dtb -O dts -o system-top-test.dts system-top-test.dtb

Of course, performing the PetaLinux build command on the device-tree auto-generates all of these files and undoes any changes.

 

For reference, I got dtc by doing the following:

mkdir dtc
cd dtc
git clone https://git.kernel.org/pub/scm/utils/dtc/dtc.git
cd dtc
make
export PATH=`pwd`:$PATH
0 Kudos
ksloatdesignlinx
Explorer
Explorer
1,984 Views
Registered: ‎02-24-2020

Yeah I think PetaLinux does some post processing on the files so uses #include instead because /include/ is the dtc standard.

If incorrect statements in system-user.dtsi to not cause compile to fail then for some reason it's not actually being built in your project. What happens if you modify system-top.dts and then do a build? You'll want to check that is does not get regenerated after trying this too, or do like:

petalinux-build -x device-tree -c cleansstate
petalinux-build -x device-tree -c build

 

Ken Sloat - Embedded Software Engineer
https://www.designlinxhs.com
0 Kudos
stephenm
Moderator
Moderator
1,974 Views
Registered: ‎09-12-2007

@wfrederi you said "apparently, dtc doesn't recognize #include"

You need to precompile the DTS/DTSI first to add the include files

For example:

gcc -I my_dts -E -nostdinc -undef -D__DTS__ -x assembler-with-cpp -o my_dts/system-top.dts.tmp my_dts/system-top.dts

 

Reference:

https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/341082130/Quick+guide+to+Debugging+Device+Tree+Generator+Issues

0 Kudos
ksloatdesignlinx
Explorer
Explorer
1,969 Views
Registered: ‎02-24-2020

@stephenm I think he was just demonstrating that he could compile the tree manually but the root issue is his system-user.dtsi file is not being built with his changes in PetaLinux for whatever reason.

@wfrederi let me know what happens when you try my latest suggestion.

Ken Sloat - Embedded Software Engineer
https://www.designlinxhs.com
0 Kudos
wfrederi
Observer
Observer
1,947 Views
Registered: ‎04-14-2020

@stephenm I have looked at the link you provided before (or at least something similar).  It refers to running commands in the XSCT, which is in the Vitis environment in 2019.2 and later.  For my setup, Vivado and Vitis are installed in Windows while the PetaLinux tools, of course, are installed in a Linux environment.  It seems overly cumbersome to try to figure out what to transfer and where to transfer files to and from the different environments to run these commands.  So, I've been trying to figure out a method for updating the device-tree completely within the confines of the PetaLinux Tools environment.

@ksloatdesignlinx I have tried running what you indicated (with the -c and -x in the correct places).  After changing the system-top.dts file (changed #includes to /include/s and also changed the labels in the local copy of the system-user.dtsi file) and running your commands, nothing appears to get updated and the system-top.dtsi file is reverted to #includes.

I do seem to have worked out a method for updating the device tree, but I'm not yet completely sure of what part of what I did actually made it work.  When I figure out those details, I will be sure to post the process.

0 Kudos
wfrederi
Observer
Observer
1,882 Views
Registered: ‎04-14-2020

Sorry for the suspense.  I got distracted by shiny objects and wanted to check out a couple things before I finalized my results.  This is the process that I came up with:

First, copy the system-user.dtsi file into the <Project Path>/components/plnx_workspace/device-tree/device-tree folder (if not already there) from <Project Path>/project-spec/meta-user/recipes-bsp/device-tree/files.  Update the file with desired device-tree changes.  I have attached the file with the updates that I made for the gpio-keys (in a zip file since it doesn't seem to like dtsi files as attachments).

Modify the system-top.dts file to replace all instances of #include with /include/.  In my project, this is the only file with #includes.  This is really just to make a change to this file.  EDIT: You can actually just add a space character and save.

Perform the following commands (see note below about distclean):

petalinux-build -c device-tree -x cleansstate
petalinux-build -c device-tree
petalinux-build -c kernel -x distclean
petalinux-build -c kernel

The device-tree builds update the system.dtb file in the <Project Path>/images/Linux folder.  The kernel builds pull those changes into the kernel images (e.g. image.ub).  EDIT: As an alternative to distclean, which will wipe out any kernel configuration changes that you may have made, you could use "petalinux-config -c kernel", toggle anything on and off (resulting in no actual configuration change), save the kernel, and then just perform a petalinux-build.  Or better yet, you could probably just run the touch command on the kernel configuration file (if you know where it is) and then perform the petalinux-build.

I tested this by adding a 0 to each of the labels in my modified gpio-keys.  I then verified that a dts file generated from the system.dtb using dtc and the /proc/interrupts output showed the labels with the added 0 character.

There was a point where I thought that the petalinux-build commands had to be preceded by the following dtc commands for this to work, but I have since run without these commands and everything was updated as expected. 

dtc -I dts -O dtb -o system-top-mod.dtb system-top.dts
dtc -I dtb -O dts -o system-top-mod.dts system-top_mod.dtb

NOTE: I had removed the system-top-mod.* files prior to performing the above update/build process.

View solution in original post

0 Kudos
arashr
Explorer
Explorer
1,214 Views
Registered: ‎02-06-2018

Hi,

I'm bringing this thread to the top because I have the same issue. When I change the system-user.dtsi in the following path:

/project-spec/meta-user/recipes-bsp/device-tree/files

It doesn't take effect or update the device tree in the build process and nothing changes. When I put garbage in the file, no error is returned. Also, I don't want to follow the accepted solution because it doesn't include general application cases.

However, I found a work around; the solution is simply to change the system-user.dtsi in the following path instead:

/components/yocto/workspace/sources/device-tree/oe-local-files/system-user.dtsi

I don't know why this happens, it seems the dtsi files at oe-local-files have higher priority? Any ideas?

0 Kudos
arashr
Explorer
Explorer
1,211 Views
Registered: ‎02-06-2018

Even a better solution, go to the following path:

/components/yocto/workspace/sources/device-tree/oe-local-files/

rename system-user.dtsi to something else like system-user_backup.dtsi

You are good to go now, you can edit the system-user.dtsi in the following path:

/project-spec/meta-user/recipes-bsp/device-tree/files

 and it works now.

It would be awesome if experts could jump in to comment on why this needs to be done. Thank you.

0 Kudos
wfrederi
Observer
Observer
1,186 Views
Registered: ‎04-14-2020

Unfortunately, that folder path doesn't appear to exist under PetaLinux 2019.2.  The only files that I find in the project are in the component device tree (which I copied there) and in the recipe (where it was originally generated for the project).  It didn't seem to find my recipe file changes until I copied them into the component device tree path.

[labuser@localhost zc702_linux_test_project]$ find . -name "system-user.dtsi"
./project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi
./components/plnx_workspace/device-tree/device-tree/system-user.dtsi

However, the problem might have actually been that it wasn't always automatically building the device tree into the kernel.  Just changing the recipe file and running a petalinux-build didn't seem to build the device tree.

Given this, I went ahead and tried moving the system-user.dtsi file changes back to the recipe folder, removed it from the components folder, forced the kernel to rebuild by using petalinux-config -c kernel and saving the configuration, and rebuilt with petalinux-build.  The rebuild included the device tree changes and incorporated them into the kernel image.

Since that seemed to work, I tried just changing the system-user.dtsi file in the recipe folder and rebuilding with petalinux-build.  Interestingly, the build did now seem to include the recipe folder device tree changes and they were correctly incorporated into the kernel image.  Not sure exactly what changed, but this didn't originally appear to work, which is what led me down the path of copying the file directly into the device-tree in the first place.  I am now perplexed, but satisfied.

0 Kudos
arashr
Explorer
Explorer
1,168 Views
Registered: ‎02-06-2018

@wfrederiThanks for the update. I'm glad it has started working. I should have made it clear that I'm using 2020.2 so this might explain why the path doesn't exist in 2019.2.

0 Kudos