Author Topic: Adding User Application to PetaLinux  (Read 10438 times)

pb

  • Active Member
  • *
  • Posts: 13
Adding User Application to PetaLinux
« on: November 30, 2016, 04:32:02 PM »
Hi,

I am trying to add some custom application to my PetaLinux. I tried to follow the section "Including Prebuilt Applications" and "Buildng User Applications" from UG1144.

I have Vivado and Xilinx SDK on my Windows PC and the PetaLinux toolchain on my VM (Ubuntu 14.04). I would like to write some applications in XIlinx SDK and include them to PetaLinux. I followed the instructions from "Including Prebuilt Applications", unfortunately i doesn't mention the file type for <myapp>. So I tried *.elf and *.o file with no success. I made sure the app is listed and marked (petalinux-config -c rootfs -> Apps), I also tried to modify the makefile with following: install: $(TARGETINST) -d data/<myapp> bin/<myapp>.

After building the new image file and storing it on SD card, I can't find my application under the /bin directory. After running "petalinux-build -t apps --template install --name <myapp> --enable" I tried to run the default app, which only includes:
#!/bin/sh
echo "Hello PetaLinux World"

This app is listed in /bin, but I can't run it, respectively I don't see any output.


Can you give me some advice ?

Thanks.

Andrei Errapart

  • Jr. Member
  • **
  • Posts: 56
Re: Adding User Application to PetaLinux
« Reply #1 on: November 30, 2016, 07:31:45 PM »
Hi, no problem to help at all, however, it could be easier if you have included the corresponding error messages, which surely were there, but maybe you overlooked them.

The build command writes the detailed log to the file "build/build.log". Just use the commands "less" or "cat" to view the log and search for the first line containing an error.

As for the file extensions (you tried *.elf and *.o), let me note that the Linux kernel and most linux applications (except GUI applications) overlook the dot '.' character in the  file name and are simply unable to take file extensions into account. The tradition is to completely omit extension from the file names of the executables; just have a look in the directory "/bin" for examples.

I recommend using the following command in the Makefile to install an executable built with Xilinx SDK:
$(TARGETINST) -d -p 0755 data/myapp.elf /bin/myapp
The directory "/bin" is already in the default search path, thus, you will be able to run your application by simply typing "myapp".

As for the default app, it is a platform-independent script and you should be able to run it in the VM, too. In the command line, when you are in the same directory as your script, just prefix the name of the script with "./" to run it, for example as follows:
./myapp
If it works, it will work on the Zynq, too.

If it complains "Permission denied", you have to make sure the permission bits and owner of the file are such that you have the right to execute the script. The brute force method is to simply execute
chmod 0755 myapp
or in the Makefile, add the permission bits to the install command as follows:
$(TARGETINST) -d -p 0755 data/<myapp> /bin/<myapp>


If it complains "bad interpreter", most probably the file has MS-DOS line endings (0x0D 0x0A instead of 0x0A).  Just install the "dos2unix" software package by running and run the command as follows:
dos2unix myapp


Last but not least, let me mention that when you need to debug your application, the easiest way is to add the "TCF Agent" application to the image (no dropbear needed, no qemu either) and configure the Xilinx SDK to use it. It is also the fastest way to try out changes to your application - only a couple of seconds and your application runs on the real hardware.

pb

  • Active Member
  • *
  • Posts: 13
Re: Adding User Application to PetaLinux
« Reply #2 on: November 30, 2016, 09:02:48 PM »
Hi Andrei,

thanks for your advice. I tried using the tcf agent and the setup was pretty easy. I can download and test my application this way.

I also tried to include my application into PetaLinux. I got this method working for a c-file (I will try *.elf and *.o file later).
I think I made a mistake when building linux: after building I only replaced the image file, b/c it was the only file that changed. I use an sd card as rootfile system. There is bug and no new rootfile system will be built, when sd card is selected. So after changing the filesystem to initramfs, the rootfile system was updated too (afterwards I did a rebuilt for sd card). After flashing both files (image and root.cpio) to sd card, <myapp> was running. As I I will also test this with other files.

Thanks again.

Andrei Errapart

  • Jr. Member
  • **
  • Posts: 56
Re: Adding User Application to PetaLinux
« Reply #3 on: December 01, 2016, 09:13:31 AM »
The *.o files are intermediate object files, which are no longer needed when the executable has been built. They cannot be run.

Happy to hear that you got it running :)