Import pynq package on non-pynq image

I’m running a non-Pynq image (xilinx 2019.1 kernel with Ubuntu rootfs for the ZCU111), and I’m trying to install the pynq python package (e.g. import pynq in python3) to leverage the xrfdc drivers that “pynq” provides. With that, I started at the Xilinx/PYNQ git page and tried to start installing via:

[1] sudo pip3 install --upgrade git+https://github.com/Xilinx/PYNQ.git

I’ve encountered errors along the way and resolved them by installing many dependencies, packages, etc. But, now I’m at an error (not able to find libxlnk_cma.h) when trying to install as shown in [1]. The error appears to be referencing a libxhdmi.so library I don’t have.

While I continue looking into this library, I’m curious (since I can’t find this answer anywhere else, yet) what are your thoughts on installing the python pynq package on a non-pynq image? I’m digging through Makefiles and cmake files and other files while trying to be efficient with my time, that is it’s taking longer than I thought :smile:

Any thoughts are appreciated. Thanks!

[EDIT/AFTERTHOUGHT]: I guess it seems like, perhaps I’m reinventing the wheel here, so to speak. I say that not being the most familiar with Pynq and all that it allows. My thought was the the pynq package that I can import is only a piece of what a pynq image provides. Meaning, perhaps what I’m doing isn’t much different than what the ZCU111 pynq image provides?

1 Like

We are retiring that pip install from github. The best thing that you can try, is to install from the sdist.

python3 -m pip install <pynq_sdist>.tar.gz --upgrade --no-deps

where you can download pynq_sdist from https://github.com/Xilinx/PYNQ/releases/download/v2.5/pynq-2.5.tar.gz

This flow has not been tested on other rootfs so proceed with your own risk.

Thanks! It said it installed, but upon opening python3 and executing import pynq:

>>> import pynq
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/pynq/__init__.py", line 33, in <module>
    from .pl import PL
  File "/usr/local/lib/python3.6/dist-packages/pynq/pl.py", line 39, in <module>
    from .ps import CPU_ARCH_IS_SUPPORTED, CPU_ARCH, ZYNQ_ARCH, ZU_ARCH
  File "/usr/local/lib/python3.6/dist-packages/pynq/ps.py", line 322, in <module>
    class _ClocksUltrascale(_ClocksMeta):
  File "/usr/local/lib/python3.6/dist-packages/pynq/ps.py", line 382, in _ClocksUltrascale
    IOPLL_CTRL = Register(CRL_APB_ADDRESS + IOPLL_CTRL_OFFSET)
  File "/usr/local/lib/python3.6/dist-packages/pynq/registers.py", line 115, in __init__
    array = MMIO(address, np.dtype(register_type).itemsize).array
  File "/usr/local/lib/python3.6/dist-packages/pynq/mmio.py", line 82, in __init__
    device = Device.active_device
  File "/usr/local/lib/python3.6/dist-packages/pynq/pl_server/device.py", line 91, in active_device
    raise RuntimeError("No Devices Found")
RuntimeError: No Devices Found
>>>

Devices? *digging into the code … *

Is there a reason you don’t want to use the pre-compiled ZCU111 PYNQ image?

Available here:

Cathal

I may consider that in the future, but at the moment I’m mostly curious about accessing a bitstream via a python package, and I came across Pynq :slight_smile:

It might be related to the fpga manager. Do you have fpga manager framework enabled on your rootfs? PYNQ users that framework to manage bitstreams.

Yes. I even tried loading the bistream first before importing pynq:

cp <bistream>.bit /lib/firmware
echo 0 > /sys/class/fpga_manager/fpga0/flags
echo <bitstream>.bit > /sys/class/fpga_manager/fpga0/firmware
(shows that it's writing, lasts for about 10-20 seconds)
cat /sys/class/fpga_manager/fpga0/state
(shows operating)

After this, I tried importing pynq and get the same “No devices found” error :confused:

In my device tree, I have:

fpga-full {
                compatible = "fpga-region";
                fpga-mgr = <0x0000000b>;
                #address-cells = <0x00000002>;
                #size-cells = <0x00000002>;
        };

… but nothing else seems related to the fpga_manager.

:thinking:

I’m trying to use PYNQ on a Zynqberry device, and I am facing the exact same problem! Did you find a solution for this problem? the Traceback path is exactly the same and fpga_manager is aslo operating!

Unfortunately, no, since I’ve been playing with this in my free time. The variable in my equation that I’m skeptical of is my Ubuntu rootfs. That is, I’m using the Xilinx Linux kernel and an ubuntu rootfs (not the default Petalinux rootfs). Although, I seem to have the right pieces in place. I’m sure I’ll have more free time at some point and will definitely be coming back to this.

The “No devices” is due to a lack of the xlnk device that PYNQ uses for memory allocation on ZYNQ. You need to make sure that CONFIG_XILINX_APF=y is set in the kernel config and the suitable device tree entry is added:

	xlnk {
		compatible = "xlnx,xlnk-1.0";
	};

With that in place you should see /dev/xlnk appear which is what PYNQ searched for on startup.

These config changes will happen automatically if you add the meta-pynq layer to the petalinux project you’re using to build the kernel.

Peter

1 Like

Thanks Peter,

thanks for the reply. For my problem (Pynq on zynqberry) I tried your solution but still it does not work and the /dev/xlnk folder is not created. I also read that another configuration is needed:

  • for Zynq-7000 SoC: Device Drivers→ Generic Driver Options → Size in Mega Bytes(256)
  • CONFIG_LOCALVERSION=“-xilinx-apf”

Do you have any idea what is going wrong?

Regards,
Perjikolaei

That shouldn’t cause the xlnk device not to appear. Would you be able to post /proc/config.gz and the device tree you are using?

Peter

Hi Peter,

now I can import pynq successfully. I used the root instead of xilinx and it worked.

Thank you so much.

Perjikolaei

I anticipate you mean that you changed user to root (sudo su)? If not, can you please clarify your statement, “… used root instead of xilinx.”

Thanks!

yes. Exactly that’s what I did. Also I checked /proc/config.gz to be sure the kernel configuration is set properly.

I added the meta-pynq layer to my Xilinx 2018.3 build and it was working on my Ultra96. I am now using a Trenz SOM and Xilinx 2020.1 which already has the pynq layer in petalinux. I did have to enable the APF driver and add the entry in the devicetree; however, when I boot I get this message:

[ 13.791090] sysfs: cannot create duplicate filename ‘/class/xlnk’
[ 13.797197] CPU: 2 PID: 588 Comm: cat Tainted: G O 5.4.0-xilinx-v2020.1 #1
[ 13.805355] Hardware name: xlnx,zynqmp (DT)
[ 13.809522] Call trace:
[ 13.811958] dump_backtrace+0x0/0x178
[ 13.815608] show_stack+0x14/0x20
[ 13.818909] dump_stack+0xac/0xd0
[ 13.822215] sysfs_warn_dup+0x5c/0x78
[ 13.825868] sysfs_create_dir_ns+0xd8/0xf0
[ 13.829948] kobject_add_internal+0xc8/0x358
[ 13.834200] kset_register+0x54/0x80
[ 13.837761] __class_register+0xc8/0x190
[ 13.841674] __class_create+0x4c/0x90
[ 13.845321] xlnk_probe+0xa4/0x290
[ 13.848705] platform_drv_probe+0x50/0xa0
[ 13.852697] really_probe+0xec/0x428
[ 13.856256] driver_probe_device+0x64/0x130
[ 13.860423] __device_attach_driver+0x98/0x110
[ 13.864850] bus_for_each_drv+0x74/0xc0
[ 13.868669] __device_attach+0xdc/0x160
[ 13.872488] device_initial_probe+0x10/0x18
[ 13.876654] bus_probe_device+0x90/0x98
[ 13.880473] device_add+0x340/0x620
[ 13.883946] of_device_add+0x4c/0x58
[ 13.887505] of_platform_device_create_pdata+0xb4/0x120
[ 13.892713] of_platform_notify+0xd4/0x168
[ 13.896793] notifier_call_chain+0x58/0x98
[ 13.900871] blocking_notifier_call_chain+0x54/0x78
[ 13.905734] __of_changeset_entry_notify+0xd0/0x100
[ 13.910594] __of_changeset_apply_notify+0x54/0xd0
[ 13.915367] of_overlay_fdt_apply+0x774/0xad8
[ 13.919707] create_overlay+0x24/0x60
[ 13.923353] cfs_overlay_item_dtbo_write+0x54/0xa8
[ 13.928128] configfs_release_bin_file+0x88/0xd0
[ 13.932728] __fput+0x88/0x208
[ 13.935765] ____fput+0xc/0x18
[ 13.938804] task_work_run+0xc8/0xf8
[ 13.942363] do_exit+0x2ac/0x9b8
[ 13.945574] do_group_exit+0x40/0xa8
[ 13.949132] __arm64_sys_exit_group+0x14/0x18
[ 13.953474] el0_svc_common.constprop.0+0x68/0x160
[ 13.958247] el0_svc_handler+0x6c/0x88
[ 13.961979] el0_svc+0x8/0xc
[ 13.964860] kobject_add_internal failed for xlnk with -EEXIST, don’t try to register things with the same name in the same direc.
[ 13.976848] xlnk xlnk: xlnk_probe: Error creating xlnk class

The thing is that I can see the driver already loaded earlier based on these messages:
[ 10.714774] xlnk xlnk: Major 247
[ 10.717813] xlnk xlnk: xlnk driver loaded
[ 10.721714] xlnk xlnk: xlnk_pdev is not null

I’m mainly just using pynq for the parsing of the hwh and mmio support so don’t use /dev/xlnk. I’m not clear why the drivers probe function is being called again. I can create a pynq object, without downloading the bitstream, but I get other driver errors like this and eventually my console hangs but the system stays up.

Any ideas on what is happening?
thanks,
jeff

Can you check your device tree? The meta-pynq layer in Petalinux loads xlnk via a device-tree overlay post-boot and I’m guessing this is conflicting with an entry that is statically defined somewhere. Do you have an xlnk entry in your system-user.dtsi?

Peter

Ah, yes. I had added that to my system-user.dtsi because I had it in my 2.4 build. I did not realize the pl_server was doing this. Remove the xlnk node from the system-user.dtsi fixed the problem.

thanks!
jeff

Sorry to re-open the issue, I am on Petalinux 2021.2 on zcu104 device and I can’t find the /dev/xlnk on my system. Trying to run an FINN overlay.

I have imported meta-pynq overlay (I can see /components/yocto/layers/meta-xilinx/meta-xilinx-pynq/recipes-support/pynq-overlay/pynq-overlay). I have enabled XILINX_APF from petalinux-config -c kernel and CMA is on 256MB.
I have run the build without modification of system-user.dtsi. Then tried to modify the system-user.dtsi (copied from pynq_zynqmp.dtsi in pynq-overlay folder), as shown bellow…

/include/ "system-conf.dtsi"

&sdhci1 {
      no-1-8-v;
      disable-wp;
};

&amba {
        xlnk {
                compatible = "xlnx,xlnk-1.0";
        };
        fabric@A0000000 {
                compatible = "generic-uio";
                reg = <0x0 0xA0001000 0x0 0x1000>;
                status = "okay";
                interrupt-parent = <&gic>;
                interrupts = <0 89 4>;
        };

};

Also have tried

/include/ "system-conf.dtsi"

&sdhci1 {
      no-1-8-v;
      disable-wp;
};

xlnk {
            compatible = "xlnx,xlnk-1.0";
};

(Haven’t tried on pl-custom.dtsi, I don’t know if it makes any difference, just mentioning it.)

I am not familiar with custom device-tree code…Can you please colaborate with what I am doing wrong?

And my rootfs comfiguration :

CONFIG_xrt=y
CONFIG_dnf=y
CONFIG_imagefeature-package-management=y
CONFIG_e2fsprogs-resize2fs=y
CONFIG_parted=y
CONFIG_resize-part=y
CONFIG_packagegroup-petalinux-opencv=y
CONFIG_mesa-megadriver=y
CONFIG_packagegroup-petalinux-x11=y
CONFIG_packagegroup-petalinux-v4lutils=y
CONFIG_packagegroup-petalinux-matchbox=y
CONFIG_python3-pynq=y
CONFIG_python3-audio=y
CONFIG_python3-pillow=y
CONFIG_pynq-overlay=y
CONFIG_libstdc++=y
CONFIG_docker=y
CONFIG_docker-ce-contrib=y
CONFIG_nano=y

One last thing. I see this, on system startup I don’t know if it’s relative:

Starting udev
[    6.310723] udevd[265]: starting version 3.2.9
[    6.327723] random: udevd: uninitialized urandom read (16 bytes read)
[    6.334941] random: udevd: uninitialized urandom read (16 bytes read)
[    6.341419] random: udevd: uninitialized urandom read (16 bytes read)
[    6.400441] udevd[266]: starting eudev-3.2.9
[    6.510272] zocl: loading out-of-tree module taints kernel.
[    6.518236] [drm] Probing for xlnx,zocl
[    6.522461] zocl-drm amba_pl@0:zyxclmm_drm: IRQ index 32 not found
[    6.528817] [drm] FPGA programming device pcap founded.
[    6.534049] [drm] PR Isolation addr 0x0
[    6.538258] [drm] Initialized zocl 0.0.0 00000 for amba_pl@0:zyxclmm_drm on minor 1
[    7.090060] FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
[    7.196381] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
bootlogd: /dev/ttyPS0Starting jupyter-setup

Unable to start, see /var/log/jupyter-setup.log and /var/log/jupyter-setup.err

Starting pl_server

[    8.152868] OF: resolver: overlay phandle fixup failed: -2
[    8.158375] create_overlay: Failed to create overlay (err=-2)
Unable to start, see /var/log/pl_server.log and /var/log/pl_serve