Firmware Development

Making a Petalinux MicroSD Card with u-dma-buf, detailed

Later on we are going to need to look at adding ubuntu so we can download packages and whatnot.  Since there are kernel modules being built here I don’t think we can just drop in the ubuntu rootfs unchanged like in most tutorials.  I wrote this largely as a log for myself to refer to in the future.  I hope it helps someone.  I’ll come back and update with detailed instructions to make the vivado project and export the hardware, as well as properly formatting the SD card.


Making the LinuxBoot Project and Configuring

Create the Project

This will set the paths to the petalinux tools and check your build environment:

source ~/Xilinx/PetaLinux/2022.1/bin/

I’m working in my Vivado project directory, where I have already exported the hardware and it created an xsa file.


petalinuxcreatetprojectnLinuxBoot template zynq

cd LinuxBoot
petalinux-create -t project -n LinuxBoot --template zynq

cd LinuxBoot

petalinux-config --get-hw-description=..

In the following window we would like to select a few configuration settings:

under “Image Packaging Configuration” select: root file system type, and select “Ext 4”

This will allow us to copy in the ubuntu rootfs later.  You can now exit and save the configuration.

Configure u-boot
petalinux-config -c u-boot


No need to make changes here, just exit and save.

Configure Kernel

petalinux-config -c kernel

Find the following and enable each option by pressing ‘y’:

Device Drivers > USB Support
Device Drivers > USB Support > USB ULPI PHY interface support
Device Drivers > USB support > EHCI HCD (USB 2.0) support
Device Drivers > USB support > ChipIdea Highspeed Dual Role Controller
Device Drivers > USB support > ChipIdea device controller
Device Drivers > USB support > ChipIdea host controller
Device Drivers > USB support > USB Gadget Support

Now we need to build the device tree and add an entry for the usb controller.

petalinux-build -c device-tree

gedit /path/to/project/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi

Add the following lines:

/include/ "system-conf.dtsi"
/ {
       usb_phy0: usb_phy@0 {
       compatible = "ulpi-phy";
       #phy-cells = <0>;
       reg = <0xe0002000 0x1000>;
       view-port = <0x0170>;

&usb0 {
   dr_mode = "host";
   usb-phy = <&usb_phy0>;

Adding U-DMA-BUF

Go to the below URL and download or clone the repository to a path of your choosing (I put it in the vivado project directory):

git clone

I spent a lot of time trying and failing to get it to cross compile. I found the best way to build the module thanks to this post:

petalinux-create -t modules --name u-dma-buf --enable
petalinux-create -t modules --name u-dma-buf-mgr --enable

Now it’s created modules for us under ./project-spec/meta-user/recipes-modules/u-dma-buf/files

These have blank placeholders instead of the real c files.  The main module is only one c file so we just need to copy the file in. u-dma-buf-mgr is a bit more complicated.  I got it to build but it does NOT load properly.  Notably I can’t get it to load properly on my desktop system either, so I suppose we’ll see if I figure that out then I’ll come back and update this.

cd project-spec/meta-user/recipes-modules/u-dma-buf/files/

cp ~/zybopeta2022/udmabuf/u-dma-buf.c .

The buf-mgr requires two source files, udma-buf-mgr.c and udma-buf.c

cd ../../u-dma-buf-mgr/files

cp ~/zybopeta2022/udmabuf/u-dma-buf-mgr.c .

cp ~/zybopeta2022/udmabuf/u-dma-buf.c .

cd ..

now open in your favorite editor, we need to add the second file:

SUMMARY = "Recipe for  build an external u-dma-buf-mgr Linux kernel module" 
LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e" 

inherit module 


SRC_URI = "file://Makefile \ 
          file://COPYING \ 
          file://u-dma-buf-mgr.c \ 
          file://u-dma-buf.c \ 

S = "${WORKDIR}" 

# The inherit of module.bbclass will automatically name module packages with 
# "kernel-module-" prefix as required by the oe-core build environment.                                                                  

Now we need to go back to files. 

cd files

open the Makefile:

add the following right after the obj-m line:

u-dma-buf-mgr-objs := u-dma-buf-mgr.o u-dma-buf.o


Your file now looks like this:

obj-m := u-dma-buf-mgr.o 
u-dma-buf-mgr-objs := u-dma-buf-mgr.o u-dma-buf.o 
ccflags-y += ${MY_CFLAGS} 

SRC := $(shell pwd) 

        $(MAKE) -C $(KERNEL_SRC) M=$(SRC) 

        $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install 

        rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c 
        rm -f Module.markers Module.symvers modules.order 
        rm -rf .tmp_versions Modules.symvers 


Now go back to your petalinux project directory and run:

petalinux-config -c rootfs



Now we can finally build!


That will take a while, after that we package it with the following:

petalinux-package --boot --force --fsbl images/linux/zynq_fsbl.elf --fpga images/linux/system.bit --u-boot

The modules will be built into the kernel!