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

Contact

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



Content

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

Zynq Design From Scratch
Started February 2014
1 Introduction
Changes and updates
2 Zynq-7000 All Programmable SoC
3 ZedBoard and other boards
4 Computer platform and VirtualBox
5 Installing Ubuntu
6 Fixing Ubuntu
7 Installing Vivado
8 Starting Vivado
9 Using Vivado
10 Lab 1. Create a Zynq project
11 Lab 1. Build a hardware platform
12 Lab 1. Create a software application
13 Lab 1. Connect to ZedBoard
14 Lab 1. Run a software application
15 Lab 1. Benchmarking ARM Cortex-A9
16 Lab 2. Adding a GPIO peripheral
17 Lab 2. Create a custom HDL module
18 Lab 2. Connect package pins and implement
19 Lab 2. Create a software application and configure the PL
20 Lab 2. Debugging a software application
21 Running Linux from SD card
22 Installing PetaLinux
23 Booting PetaLinux
24 Connect to ZedBoad via ethernet
25 Rebuilding the PetaLinux kernel image
26 Running a DHCP server on the host
27 Running a TFTP server on the host
28 PetaLinux boot via U-boot
29 PetaLinux application development
30 Fixing the host computer
31 Running NFS servers
32 VirtualBox seamless mode
33 Mounting guest file system using sshfs
34 PetaLinux. Setting up a web server
35 PetaLinux. Using cgi scripts
36 PetaLinux. Web enabled application
37 Convert from VirtualBox to VMware
38 Running Linaro Ubuntu on ZedBoard
39 Running Android on ZedBoard
40 Lab2. Booting from SD card and SPI flash
41 Lab2. PetaLinux board bringup
42 Lab2. Writing userspace IO device driver
43 Lab2. Hardware debugging
44 MicroZed quick start
45 Installing Vivado 2014.1
46 Lab3. Adding push buttons to our Zynq system
47 Lab3. Adding an interrupt service routine
48 Installing Ubuntu 14.04
49 Installing Vivado and Petalinux 2014.2
50 Using Vivado 2014.2
51 Upgrading to Ubuntu 14.04
52 Using Petalinux 2014.2
53 Booting from SD card and SPI flash
54 Booting Petalinux 2014.2 from SD card
55 Booting Petalinux 2014.2 from SPI flash
56 Installing Vivado 2014.3

Chipotle Verification System
Introduction

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
Introduction
Table of contents
Leon3
MicroBlaze
OpenRISC 1200
Nios II

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

FPGA Design From Scratch
Started December 2006
Introduction
Table of contents
Index
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

CAD
A hardware designer's best friend
Zoo Design Platform

Linux
Installing Cobra Command Tool
A processor benchmark

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

Running
The New York City Marathon

Skiing/Skating
Kittelfjall Lappland

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

Travel
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

Books
100 Power Tips for FPGA Designers

Favorites
Adventures in ASIC
ChipHit
Computer History Museum
DeepChip
Design & Reuse
Dilbert
d9 Tech Blog
EDA Cafe
EDA DesignLine
Eli's tech Blog
Embedded.com
EmbeddedRelated.com
FPGA Arcade
FPGA Blog
FPGA Central
FPGA CPU News
FPGA developer
FPGA Journal
FPGA World
Lesley Shannon Courses
Mac 2 Ubuntu
Programmable Logic DesignLine
OpenCores
Simplehelp
SOCcentral
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)

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

clean:
    -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: 192.168.33.3:8080/cgi-bin/HelloWorld



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 ftp://192.168.33.3

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:

Name


Homepage (optional)


Comments




Previous Entry Home Next Entry