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: 
Observer raymond.walter
Observer
4,158 Views
Registered: ‎04-04-2017

PetaLinux 2017.3 Completely custom Device Tree

Hey,

 

is there a way to use a completely different (custom) device tree instead of modifying the existing one by adding changes to the system-user.dtsi file? I want to write my own device tree for the ZynqMP ZCU102 but I can't find a way to replace the whole device tree.

 

I tried modifying a .bbappend file for device-tree-generation_%.bb but haven't gotten any results from that.

 

Kind Regards

Raymond

 

 

8 Replies
Explorer
Explorer
4,139 Views
Registered: ‎11-24-2013

Re: PetaLinux 2017.3 Completely custom Device Tree

Hi @raymond.walter,

 

I usually do this by creating an "image.ub" with my custom device tree. The steps I follow are:

 

First I copy the fit image configuration file used by Petalinux and modify it to refer to relative paths. I put the copied file in the directory I am going to work in with the name "config.its". The original file is here:

[petalinux-project]/build/tmp/deploy/images/plnx_aarch64/fitImage.its-1.0-r0

After the modification, it looks like this:

/dts-v1/;

/ {
	description = "U-Boot fitImage for plnx_aarch64 kernel";
	#address-cells = <1>;

	images {
		kernel@0 {
			description = "Linux Kernel";
			data = /incbin/("Image");
			type = "kernel";
			arch = "arm64";
			os = "linux";
			compression = "none";
			load = <0x80000>;
			entry = <0x80000>;
			hash@1 {
				algo = "sha1";
			};
		};
		fdt@0 {
			description = "Flattened Device Tree blob";
			data = /incbin/("system.dtb");
			type = "flat_dt";
			arch = "arm64";
			compression = "none";
			hash@1 {
				algo = "sha1";
			};
		};
		ramdisk@0 {
			description = "ramdisk";
			data = /incbin/("rootfs.cpio.gz");
			type = "ramdisk";
			arch = "arm64";
			os = "linux";
			compression = "none";
			hash@1 {
				algo = "sha1";
			};
		};
	};
	configurations {
		default = "conf@1";
		conf@1 {
			description = "Boot Linux kernel with FDT blob + ramdisk";
			kernel = "kernel@0";
			fdt = "fdt@0";
			ramdisk = "ramdisk@0";
			hash@1 {
				algo = "sha1";
			};
		};
		conf@2 {
			description = "Boot Linux kernel with FDT blob";
			kernel = "kernel@0";
			fdt = "fdt@0";
			hash@1 {
				algo = "sha1";
			};
		};
	};
};

 

Then, I copy (or link) the files to the working directory. The ones generated by Petalinux are in [petalinux-project]/images/linux and the device tree is the one created by me.

 

After that, I generate the image like this:

mkimage -f config.its image.ub

 

This way you can easily change the device tree being used without having to run "petalinux-build".

 

Note: if your device tree is not compiled, you can do it with the tool "dtc" (available in Ubuntu with the package "device-tree-compiler")

dtc -I dts -O dtb system.dts -o system.dtb

I hope this helps!

 

Regards

Ignacio

 

0 Kudos
Observer raymond.walter
Observer
4,127 Views
Registered: ‎04-04-2017

Re: PetaLinux 2017.3 Completely custom Device Tree

Thanks, that is definitely a way of doing it but I want to keep using petalinux-build for everything.

Is there a way to modify the device-tree-generation recipes to achieve this? Ideally I'd want to have the full device tree file inside my Yocto layer and have it generate a dtb for u-boot and linux.

 

King Regards

Raymond

0 Kudos
Moderator
Moderator
4,085 Views
Registered: ‎09-12-2007

Re: PetaLinux 2017.3 Completely custom Device Tree

You could download the devicetree generator here:
https://github.com/xilinx/device-tree
cd device-tree-generator
git checkout xilinx-v2017.4

Then Make your edits, then create a patch
git diff xilinx-v2017.4 > 0001-dtg-patch.patch

Then add this patch to the files folder in
plnx-projroot>/components/plnx_workspace/device-tree-generation/ and <plnx-proj-root>/project-spec/meta-user/recipes-dt/device-tree/files

Then update the bappend file to add this patch

SRC_URI_append = " \
file://system-user.dtsi \
file://0001-dyg-patch.patch \
"

0 Kudos
Explorer
Explorer
4,069 Views
Registered: ‎10-04-2017

Re: PetaLinux 2017.3 Completely custom Device Tree

If you use a private git repo for linux you can put your devicetree in the linux repo and disable devicetree generation.

0 Kudos
Moderator
Moderator
4,055 Views
Registered: ‎04-24-2017

Re: PetaLinux 2017.3 Completely custom Device Tree

Hi @raymond.walter,

 

You can remove DTB from petalinux config.

 

1. In petalinux-config change the "dtb image settings" from 'from boot image' to 'primary sd'
( ) from boot image 
( ) primary flash
(X) primary sd
( ) ethernet 
( ) manual
2. petalinux-build
3. package the image and copy BOOT.BIN, system.dtb(custom one), and Image(kernel image+rootfs) to SD Card
4. Halt at U-Boot from add below env settings
 
ZynqMP> setenv kernel_img Image
ZynqMP> setenv cp_kernel2ram 'mmcinfo && fatload mmc 0 ${netstart} ${kernel_img}'
ZynqMP> setenv cp_dtb2ram 'mmcinfo && fatload mmc 0:1 ${dtbnetstart} system.dtb'
ZynqMP> setenv default_bootcmd 'run cp_kernel2ram && run cp_dtb2ram && booti ${netstart} - ${dtbnetstart}'
ZynqMP> boot
 
Thanks,
Sandeep
PetaLinux Yocto | Embedded SW Support

---------------------------------------------------------------------------
Don’t forget to Reply, Kudo, and Accept as Solution.
---------------------------------------------------------------------------
0 Kudos
Visitor leonliu
Visitor
1,730 Views
Registered: ‎06-05-2018

Re: PetaLinux 2017.3 Completely custom Device Tree

mkimage gives me errors as below. I checked the source code. It seems the format if image.ub is not compatible

Mind sharing some idea to fix it?

Error

$ mkimage -f dtc-rnic-cmac.dts images/linux/image.ub

Can't find images parent node '/images' (FDT_ERR_NOTFOUND)
mkimage Can't add hashes to FIT blob

Source Code

/* Find images parent node offset */
images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
if (images_noffset < 0) {
printf("Can't find images parent node '%s' (%s)\n",
FIT_IMAGES_PATH, fdt_strerror(images_noffset));
return;

}

 

0 Kudos
Visitor leonliu
Visitor
1,699 Views
Registered: ‎06-05-2018

Re: PetaLinux 2017.3 Completely custom Device Tree

This is very cool. it works too

0 Kudos
Explorer
Explorer
1,419 Views
Registered: ‎09-19-2010

Re: PetaLinux 2017.3 Completely custom Device Tree

Hi Sandeep,

PetaLinux 2018.3. Your solution does not work.

Indeed in Petalinux-config, when you change in dtb image settings the storage media from boot image to primary sd, PetaLinux updates u-boot env variables automatically and they are correct.

But, Petalinux forgets to update the .its file for generation of image.ub

The generated image.ub is still containing the device tree. That is if you try to boot the Linux with booti, it will fail with an error that the image format is incorrect.

but if you try to boot Linux with bootm and without any notion of dtb file it boots perfectly fine.

image.ub has not really changed, petalinux has not used any updated its file. the image.ub still contains the devicetree. 

 

0 Kudos