Archive for February, 2011

Linux Bring-Up on SoPC

February 21, 2011

System-on-Programmable-Chip is an emerging trend in the embedded world.
Here’s what I did to bring-up Petalinux on Xilinx Spartan-6 devkit SP605/SP601.
Petalinux is an embedded Linux distribution for Xilinx FPGA’s MicroBlaze softcore. Since SDK v1.3, the current release as of early 2011, Petalinux supports PowerPC440 hardcore.
Once you have the right hardware and software tools, such as devkit (SP605 or SP601), Xilinx ISE (12.4, 12.3 is fine), Petalinux SDK (v1.3) and a Linux host (a Xubuntu 10.4 VM on Macbook), it is surprising easy to bring-up Linux on FPGA. The idea is the same if you have a different hardware and software combination.

1. Install Xilinx ISE 12.4 for Linux. Petalinux SDK depends on Xilinx design suite to run.

I installed ISE (Embedded Edition) to a CIFS network share, which is a Journaled HFS+ external portable USB2 hard drive connected to Macbook (it is worth for another article to cover the topic, may be some other time). If ISE is installed on a virtual disk, it takes about 12G space for ISE, EDK, PlanAhead, LabTools and SDK (not all are necessary for our purpose).
Here’s how ISE 12.4 is setup.

ISE 12.4

Xilinx JTAG Platform Cable drive needs to be installed too. I installed CP210x USB/UART driver on Macbook host.

2. Install Petalinux SDK 1.3

The SDK should be installed on a Linux file system, because of some Linux specific symbolic links. I installed it to my Xubuntu’s second ext4 virtual disk.

Here’s how Xilinx and Petalinux (/media/users) are mounted:


Here’s how SDK is setup. I installed it to /software/target/ because of the specific need for the projects I am working on.

SDK 1.3

3. Treakin Ubuntu
The following first two changes are needed for SDK under Ubuntu.

  • SDK scripts are using pushd/popd, so replace /bin/sh (link to /bin/dash) and point it to /bin/bash.
  • Create symbolic link /usr/bin/gmake, pointing to /usr/bin/make.
  • I also found a weird thing about SDK 1.3. It looks for some files from ISE 12.3, so create a symbolic link 12.3 and points it to 12.4 (See Picture ISE 12.4).
  • 4. Design hardware
    PetaLogix’s Board Bringup Guide is extremely useful, but not all that clear. To bring up Linux, it needs UART, system timer, DDR and MicroBlaze hardware, Ethernet and Flash are optional. UART, system timer and Ethernet must be interrupt driven.
    Create a folder, say sopc, under $PETALINUX/hardware/user-platforms.
    Launch Xilinx Platform Studio (enter $xps &) and choose Base System Builder wizard.

    Base System Builder wizard

    Create New XPS Project by specifying project file name, say sopc.xmp under $PETALINUX/hardware/user-platforms/sopc, and search path at $PETALINUX/hardware/edk_user_repository.

    XMP Project

    Keep “PLB system” as the default interconnect type, and move BSB wizard forward to “Board Select”. Choose “Spartan-6 SP605 Evaluation Platform” as the “Board Name”.


    Move BSB wizard forward by using all default selections till “Peripheral Configuration”. Add xps_timer, check “Use Interrupt” option and choose “Two timers are present” for “Configuration Mode”.

    xps timer

    Check “Use Interrupt” option for Ethernet_MAC.


    For RS232_Uart, select 115200 for “Baud Rate”, and check “Use Interrupt” option.


    Move to “Cache Configuration”, and check both “Instruction Cache” and “Data Cache”.


    Move the wizard to the end to finish BSB, and go back to XPS. In “System Assembly View” tab, double click MicroBlaze instance to launch “MicroBlaze Configuration Wizard”. Select “Linux with MMU” configuration, and then “OK” button to finish the wizard.

    Select “Software Platform Settings” from XPS “Software” menu. For “Software Platform” tab, select “petalinux” as “OS” under “OS & Library Settings” section.

    Software Platform Petalinux

    For “OS and Lib Configuration” tab, make the selections for peripheral as highlighted in the following screenshot. If FLASH is used in the design, make sure its value is properly set.

    OS and Lib Configuration

    Now the hardware design is done, time to build bitstream by selecting “Generate Bitstream” from “Hardware” menu.
    Before doing that, and if FLASH is used, make sure FLASH’s base address must be after DDR3. It can be changed and verified from XPS “System Assembly View” tab under “Address”.
    In my environment, it takes about 22 minutes to finish the build process. The generated bit file is located at: $PETALINUX/hardware/user-platforms/sopc/implementation/sopc.bit. It will be used to configure Spartan-6 FPGA on SP605 later.

    5. Design software

  • Create software platform by using: petalinux-new-platform:
    petalinux-new-platform -c <cpu-arch> -v <VENDOR> -p <PLATFORM> 

    Create Software Platform

    Architecture configuration, Linux kernel configuration, and DTS file, etc., are generated at: $PETALINUX/software/petalinux-dist/vendors/tcao/sopc.

  • Configure Software Platform:
    petalinux-copy-autoconfig -v <VENDOR> -p <PLATFORM> PROJECT_FILE 

    Configure Software Platform

    FPGA configuration files and drivers are copied to proper folders in $PETALINUX/software/petalinux-dist/linux-2.6.x.

  • Configure Kernel and Applications.

    Configure Kernel and Apps

  • Build Linux Kernel
    cd $PETALINUX/software/petalinux-dist

    Build Kernel

    It takes about 21 minutes to build the kernel. Kernel image is at:

    6. Upload configuration and application
    Now comes the fun part to configure FPGA and unload Linux kernel. Connect JTAG USB and USB/UART cables to the host, power on SP605 or SP601 board. I forward the JTAG USB connection to VM, and keep USB/UART connection to host (baud rate is 115200).

  • Configure FPGA
    Navigate to the hardware project folder and launch XMD:
    XMD% fpga -f xxx.bit

    FPGA Programming

  • Upload Linux Image
    Within XMD, connect to Microblaze core, upload the Linux image and boot Linux:
    XMD% connect mb mdm
    XMD% dow xxx.elf
    XMD% run

    Linux Upload

    From serial console, login as root.

    Petalinux Console

  • Shrink VMware virtual disks

    February 20, 2011

    Virtual disks usually only expand, their sizes won’t get reduced even files are removed.
    The problem originates from the fact how files are managed by a file system. When a file is removed from a disk, its contents remain, only spaces taken by the removed file are reclaimed by the file system.

    I used Virtual PC, VirtualBox and QEMU, and is using VMware Fusion exclusively on Mac (sorry, Parallels).
    I don’t know there is a single step process to shrink virtual disks, but here’s how I manage to get my virtual machines’ sizes in control by:
    1. On VM, remove unnecessary files such as browser’s cache, temporary files, etc.
    2. defragging disks for Windows VMs. Linux ext3 and ext4 file systems don’t need defrag.
    The purpose of defragmentation is to improve file I/O performance, and have a better opportunity to shrink size more.
    Enter the following from Console to launch Disk Defragmenter.
    For XP Windows VM, such as XP or Windows 2003, type “dfrg.msc”:

    XP or Windows 2003 Disk Defragmenter

    For Windows 7 VM, including Windows Server 2008, type “dfrgui”:

    Win7 or Windows Server 2008 Disk Defragmenter

    3. On VM, zeros out previously used and reclaimed disk spaces.
    For Windows, you can find Sysinternals SDelete. To zero out, say c: drive, you can launch it from Console as: “sdelete -c c:”.


    For Linux, navigate to any folder within the disk you want to zero out, and run the following command as a super or root user: “cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill”.
    It may take some time to finish. You will see a disk full message. It is OK, the generated file is removed right away.


    4. On host, shrink virtual disks. You can use UI to do it, as the following screen shots.

    VM Settings

    VM Disks

    Or, it can be done by the command line tool vmware-vdiskmanager with -k option, which is located at:
    /Library/Application Support/VMware Fusion. You only need specify the master virtual disk (Disk DescriptorFile).
    My xubunty.vmdk is split into 2 GB files, and here’s how to shrink it: