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
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

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

Stockholm by bike

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

Saturday, April 26, 2014
Zynq design from scratch. Part 41.
Petalinux board bringup

One of the great strengths of an FPGA platform is the ability to completely customise our processor system architecture, either for an off-the-shelf evaluation board, or for our own custom designs. PetaLinux SDK was created to embrace that flexibility, and includes a set of tools specifically designed to make it as easy as possible to boot a Zynq or MicroBlaze Linux platform on a new board or CPU subsystem design.

Let's build our own PetaLinux for the LED Controller design in lab2.


We will follow the procedure described in the document PetaLinux SDK Board Bringup Guide.

Hardware platform

Hardware platforms can be created from a number of sources, such as an existing Vivado/XPS project. Regardless of how the hardware system is created and configured, there is a small number of hardware IP and software platform configuration changes required to make the hardware system Linux ready. These are described below.

  1. One Triple Timer Counter
  2. External memory controller with at least 32MB of memory
  3. UART for serial console
  4. Non-volatile memory (QSPI Flash, SD/MMC)
  5. Ethernet

Our design fulfills all these requirements.

Configure software settings and bootloader

After designing the hardware system, it is necessary to configure a PetaLinux BSP for the platform. This is required to automate the PetaLinux board bringup. We will use Xilinx SDK to setup the PetaLinux Board Support Package (BSP) and the First Stage BootLoader (FSBL).

Launching Xilinx SDK

->xsdk &

Add PetaLinux SDK repositories

To add PetaLinux SDK repository select from the top menu:

Xilinx Tools->Repositories

Click the New button and browse to the directory: /opt/PetaLinux/petalinux-v2013.10-final/components/edk_user_repository

Click OK to finish adding local repositories.

Create Zynq FSBL

See part 40 for a decription on how to add the first stage bootloader program.

Create PetaLinux BSP

We will create the BSP and configure it for U-boot and the Linux operating system.

1. Select from the top menu:

File->New->Project and select the Board Support Package wizard.

Click Next. The New Board Support Package Project window appears. Select PetaLinux as BSP OS.

Click Finish and wait for settings window to open.

Select Petalinux from the left sidebar.

Change the settings for:

  • stdout
  • stdin
  • main_memory
  • flash_memory
  • gpio
  • sdio
  • ethernet

Click OK to finish the PetaLinux BSP setup. The directories fsbl_0 and petalinux_bsp_0 have been added to our workspace.

Create a new PetaLinux platform

The next step is to create a new PetaLinux SDK software platform, ready for building a Linux system customized to our new hardware platform. The petalinux-create command is used to achieve this:

-> petalinux-create --type project --template <CPU_TYPE> --name <PROJECT_NAME>

CPU_TYPE      (zynq or microblaze)
PROJECT_NAME  (the name of the platform we are building)

This command will create a new PetaLinux project folder from a default template. Later steps customize these settings to match the hardware project created previously. Here is the result:

Configure the software platform

The final step is to customize the software platform template to precisely match our unique hardware system. This is done by copying and merging the platform configuration files generated during the hardware build phase, into the newly created software platform, as described below:

1. Navigate to appropriate directory before using the petalinux-config command. In general the XSDK BSP directory is for example: "<XSDK workspace directory>/petalinux_bsp_0/"

2. Use the petalinux-config command to import the hardware configuration.

-> cd .../workspace/petalinux_bsp_0
-> petalinux-config --get-hw-description -p <plnx-proj-root>

The -p option points to the PetaLinux project that will be updated to match the hardware platform configurations. This step may take a few minutes to complete. This is because it merges the existing platform configuration to Kernel configuration and enables the appropriated drivers in the Kernel configuration.

This tool generates the hardware configuration files, if required and copies the configuration files to the correct location in our project directory. The configuration files are stored in the directory: PetaZed/subsystem/linux/hw-description

3. Change into the PetaLinux project root:

-> cd .../PetaZed

4. Launch the top level system settings configuration menu. Change the boot device to SD card.

-> petalinux-config

5. Launch the Linux kernel configuration menu. No changes made now.

-> petalinux-config -c kernel

5. Launch the rootfs configuration menu. No changes made now.

-> petalinux-config -c rootfs

Build the system image

Run petalinux-build to build the system image:

The compilation log: build.log is stored in the build directory. The result of the build can be found in the images/linux directory.

Generate BOOT.BIN image

Use this command to generate the boot image:

-> petalinux-package --boot --fsbl <FSBL image> --fpga <FPGA bitstream> --uboot

The FSBL image file and the bitstream files can be found here:

Boot system image on the ZedBoard

We will boot from SD card.

1. Copy the files BOOT.BIN and image.ub to the SD card
2. Insert the SD card into the ZedBoard.
3. Set the jumpers to SD boot
4. Connect a terminal
5. Power up the board.

Our Linux image will boot in a few seconds.

Running the LED_Dimmer application

We can not run the bare-metal LED_Dimmer application program inside the PetaLinux OS. We have to rewrite it to use direct memory accesses. Let's find out how to do it. We will start by studying the GPIO documentation. Here is the GPIO register map:

We find the GPIO base address in the PetaZed/hw-description/xparameters.h file

#define XILINX_GPIO_BASEADDR      0x41200000

Using the peek/poke program

Using the poke command we can write to any memory/register location in the Zynq address map. We can use this command to turn on/off the LEDs and set the dimming factor.

Writing Linux device drivers

I wrote a blog entry about this subject a few years ago. It is still valid. Let's study the poke.c source code,  found in the directory: /opt/Petalinux/petalinux-v2013.10-final/components/apps to get some ideas.

Userspace access via /dev/mem

"/dev/mem" is a virtual file representing the memory map of the whole system. To access the device from user space, we can open "/dev/mem", and then use mmap() to map the device to memory, and then we can access the device by using the pointer which points to the mapped memory. Here are some of the characteristics:

  • Userspace interface to system address space
  • Accessed via mmap() system call
  • Must be root or have appropriate permissions
  • Quite a blunt tool, must be used carefully
  • Can bypass protections provided by the MMU
  • Possible to corrupt kernel, device or other processes memory


  • Very simple, no kernel module or code
  • Good for quick prototyping / IP verification
  • peek/poke utilities
  • Portable (in a very basic sense)


  • No interrupt handling possible
  • No protection against simultaneous access
  • Need to know physical address of IP

OK for prototyping, not recommended for production

Rewriting LED_Dimmer.c

Here is a version of LED_Dimmer.c we can run in PetaLinux. To use it:
  1. Create a new application (LED_Dimmer) and add this program
  2. Run petalinux-config -c rootfs and add the LED_Dimmer application
  3. Build a new Linux kernel.
  4. Boot PetaLinux
  5. Execute LED_Dimmer

Top   Previous   Next

Posted at 16:59 by svenand

June 5, 2014   07:21 PM PDT
Hi, when I'm trying to create a BSP for Petalinux under Vivado 2014.1 and Petalinux 2013.10 I just get "Error generating bsp sources : Failed to generate BSP in the log files and as a message.
Any idea about this issue ?

The repository path is correctly set !

Best, Thorsten

Leave a Comment:


Homepage (optional)


Previous Entry Home Next Entry