New Horizons

Welcome to my blog

My name is Sven Andersson and I
work as a consultant in embedded
system design, implemented in ASIC
and FPGA.
In my spare time I write this blog
and I hope it will inspire others to
learn more about this fantastic field.
I live in Stockholm Sweden and have
my own company


You are welcome to contact me
and ask questions or make comments
about my blog.


New Horizons
What's new
Starting a blog
Writing a blog
Using an RSS reader

Zynq Design From Scratch
Started February 2014
Changes and updates
Zynq-7000 All Programmable SoC
ZedBoard and other boards
Computer platform and VirtualBox
Installing Ubuntu
Fixing Ubuntu
Installing Vivado
Starting Vivado
Using Vivado
Lab 1. Create a Zynq project
Lab 1. Build a hardware platform
Lab 1. Create a software application
Lab 1. Connect to ZedBoard
Lab 1. Run a software application
Lab 1. Benchmarking ARM Cortex-A9
Lab 2. Adding a GPIO peripheral
Lab 2. Create a custom HDL module
Lab 2. Connect package pins and implement
Lab 2. Create a software application and configure the PL
Lab 2. Debugging a software application
Running Linux from SD card
Installing PetaLinux
Booting PetaLinux
Connect to ZedBoad via ethernet
Rebuilding the PetaLinux kernel image
Running a DHCP server on the host
Running a TFTP server on the host
PetaLinux boot via U-boot
PetaLinux application development
Fixing the host computer
Running NFS servers
VirtualBox seamless mode
Mounting guest file system using sshfs
PetaLinux. Setting up a web server
PetaLinux. Using cgi scripts
PetaLinux. Web enabled application
Convert from VirtualBox to VMware
Running Linaro Ubuntu on ZedBoard
Running Android on ZedBoard
Lab2. Booting from SD card and SPI flash
Lab2. PetaLinux board bringup
Lab2. Writing userspace IO device driver
Lab2. Hardware debugging
MicroZed quick start
Installing Vivado 2014.1
Lab3. Adding push buttons to our Zynq system
Lab3. Adding an interrupt service routine
Installing Ubuntu 14.04
Installing Vivado and Petalinux 2014.2

Chipotle Verification System

EE Times Retrospective Series
It all started more than 40 years ago
My first job as an electrical engineer
The Memory (R)evolution
The Microprocessor (R)evolution

Four soft-core processors
Started January 2012
Table of contents
OpenRISC 1200
Nios II

Using the Spartan-6 LX9 MicroBoard
Started August 2011
Table of contents
Problems, fixes and solutions

FPGA Design From Scratch
Started December 2006
Table of contents
Acronyms and abbreviations

Actel FPGA design
Designing with an Actel FPGA. Part 1
Designing with an Actel FPGA. Part 2
Designing with an Actel FPGA. Part 3
Designing with an Actel FPGA. Part 4
Designing with an Actel FPGA. Part 5

A hardware designer's best friend
Zoo Design Platform

Installing Cobra Command Tool
A processor benchmark

Porting a Unix program to Mac OS X
Fixing a HyperTerminal in Mac OS X
A dream come true

The New York City Marathon

Kittelfjall Lappland

Tour skating in Sweden and around the world
Wild skating
Tour day
Safety equipment
A look at the equipment you need
Skate maintenance
Books, photos, films and videos
Weather forecasts

38000 feet above see level
A trip to Spain
Florida the sunshine state

Photo Albums
Seaside Florida
Ronda Spain
Sevilla Spain
Cordoba Spain
Alhambra Spain
KittelfjÀll Lapland
Landsort Art Walk
Skating on thin ice

100 Power Tips for FPGA Designers

Adventures in ASIC
Computer History Museum
Design & Reuse
d9 Tech Blog
EDA Cafe
EDA DesignLine
Eli's tech Blog
FPGA Arcade
FPGA Central
FPGA developer
FPGA Journal
FPGA World
Lesley Shannon Courses
Mac 2 Ubuntu
Programmable Logic DesignLine
World of ASIC

If you want to be updated on this weblog Enter your email here:

rss feed

Sunday, April 06, 2014
Zynq design from scratch. Part 35.
Using CGI scripts

The Common Gateway Interface (CGI) is a standard method for web servers software to delegate the generation of web pages to executable files. Such files are known as CGI scripts; they are programs, often stand-alone applications, usually written in a scripting language like Perl. In this example we will write the CGI script using the C language.

Create a CGI script

Create a user application by running petalinux-create -t apps from inside a PetaLinux project on our workstation.

->cd Projects/PetaLinux/Avnet-Digilent-ZedBoard-2013.3
->petalinux-create -t apps --name HelloWorld

HelloWorld C program

As usual when starting work with some new programming technology, we should probably first make a trivial program work. This avoids fighting with many potential problems at a time and concentrating first on the issues specific to the environment, here CGI.

We will use the following program that just prints Hello world but preceded by HTTP headers as required by the CGI interface. Here the header specifies that the data is plain ASCII text.

#include <stdio.h>

int main(void) {
  printf("Content-Type: text/plain;charset=us-ascii ");
  printf("Hello world ");
  return 0;

HelloWorld makefile

The CGI script will be installed in directory: /home/httpd/cgi-bin

APP = HelloWorld

# Add any other object files to this list below
APP_OBJS = HelloWorld.o

all: build install

build: $(APP)

    $(CC) $(LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS)

    -rm -f $(APP) *.elf *.gdb *.o

.PHONY: install image

install: $(APP)
    $(TARGETINST) -d $(APP) /home/httpd/cgi-bin/$(APP)

%.o: %.c
    $(CC) -c $(CFLAGS) -o $@ $<

Build and boot PetaLinux

Follow the instructions in part 29 to add a new appliction, build and boot PetaLinux.

Start the web server

Login to PetaLinux and start httpd (Hypertext Transfer Protocol Daemon) using port 8080:

->httpd -p 8080 -h /home/httpd

Displaying the web page

Open a web browser on the host machine and enter the following web address:

The CGI script will execute on the server side and display the text: Hello world.

Modifying the HelloWorld program

Writing C programs normally means we have to do a number of iterations including bug fixing and adding more code, which means we have to go through this process every time.
  1. Change the source code
  2. Rebuild the Linux kernel
  3. Load and boot the kernel

This will take several minutes to be completed and we will spend a lot of time waiting for things to finish. Let's find a faster way to modify and test a C program. Here is the modification:

printf("Hello world from Zoocad Consulting ");

Build the the application

To find out what other possibilities we have to build our application we use the command:

->petalinux-build --help

We will use this command to build only the HelloWorld application:

->petalinux-build -c rootfs/HelloWorld -x build

The result from the build is stored in the directory: build/linux/rootfs/apps/HelloWorld

Copy the HelloWorld application

As we have the Ubuntu file system NFS mounted on our host we can copy the executable file HelloWorld to PetaLinux using the curl command (see part 34).

-> cd ..../build/linux/rootfs/apps/HelloWorld
-> curl -T HelloWorld -u root:root

On the PetaLinux side:

->cd /var/ftp
->chmod 755 HelloWorld
->cp HelloWorld /home/httpd/cgi-bin/.

Top   Previous   Next

Posted at 19:15 by svenand

Penyubur Kandungan
August 10, 2014   02:06 AM PDT
I have bookmarked your website because this site contains valuable information in it. I am really happy with articles quality and presentation.

Leave a Comment:


Homepage (optional)


Previous Entry Home Next Entry