Bar
SpaceWire UK
Specialist providers of VHDL Intellectual Property & Design Services
BarBarBarBar
Tutorial
Missing Image!
Part 16 - Create Peek & Poke CGI scripts to access Programmable Logic address space

Introduction

This tutorial details the steps required to create and install peek & poke CGI shell applications to be used with the website. The previously installed binary peek & poke applications shall be called from within shell scripts that include the extra code to make CGI possible.

Aims

The aims of this tutorial are as follows :-
  1. Setup environment
  2. Change present working directory
  3. Create installer application
  4. Create CGI scripts
  5. Modify BitBake recipe
  6. Build, package & deploy project on Zedboard
  7. Check application is working

1. Setup environment

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

Tools are as follows :-
vivado @ /opt/Xilinx/Vivado/2021.2/bin/vivado
vitis @ /opt/Xilinx/Vitis/2021.2/bin/vitis
petalinux-build @ /opt/Xilinx/PetaLinux/2021.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

3. Create installer application

Create a new auto-enabled installer application.
steve@Linux-Steve:/home/steve/projects/petalinux$ petalinux-create --type apps --template install --name cgipeekpoke --enable
Examine the file structure of the newly created installer application.
steve@Linux-Steve:/home/steve/projects/petalinux$ tree project-spec/meta-user/recipes-apps/cgipeekpoke
project-spec/meta-user/recipes-apps/cgipeekpoke
├── cgipeekpoke.bb
├── files
│   └── cgipeekpoke
└── README

1 directory, 3 files

4. Create CGI scripts

Create CGI wrapper scripts for the pre-existing peek & poke binary applications.
steve@Linux-Steve:/home/steve/projects/petalinux$ subl project-spec/meta-user/recipes-apps/cgipeekpoke/files/{peek.sh,poke.sh}

peek.sh

  1. #!/bin/sh

  2. # Create associative array from query string
  3. declare -A param
  4. while IFS='=' read -r -d '&' key value && [[ -n "$key" ]]; do
  5.   param["$key"]=$value
  6. done <<<"${QUERY_STRING}&"

  7. # Execute command
  8. val=$(peek ${param["addr"]})

  9. # Return exit status
  10. ret=$?
  11. printf "Content-type: text/html\r\n\r\n"
  12. if [ ${ret} -ne 0 ]; then
  13.   printf "failed"
  14. else
  15.   printf "$val"
  16. fi

poke.sh

  1. #!/bin/sh

  2. # Create associative array from query string
  3. declare -A param
  4. while IFS='=' read -r -d '&' key value && [[ -n "$key" ]]; do
  5.   param["$key"]=$value
  6. done <<<"${QUERY_STRING}&"

  7. # Execute command
  8. poke ${param["addr"]} ${param["val"]}

  9. # Return exit status
  10. ret=$?
  11. printf "Content-type: text/html\r\n\r\n"
  12. if [ ${ret} -ne 0 ]; then
  13.   printf "failed"
  14. else
  15.   printf "success"
  16. fi

5. Modify BitBake recipe

Edit the BitBake recipe to remove the cgipeekpoke entry and add in entries for peek & poke. Change the installation location from /usr/bin to /srv/www/cgi-bin.
steve@Linux-Steve:/home/steve/projects/petalinux$ subl project-spec/meta-user/recipes-apps/cgipeekpoke/cgipeekpoke.bb

cgipeekpoke.bb

  1. #
  2. # This file is the cgipeekpoke recipe.
  3. #

  4. SUMMARY = "Simple cgipeekpoke application"
  5. SECTION = "PETALINUX/apps"
  6. LICENSE = "MIT"
  7. LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

  8. SRC_URI = "file://peek.sh \
  9.        file://poke.sh \
  10. "

  11. FILES_${PN} += "/srv/www/cgi-bin"

  12. S = "${WORKDIR}"

  13. do_install() {
  14.      install -d ${D}/srv/www/cgi-bin
  15.      install -m 0755 ${S}/peek.sh ${D}/srv/www/cgi-bin
  16.      install -m 0755 ${S}/poke.sh ${D}/srv/www/cgi-bin
  17. }

6. Build, package & deploy project on Zedboard

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

7. Check application is working

Access the CGI application directly to test functionality by performing a write to the LED register and a read from the slide switch register.

Using the Client URL (curl) command enter the following URL to command the CGI script to write 0x0F to the LED register at 0x41200000.
steve@Linux-Steve:/home/steve/projects/petalinux$ curl -w "\nReceived %{size_download} bytes\n" "http://192.168.2.87/cgi-bin/poke.sh?addr=0x41200000&val=0x0F"
All being well LED's 0, 1, 2 & 3 should illuminate and the script should return the success message.
success
Received 7 bytes
Again using curl enter the following URL to command the CGI script to read from the slide switch register at 0x41200008.
steve@Linux-Steve:/home/steve/projects/petalinux$ curl -w "\nReceived %{size_download} bytes\n" "http://192.168.2.87/cgi-bin/peek.sh?addr=0x41200008"
All being well the script should successfully return something akin to the following indicating which of the slide switches are in their on position, in this case switches 0 & 1.
0x00000003
Received 10 bytes