Custom Application Creation in PetaLinux on the Zynqberry
Advance your PetaLinux designs with custom application creation.
In my previous post on the Zynqberry I had mentioned that developing custom applications in PetaLinux for a design is one of the best ways to take full advantage of the available processing power in the Arm cores and couple it with the FPGA fabric in the Zynq chip. This blog is a follow up utilizing the Zynqberry base design created in my last post that walks through the basic steps of custom application creation and deployment in a PetaLinux project. The following is the basic outline of steps for creating a custom PetaLinux application that can be applied to any project. Obviously, I'm using the base design from my earlier post here.
Step 1: Create the app
Step 2: Enable the application in the root filesystem configuration menu
Step 3: Build the application
Step 4: Rebuild the entire PetaLinux project
Step 5: Update the boot image file (BOOT.BIN)
Step 6: Re-flash QSPI and replace root file system on SD card
Step 7: Boot Zynqberry and run application
Source the PetaLinux tools environment and change directories into the existing project directory, then create the new application with the desired name and language template. I prefer to use C, but C++ is also an option. It's also possible to import existing C/C++ files as well, and you'll want to match which of those languages the existing files are in.
petalinux-create -t apps --name hello-zynqberry-app --template c
Browsing through the <PetaLinux project directory>/project-spec/meta-user/recipes-apps/<app name> directory you'll see everything that was auto-generated by the petalinux-create command for the application.
In the files folder, the source file with the name of your application will contain the main function which you can use for your starting point for any desired edits. For demonstration purposes, I just changed the print out from "Hello World!" to "Hello Zynqberry PetaLinux App!". Once all desired edits are made, save and close the file.
To enable the application in the final image, launch the root filesystem configuration editor:
petalinux-config -c rootfs
Under the 'user packages' option, you'll see the new application as an option that can now be included in the root filesystem of the PetaLinux project. Once the app is included, save and close the root filesystem configuration editor.
The application itself needs to be built first, which is what the Makefile in the folder with the main source file is for. This Makefile is run with the following command:
petalinux-build -c hello-zynqberry-app
Now that the application has been enabled and compiled, rebuild the PetaLinux project as a whole to update the boot image and root filesystem image.
petalinux-build
To create a new boot image file, run the same petalinux-package command with the same parameter set passed to is as when initially creating the project, but just add the --force flag to it.
petalinux-package --boot --fsbl ../vitis_workspace/zynqberry_0/export/zynqberry_0/sw/zynqberry_0/boot/fsbl.elf --fpga ../vitis_workspace/zynqberry_0/export/zynqberry_0/hw/zsys_wrapper.bit --u-boot --force
Following the same steps as in the previous post, re-flash the Zynqberry QSPI with the new boot image and replace the root filesystem on the SD card.
Boot up the Zynqberry and the new application will be present in the /usr/bin directory, which you can see by listing the contents of the directory.
ls /usr/bin
After verifying the application is present in the image, you can execute it by simply calling the application name from the command line.
/usr/bin/hello-zynqberry-app
You'll see the custom message "Hello Zynqberry PetaLinux App!" print out in the command terminal as verification everything is working correctly!
Again, it you're following this series of Zynqberry blogs, you can find the latest version of my project in my GitHub repository here.