Part 13 - Create & test a PetaLinux application that runs automatically at startup
Missing Image!Missing Image!Missing Image!

Introduction

This tutorial details the steps required to build an application into PetaLinux that will run at boot time.

Aims

The aims of this tutorial are as follows :-
  1. Setup environment
  2. Change present working directory
  3. Create auto-run application
  4. Build, package & deploy project on Zedboard
  5. Launch terminal emulator
  6. Check auto-run application is working

1. Setup environment

Setup Xilinx design environment for the 2020.2 toolset.
steve@Linux-Steve:/home/steve$ source xilinx.sh
Xilinx tools available tools at /opt/Xilinx :-
1) 2020.2 - Vivado - SDK - Vitis - PetaLinux
0) Exit
Please select tools required or exit : 1

Tools are as follows :-
vivado @ /opt/Xilinx/Vivado/2020.2/bin/vivado
vitis @ /opt/Xilinx/Vitis/2020.2/bin/vitis
petalinux-build @ /opt/Xilinx/PetaLinux/2020.2/tool/tools/common/petalinux/bin/petalinux-build

2. Change present working directory

Change the present working directory to be the project directory.
steve@Linux-Steve:/home/steve$ cd /home/steve/projects/petalinux/avnet-digilent-zedboard-2020.2

3. Create auto-run application

Create a blank application component (auto enabled).
steve@Linux-Steve:/home/steve/projects/petalinux/avnet-digilent-zedboard-2020.2$ petalinux-create --type apps --template install --name led-runner --enable
Change the default source code to do something a little more obvious.
steve@Linux-Steve:/home/steve/projects/petalinux/avnet-digilent-zedboard-2020.2$ subl project-spec/meta-user/recipes-apps/led-runner/files/led-runner

led-runner

  1. #!/bin/sh

  2. poke 0x41200000 0x18
  3. usleep 125000
  4. poke 0x41200000 0x3C
  5. usleep 125000
  6. poke 0x41200000 0x7E
  7. usleep 125000
  8. poke 0x41200000 0xFF
  9. usleep 125000
  10. poke 0x41200000 0x7E
  11. usleep 125000
  12. poke 0x41200000 0x3C
  13. usleep 125000
  14. poke 0x41200000 0x18
  15. usleep 125000
  16. poke 0x41200000 0x00

Change the BitBake receipe to make it suitable for an auto-start application.
steve@Linux-Steve:/home/steve/projects/petalinux/avnet-digilent-zedboard-2020.2$ subl project-spec/meta-user/recipes-apps/led-runner/led-runner.bb

led-runner.bb

  1. #
  2. # This file is the led-runner recipe.
  3. #
  4. SUMMARY = "Simple led-runner application"
  5. SECTION = "PETALINUX/apps"
  6. LICENSE = "MIT"
  7. LIC_FILES_CHKSUM ="file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

  8. SRC_URI = "file://led-runner"

  9. S = "${WORKDIR}"

  10. FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

  11. inherit update-rc.d

  12. INITSCRIPT_NAME = "led-runner"
  13. INITSCRIPT_PARAMS = "start 99 S ."

  14. do_install() {
  15.   install -d ${D}${sysconfdir}/init.d
  16.   install -m 0755 ${S}/led-runner ${D}${sysconfdir}/init.d/led-runner
  17. }
  18. FILES_${PN} += "${sysconfdir}/*"

4. Build, package & deploy project on Zedboard

Rebuild the project to include the updated files, package up the project ready for deployment, power cycle the Zedboard and deploy the project via JTAG.
steve@Linux-Steve:/home/steve/projects/petalinux/avnet-digilent-zedboard-2020.2$ petalinux-build
steve@Linux-Steve:/home/steve/projects/petalinux/avnet-digilent-zedboard-2020.2$ petalinux-package --prebuilt --force
steve@Linux-Steve:/home/steve/projects/petalinux/avnet-digilent-zedboard-2020.2$ petalinux-boot --jtag --prebuilt 3

5. Launch terminal emulator

Launch the MiniCom terminal emulator if not already running.
steve@Linux-Steve:/home/steve/projects/petalinux/avnet-digilent-zedboard-2020.2$ minicom -D /dev/ttyACM0 -b 115200

6. Check auto-run application is working

The following sequence of events should be observed.

'projects' location : 'repos' location : 'downloads' location :
Copyright © 2021 Steve Haywood
Missing Image!
Missing Image!Missing Image!Missing Image!